AWS Database Blog

Using cost allocation tags with Amazon DocumentDB (with MongoDB compatibility)

Amazon DocumentDB (with MongoDB compatibility) is a fast, scalable, highly available, and fully managed document database service that supports MongoDB workloads. You can use the same MongoDB 3.6 application code, drivers, and tools to run, manage, and scale workloads on Amazon DocumentDB without having to worry about managing the underlying infrastructure. As a document database, Amazon DocumentDB makes it easy to store, query, and index JSON data.

Amazon DocumentDB was built to solve your challenges around availability, reliability, durability, scalability, backup, and more. In doing so, we built several unique capabilities to remove the undifferentiated heavy lifting and help reduce costs. This post introduces you to cost allocation tags and how you can track the instance, storage, IOPS, and backup storage costs for your Amazon DocumentDB clusters. The end output is a report, as shown in the following graph, that allows you to visualize these costs for a given cluster.

Cost allocation tags

In AWS, a tag is a label that you assign to an AWS resource, such as an Amazon DocumentDB cluster or instance. Tags enable you to categorize your AWS resources in different ways (for example, by purpose, owner, or environment), and you can use tags for cost allocation, access control, and automation. For more information, see the whitepaper AWS Tagging Strategies: Implement an Effective AWS Resource Tagging Strategy. In this post, I show you how to add tags to an existing Amazon DocumentDB cluster, enable cost allocation tagging in your AWS Billing and Cost Management dashboard, and analyze your costs for a given tag in AWS Cost Explorer.

A common use case is performing cost attribution for a particular team or all the services that comprise an application in an environment (such as dev, staging, or prod). With cost allocation tags, you can perform fine-grained cost analysis at the cluster level. Having greater visibility into costs makes cost attribution easy and helps identify opportunities to reduce costs. Although the subject of this post is Amazon DocumentDB, you can use cost allocation tags to organize your costs across multiple services.

Walkthrough overview

To implement this solution, you complete the following steps:

  1. Add a tag to an existing Amazon Document DB cluster.
  2. Tag your existing instances.
  3. Enable cost allocation tags in Billing and Cost Management.
  4. Analyze your costs for a particular tag.

Prerequisites

To use cost allocation tags, you must first provision an Amazon DocumentDB cluster. For instructions, see Getting Started with Amazon DocumentDB.

If you want to create one or more tags when you create a cluster, as part of Step 1 in the Getting Started guide, choose Show advanced settings. Under Tags, you can add tags to the cluster.

Cost allocation tags require that a tag has a non-null value. Null tags don’t appear in Cost Explorer and AWS Budgets. For more information, see Restrictions on AWS-Generated Cost Allocation Tags.

Adding a tag to an existing cluster

Tagging a cluster enables you to report on the costs for the StorageUsage, StorageIOUsage, and BackupUsage for a given cluster. To add a tag, complete the following steps:

  1. On the Amazon DocumentDB console, choose Clusters.
  2. Choose the cluster that you want to analyze with cost allocation tags.
    For this post, I choose tag-example-5-31.
  3. On the cluster page, choose the Events and tags tab.
  4. Under Tags, choose Edit.
  5. In the Edit tags section, enter a value for the Key and Value fields.
    For this post, I enter testEnvironment for the key and cluster for the value.
  6. Choose Save.

Tagging your existing instances

  1. On the Amazon DocumentDB console, choose the cluster that you want to analyze with cost allocation tags.
  2. On the cluster page, choose the Configuration
  3. Under Cluster instances, choose one of the instances in your cluster.
  4. On the instance page, choose the Events and tags
  5. Under Tags, choose Edit.
  6. In the Edit tags section, enter a value for the Key and Value fields.
    For this post, I use testEnvironment and instance, respectively.
  7. Choose Save.
  8. Repeat the steps for each instance in your cluster.

Enabling cost allocation tags

You must activate your newly created tags in your My Billing Dashboard on the AWS Management Console.

  1. Sign in to the console.
  2. From the drop-down menu, choose My Billing Dashboard.
  3. Under Cost Management, choose Cost allocation tags.
  4. In the Filter field, enter the name of the tag you created (testEnvironment).
  5. Select the tag.
  6. Choose Activate.
  7. When asked Do you wish to activate the 1 inactive tag you have selected?, choose

The process of analyzing the new tag in Cost Explorer can take up to 24 hours. When a tag is applied to a resource and the tag is activated, reporting of usage is from that time forward. Cost allocation tags don’t report retroactively.

Analyzing your costs for a particular tag

The last step is to analyze your billing data for your cluster in Cost Explorer.

  1. On the console, from the drop-down menu, choose My Billing Dashboard.
  2. Under Cost Management, choose Cost Explorer.
  3. Under Preconfigured Views, choose Daily Spend View. Use this preconfigured view to filter for the tag you created in the first step.
  4. Under FILTERS, choose Tab.
  5. In the Search for Tag field, enter the names of the tags you created earlier.
  6. For each tag, select cluster and instance.
  7. Choose Apply filters.
  8. To break down daily costs by usage type, in the Daily Cost report, in the Group by section, choose Usage Type.
  9. When asked Enable Group By?, select OK.

From this base report (see the following screenshot), you can filter and group by Usage Type to answer your specific questions. You can visualize and report on your daily costs for your Amazon DocumentDB cluster by continuing to modify the report and filters.

Summary

This post introduced you to cost allocation tags and how to use them to track the instance, storage, IOPS, and backup storage costs for your Amazon DocumentDB clusters.

Amazon DocumentDB provides you with several capabilities to help you estimate, optimize, and monitor your costs. For more information, see Best Practices for Amazon DocumentDB. If you’re new to Amazon DocumentDB, see Getting Started with Amazon DocumentDB.

 


About the Author

 

Joseph Idziorek is a Principal Product Manager at Amazon Web Services.