AWS Bulk Tagging : How To Do It And It’s Advantages

Sumit
Tensult Blogs
Published in
3 min readJan 10, 2020
Ref: https://bit.ly/2NcOdOq

If you are someone who works on AWS regularly, then you probably know how tagging works and how we can use AWS tagging to track the resources efficiently. We can sort the resources based on project name, environment name, creator etc and prepare reports for our reference and also for audit purposes.

For those who are new to AWS, tagging feature is a combination of ‘key’ and ‘value’ and is a metadata for the resources. For example, we can give a tag with Key as Project Name and Value as Production. In that case, we will know the environment the resources is deployed in, just by looking at the tag.

If you have a running AWS setup with various resources already provisioned, then implementing tags for everything becomes a tedious process. So just like many other automation projects that we implement here at Tensult, we naturally thought about automating this as well. And yes, of course, we already have a aws bulk-tagging tool thanks to Washington Post Github repo.

So, in this blog, I am about to show you how we can leverage.

Step 1 :

Using your favourite code editor tool, like Visual Studio Code, clone this Git repo in your workspace. Navigate to that folder in your code editor terminal and run the below command:

pip install aws-tagger

Step 2 :

Run the aws configure command and check/configure the aws credentials for your account. Double check the region configured in it, because a wrong region value will give error while running the tool. Eg: give region as us-east-1 or ap-south-1.

Step 3:

The main settings are all done now and we can start tagging our resources using the aws-tagger tool. We can tag resources individually and also in bulk. To tag them individually, use the below command:

aws-tagger — resource resource ID — tag “Owner:Sumit

Also, to tag multiple resources with multiple tags, we can use the below command:

aws-tagger — resource resource ID — resource resource ID — tag “Owner:Sumit” — tag “Environment:Test”

Step 4:

Now comes the interesting part. We can create a csv file with information such as resource IDs, key and value, and then use it to assign tags to every resource mentioned in that csv file. Lot of time can be saved by using this bulk-tagging feature and of course, the automation aspect is also a highlight. Read further on how to create the csv file and run the command.

a. Open Excel in your desktop/laptop and create a column with name ‘Id’. The values in this column should be the resource IDs or S3 bucket names or ARNs depending upon the resource which needs to be tagged.

Excel sheet columns

b. The first 3 resources mentioned in the above snapshot are instances and the Id in the 5th row is the name of an S3 bucket that I have. I have used 2 tags here. For first one, Key is Name and Value is tagger for all. For second tag, Key is Env and Values are from new01 to 04.

c. Save this file as csv(comma delimited) in the same folder where you downloaded/cloned the tool. I named the file taggingsheet.csv just for reference.

d. Now run the below command using the code editor:

aws-tagger — csv .\taggingsheet.csv

After the above command executes, login to the AWS management console and check the resources for tags. Your resources must have been tagged with the value you gave while running the commands. That’s it. Once you have tagged all your resources, you will be able to filter them out based on the tags. This will be useful if you need to differentiate resources based on projects and then check the billing for them.

Conclusion

I hope this blog was helpful in understanding how we can use the aws-tagger tool to tag multiple resources at once. Tagging is essential because it helps in managing the AWS in an efficient way.

Reference: https://github.com/washingtonpost/aws-tagger

--

--