Written by Mudita Misra, Cloud Engineer, Powerupcloud Technologies
Why and How the aws-tagger is useful for us?
Use case: “What if we have bulk AWS untagged resources and we need to get the billing based on tags in one or two daytime then how will we do it??”
In this article, we are going to explain how we can do the AWS resource tagging for bulk in number resources in just a few minutes.
- There was a requirement for one of our customers where we were having multiple accounts with bulk resources-EC2, RDS and S3. These resources have to be tagged with 8–9 Business tags for billing/segregation purposes. So we have explored and implemented aws-tagger to make the tagging someway easier.
- Tagging AWS resources is hard because each resource type has a different API which is slightly different. The AWS bulk tagging tool eliminates these differences so that you can simply specify the resource ID and the tags and it takes care of the rest.
Note: Any tags that already exist on the resource will not be removed, but the values will be updated if the tag key already exists. Tags are case sensitive.
- Install aws-tagger on the local/EC2-machine
- Create IAM user with access key and secret key to provide permission to aws-tagger to apply the tags on the resources.
- Create the CSV file with all tags details.
Let’s start the hands-on:
- We can do it from our local machine and also we can have one AWS EC2 Linux/Windows machine from customer private network(if concerned).
i)First, install pip on the machine.
yum install python-pip
ii)Second, install the aws-tagger
pip install aws-tagger
- We will create access key and secret key for this IAM to provide permission to our EC2/local to tag the resources into the account.
- We need to attach the below permission to the IAM user from different respective accounts.
How many ways are there to do tagging by aws tagger???
We have below ways according to requirements:
1. Tag individual resource with a single tag
aws-tagger --resource i-07axxxxxxx --tag "Business:Production"
2. Tag multiple resources with multiple tags
aws-tagger --resource i-07axxxxxxxx --resource i-045xxxxxx --tag "Business:Production" --tag "User:Mudita"
3. Tag multiple resources from a CSV file (for bulk resources)
We need to create a CSV file which will be having the Resource ID, Region ID and tag keys with values to be attached to the respective resources.
Note: Make sure no key-value should be empty/blank if you are not sure about values put ‘NA’ or ‘-’
i) We can create an excel file in google sheets and later save it as the CSV file and use it for tagging.
ii) Download/Copy the CSV file to the local/AWS-EC2 machine.
Now run the below command for CSV file:
aws-tagger --csv tagger-ec2-details-mudita\ -\ aws-tagger.csv
If the command returns to the next line, there is no error and the resources are been tagged. We can verify the tags now from our AWS console.
Implemented AWS Tagger on the following AWS resource types:
1. EC2 instances
aws-tagger --resource i-07XXXXXXX --tag "Business:Production" --tag "User:Mudita"
2. S3 buckets
aws-tagger --resource mudita-powerup-bucket --tag "Business:Production" --tag "User:Raju"
3. RDS instances
aws-tagger --resource arn:aws:rds:us-east-1:1111XXXX:db:mudita-db --tag "Business:Production" --tag "User:Mudita"
I hope this is helpful, please comment below in case of any implementation issues.
Any EC2 volumes that are attached to the instance will be automatically tagged but in case of bulk resources, we won’t recommend aws tagger. We will be coming up with a new method for tagging volumes and snapshots in our next part.
Keep following the blog post for the upcoming part on how to tag Volumes and Snapshots attached to EC2 instances.
For more resources, you can follow below Github link: