Amazon Simple Storage Service (Amazon S3) is one of the most popular cloud-based storage solutions by AWS. Amazon S3 offers flexibility for various applications and is widely used across multiple use cases as it offers durability, availability, and cost-effectiveness. It allows users to store, manage, and securely access petabyte-scale data from the AWS cloud.
By default, Amazon Billing shows how much data and cost is incurred for the cumulative storage cost and usage of all S3 buckets in each region. Because it is very easy to create multiple S3 buckets and upload objects to them, customers such as startups, small businesses, or large enterprises can quickly lose track of how much each of their Amazon S3 buckets costs.
In this article, we will apply user-defined cost allocation tags to each Amazon S3 bucket and use AWS Cost Explorer to view the costs of each S3 bucket as well as use Cost and Usage Reports for a more detailed analysis.
First, we have to add tags for each Amazon S3 bucket. If you have a few buckets, you can do this manually. If you have several buckets, you might want to create a simple script that will use the AWS CLI to query all the bucket names and loop the command to apply a tag for each bucket. For this example, we have a few buckets to add a custom cost allocation tag – cost:BucketName.
- Go to the Amazon S3 management console and click on the bucket that you want to add a cost allocation tag.
- Click on the Properties tab and under Tags section, click Edit. Add the tag key cost:BucketName. Use the name of the bucket as the value for this tag.
- Click Save changes to apply the tags.
- After saving the tag changes, it may take up to 24 hours for the tags to appear on the Cost allocation tags of the Billing and Cost Management console. If this is your first time using the service, you may need to activate Cost Explorer.
- Once you have activated AWS Cost Explorer, it may take another 24 hours for the changes to take effect before you can use AWS Cost Explorer.
- Click on Cost allocation tags on the left pane and click the User-defined cost allocation tags Search for the tag name cost:BucketName.
- Select the Tag key and click Activate. This ensures that Cost Explorer and your AWS Cost and Usage Reports will include these tags.
- Now go to the AWS Cost Explorer management console to view the usage of each Bucket.
- Create a filter based on the Tag that you have activated from the cost allocation tags page. You should see each of the buckets and their corresponding costs.
- You can also set additional filters if you want the cost explorer to show a particular Service, Linked account, Region, etc.
With these cost allocation tags, you can also filter reports that were generated by the AWS Cost and Usage Reports. This way, users can have a more details analysis of how much data is stored on each bucket and how much each bucket costs.
Sources:
https://docs.aws.amazon.com/awsaccountbilling/latest/aboutv2/cost-alloc-tags.html
https://docs.aws.amazon.com/AmazonS3/latest/userguide/CostAllocTagging.html
https://docs.aws.amazon.com/AmazonS3/latest/userguide/BucketBilling.html
https://aws.amazon.com/aws-cost-management/aws-cost-and-usage-reporting/