submitmanifest.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. ##
  2. ## Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  3. ##
  4. ## Licensed under the Amazon Software License (the "License"). You may not use this
  5. ## file except in compliance with the License. A copy of the License is located at
  6. ##
  7. ## http://aws.amazon.com/asl/
  8. ##
  9. ## or in the "license" file accompanying this file. This file is distributed on an
  10. ## "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, express or implied.
  11. ## See the License for the specific language governing permissions and limitations
  12. ## under the License.
  13. ##
  14. import sys
  15. import boto3
  16. import argparse
  17. import re
  18. import pprint
  19. tasknamere = re.compile(r'^(arn:aws:ecs:[^:]*:[^:]*:task-definition/)?([^/:]+)(:.*)?$')
  20. parser = argparse.ArgumentParser(description="Submit manifest jobs to s3grouper in ECS",
  21. usage="%(prog)s [options] -- [s3grouper options]")
  22. parser.add_argument("--region", default=None,
  23. help="AWS region. Default: value of AWS_DEFAULT_REGION")
  24. parser.add_argument("--profile", default=None,
  25. help="awscli profile")
  26. parser.add_argument("-f","--file",default="-",
  27. help="File with list of S3URIs for S3 Storage Inventory manifest.json. Default: stdin")
  28. parser.add_argument("-t","--task", metavar="NAME:TAG",
  29. help="ECS task name or ARN. If the name is given, the tag is optional.")
  30. parser.add_argument("-c","--cluster",
  31. help="ECS cluster name")
  32. parser.add_argument("grouperargs", nargs="+")
  33. args = parser.parse_args()
  34. aws = boto3.session.Session(region_name=args.region, profile_name=args.profile)
  35. ecs = aws.client("ecs")
  36. if args.file == "-":
  37. manifestfile = sys.stdin
  38. else:
  39. manifestfile = open(args.file, "r")
  40. for manifest in manifestfile.readlines():
  41. task = ecs.run_task(cluster=args.cluster,
  42. taskDefinition=args.task,
  43. overrides={"containerOverrides": [{
  44. "name": tasknamere.match(args.task).groups()[1],
  45. "command": args.grouperargs + ["-m", manifest.strip()]}]})
  46. pprint.pprint(task['tasks'])
  47. manifestfile.close()