Search code examples
amazon-web-servicesboto3aws-batch

Add tags to Batch Jobs and see them in Cost Explorer


I run several Batch Jobs in AWS and I would like to track costs. I added tags to the Jobs using tag_resources from Python's boto3, and I expected to be able to find them in the Cost Explorer, but they aren't. It looks to me that the EC2 instance itself does not inherit the tag, which is the service which is actually costing money.

What is the proper way of achieving what I'm trying?


Solution

  • You can configure EC2 tags in your Compute Environment. See the documentation for compute resources tags. The main problem is that the tags apply to all jobs that run in the Compute Environment.

    If you only need to monitor a small number of workloads, you can create separate Compute Environments for each workload.

    It is more difficult to apply tags for individual jobs. We have tried one approach where we monitor Batch Jobs using EventBridge and perform some boto3 magic to add and remove tags as jobs start and complete.