©2019 by Raghavendra Kambhampati

How to Update Tags in bulk using aws-tagger command line Tool?

Updated: Mar 7

This article outlines the steps to update tags for AWS resources using aws-tagger tool using aws-cli command line interface. 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. 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.


HIGH-LEVEL STEPS:


1. Install Python and Pip

2. Install AWSCLI using pip

3. Install AWS Tagger Tool

4. Configure AWSCLI

5. Run AWS Tagger tool using AWSCLI


STEPS:


Install Python and Pip:


1. Install latest python software (Version 3.7.0 or latest available) on windows 10 from https://www.python.org/downloads/ The following page will appear in your browser.



2. Click the Download Python 3.7.0 button.

The file named python-3.7.0.exe should start downloading into your standard download folder.


3. Double-click the icon labeling the file python-3.7.0.exe->Click Run->Ensure that the Install launcher for all users (recommended) and the Add Python 3.7 to PATH checkboxes at the bottom are checked. If the Python Installer finds an earlier version of Python installed on your computer, the Install Now message may instead appear as Upgrade Now (and the checkboxes will not appear).


4. Highlight the Install Now (or Upgrade Now) message, and then click it ->

A User Account Control pop-up window will appear, posing the question Do you want the allow the following program to make changes to this computer? -> Click the Yes button.


5. A new Python 3.7.0 (64-bit) Setup pop-up window will appear with a Setup Progress message and a progress bar. During installation, it will show the various components it is installing and move the progress bar towards completion. Soon, a new Python 3.7.0 (64-bit) Setup pop-up window will appear with a Setup was successfully message.



6. Click Close button.


7. To try to verify installation->Go to Windows Command Prompt-> Enter below command to check the location of the python installed and also to check python version

C:\Users\***********>where python

C:\Users\***********\AppData\Local\Programs\Python\Python38\python.ex C:\Users\***********>python –version

Python 3.7.0


8. When you install python version greater than 3.0.0 higher pip is also installed. To verify if pip is installed or not go to the below python scripts directory to see pip file C:\Users\***********\AppData\Local\Programs\Python\Python38\Scripts>dir

05/16/2019 02:54 PM <DIR> .

05/16/2019 02:54 PM <DIR> ..

05/16/2019 02:54 PM 102,810 easy_install-3.8.exe

05/16/2019 02:54 PM 102,810 easy_install.exe

05/16/2019 02:54 PM 102,792 pip.exe

05/16/2019 02:54 PM 102,792 pip3.8.exe

05/16/2019 02:54 PM 102,792 pip3.exe

5 File(s) 513,996 bytes

2 Dir(s) 244,067,573,760 bytes free



To Install AWSCLI using pip:


1. Go to the python scripts directory where pip is installed

C:\Users\***********\AppData\Local\Programs\Python\Python38\Scripts

05/16/2019 02:54 PM <DIR> .

05/16/2019 02:54 PM <DIR> ..

05/16/2019 02:54 PM 102,810 easy_install-3.8.exe

05/16/2019 02:54 PM 102,810 easy_install.exe

05/16/2019 02:54 PM 102,792 pip.exe

05/16/2019 02:54 PM 102,792 pip3.8.exe

05/16/2019 02:54 PM 102,792 pip3.exe

5 File(s) 513,996 bytes

2 Dir(s) 244,067,573,760 bytes free


2. Run the command pip3 install awscli

Collecting awscli

Downloading https://files.pythonhosted.org/packages/24/b1/ab1472d83c15be14f20b2a70c44fbad159b2f9b8bcd3e3cf22f66e85bada/awscli-1.16.159-py2.py3-none-any.whl (1.6MB)

100% |████████████████████████████████| 1.6MB 1.8MB/s

Collecting s3transfer<0.3.0,>=0.2.0 (from awscli)

Downloading https://files.pythonhosted.org/packages/d7/de/5737f602e22073ecbded7a0c590707085e154e32b68d86545dcc31004c02/s3transfer-0.2.0-py2.py3-none-any.whl (69kB)

100% |████████████████████████████████| 71kB 1.5MB/s

Collecting botocore==1.12.149 (from awscli)

Downloading https://files.pythonhosted.org/packages/6c/42/23072035de597e566eb007835e640936af1a7379bb8051400a097e64c18d/botocore-1.12.149-py2.py3-none-any.whl (5.4MB)

100% |████████████████████████████████| 5.4MB 2.2MB/s

Collecting colorama<=0.3.9,>=0.2.5 (from awscli)

Downloading https://files.pythonhosted.org/packages/db/c8/7dcf9dbcb22429512708fe3a547f8b6101c0d02137acbd892505aee57adf/colorama-0.3.9-py2.py3-none-any.whl

Collecting PyYAML<=3.13,>=3.10 (from awscli)

Downloading https://files.pythonhosted.org/packages/9e/a3/1d13970c3f36777c583f136c136f804d70f500168edc1edea6daa7200769/PyYAML-3.13.tar.gz (270kB)

100% |████████████████████████████████| 276kB 1.2MB/s

Collecting rsa<=3.5.0,>=3.1.2 (from awscli)

Downloading https://files.pythonhosted.org/packages/e1/ae/baedc9cb175552e95f3395c43055a6a5e125ae4d48a1d7a924baca83e92e/rsa-3.4.2-py2.py3-none-any.whl (46kB)

100% |████████████████████████████████| 51kB 1.0MB/s

Collecting docutils>=0.10 (from awscli)

Downloading https://files.pythonhosted.org/packages/36/fa/08e9e6e0e3cbd1d362c3bbee8d01d0aedb2155c4ac112b19ef3cae8eed8d/docutils-0.14-py3-none-any.whl (543kB)

100% |████████████████████████████████| 552kB 1.5MB/s

Collecting jmespath<1.0.0,>=0.7.1 (from botocore==1.12.149->awscli)

Downloading https://files.pythonhosted.org/packages/83/94/7179c3832a6d45b266ddb2aac329e101367fbdb11f425f13771d27f225bb/jmespath-0.9.4-py2.py3-none-any.whl

Collecting python-dateutil<3.0.0,>=2.1; python_version >= "2.7" (from botocore==1.12.149->awscli)

Downloading https://files.pythonhosted.org/packages/41/17/c62faccbfbd163c7f57f3844689e3a78bae1f403648a6afb1d0866d87fbb/python_dateutil-2.8.0-py2.py3-none-any.whl (226kB)

100% |████████████████████████████████| 235kB 358kB/s

Collecting urllib3<1.25,>=1.20; python_version >= "3.4" (from botocore==1.12.149->awscli)

Downloading https://files.pythonhosted.org/packages/01/11/525b02e4acc0c747de8b6ccdab376331597c569c42ea66ab0a1dbd36eca2/urllib3-1.24.3-py2.py3-none-any.whl (118kB)

100% |████████████████████████████████| 122kB 852kB/s

Collecting pyasn1>=0.1.3 (from rsa<=3.5.0,>=3.1.2->awscli)

Downloading https://files.pythonhosted.org/packages/7b/7c/c9386b82a25115cccf1903441bba3cbadcfae7b678a20167347fa8ded34c/pyasn1-0.4.5-py2.py3-none-any.whl (73kB)

100% |████████████████████████████████| 81kB 1.0MB/s

Collecting six>=1.5 (from python-dateutil<3.0.0,>=2.1; python_version >= "2.7"->botocore==1.12.149->awscli)

Downloading https://files.pythonhosted.org/packages/73/fb/00a976f728d0d1fecfe898238ce23f502a721c0ac0ecfedb80e0d88c64e9/six-1.12.0-py2.py3-none-any.whl

Installing collected packages: jmespath, six, python-dateutil, docutils, urllib3, botocore, s3transfer, colorama, PyYAML, pyasn1, rsa, awscli

Running setup.py install for PyYAML ... done

Successfully installed PyYAML-3.13 awscli-1.16.159 botocore-1.12.149 colorama-0.3.9 docutils-0.14 jmespath-0.9.4 pyasn1-0.4.5 python-dateutil-2.8.0 rsa-3.4.2 s3transfer-0.2.0 six-1.12.0 urllib3-1.24.3

You are using pip version 19.0.3, however version 19.1.1 is available.

You should consider upgrading via the 'python -m pip install --upgrade pip' command.


3. Upgrade pip version when shown in the above output at the end using below command python -m pip install --upgrade pip

C:\Users\************\AppData\Local\Programs\Python\Python38\Scripts>python -m pip install --upgrade pip

Collecting pip

Downloading https://files.pythonhosted.org/packages/5c/e0/be401c003291b56efc55aeba6a80ab790d3d4cece2778288d65323009420/pip-19.1.1-py2.py3-none-any.whl (1.4MB)

100% |████████████████████████████████| 1.4MB 347kB/s

Installing collected packages: pip

Found existing installation: pip 19.0.3

Uninstalling pip-19.0.3:

Successfully uninstalled pip-19.0.3

Successfully installed pip-19.1.1


To Install AWS Tagger Tool:


1. Go to the same python scripts directory where pip is installed

C:\Users\***********\AppData\Local\Programs\Python\Python38\Scripts

05/16/2019 02:54 PM <DIR> .

05/16/2019 02:54 PM <DIR> ..

05/16/2019 02:54 PM 102,810 easy_install-3.8.exe

05/16/2019 02:54 PM 102,810 easy_install.exe

05/16/2019 02:54 PM 102,792 pip.exe

05/16/2019 02:54 PM 102,792 pip3.8.exe

05/16/2019 02:54 PM 102,792 pip3.exe

5 File(s) 513,996 bytes

2 Dir(s) 244,067,573,760 bytes free


2. Run the below aws tagger command pip install aws-tagger

C:\Users\***********\AppData\Local\Programs\Python\Python38\Scripts>pip install aws-tagger

Collecting aws-tagger

Downloading https://files.pythonhosted.org/packages/ad/77/311770e9c601db37286e56bb4b97290ed5a270e648acd9b71c2d1caa6f07/aws-tagger-0.6.3.tar.gz

Collecting boto3>=1.4.4 (from aws-tagger)

Downloading https://files.pythonhosted.org/packages/dc/56/7edf2c5c46967e142717a3658ff2623ec9f9db1b6dd94d4c42a8e767dbb3/boto3-1.9.149-py2.py3-none-any.whl (128kB)

|████████████████████████████████| 133kB 192kB/s

Requirement already satisfied: botocore>=1.5.7 in c:\users\*********\appdata\local\programs\python\python38\lib\site-packages (from aws-tagger) (1.12.149)

Collecting click>=6.6 (from aws-tagger)

Downloading https://files.pythonhosted.org/packages/fa/37/45185cb5abbc30d7257104c434fe0b07e5a195a6847506c074527aa599ec/Click-7.0-py2.py3-none-any.whl (81kB)

|████████████████████████████████| 81kB 37kB/s

Requirement already satisfied: docutils>=0.13.1 in c:\users\*********\appdata\local\programs\python\python38\lib\site-packages (from aws-tagger) (0.14)

Collecting futures>=3.0.5 (from aws-tagger)

Downloading https://files.pythonhosted.org/packages/cc/26/b61e3a4eb50653e8a7339d84eeaa46d1e93b92951978873c220ae64d0733/futures-3.1.1.tar.gz

Requirement already satisfied: jmespath>=0.9.1 in c:\users\*********\appdata\local\programs\python\python38\lib\site-packages (from aws-tagger) (0.9.4)

Collecting retrying>=1.3.3 (from aws-tagger)

Downloading https://files.pythonhosted.org/packages/44/ef/beae4b4ef80902f22e3af073397f079c96969c69b2c7d52a57ea9ae61c9d/retrying-1.3.3.tar.gz

Requirement already satisfied: s3transfer>=0.1.10 in c:\users\***********\appdata\local\programs\python\python38\lib\site-packages (from aws-tagger) (0.2.0)

Requirement already satisfied: six>=1.10.0 in c:\users\***********\appdata\local\programs\python\python38\lib\site-packages (from aws-tagger) (1.12.0)

Requirement already satisfied: urllib3<1.25,>=1.20; python_version >= "3.4" in c:\users\***********\appdata\local\programs\python\python38\lib\site-packages (from botocore>=1.5.7->aws-tagger) (1.24.3)

Requirement already satisfied: python-dateutil<3.0.0,>=2.1; python_version >= "2.7" in c:\users\***********\appdata\local\programs\python\python38\lib\site-packages (from botocore>=1.5.7->aws-tagger) (2.8.0)

Installing collected packages: boto3, click, futures, retrying, aws-tagger

Running setup.py install for futures ... done

Running setup.py install for retrying ... done

Running setup.py install for aws-tagger ... done

Successfully installed aws-tagger-0.6.3 boto3-1.9.149 click-7.0 futures-3.1.1 retrying-1.3.3


3. Once python, pip, awscli and tagger is installed, add the awscli and pip executables to your command line path in environment variables. Go to Control Panel ->System and Security ->System->Advanced System Settings->Click on Environment Variables->Select Path under your user variable ->Click on Edit and add the awscli and pip values and Click OK and OK.

For awscli:

C:\Users\***********>where aws

C:\Users\***********\AppData\Local\Programs\Python\Python38\Scripts\aws

NOTE:-Add this awscli path in the environment variable in path. This path is different based on your own directory path where you installed.

For pip:

C:\Users\***********\AppData\Local\Programs\Python\Python38\Scripts\

NOTE:-Add this path in the environment variable in path. This path is different based on your own directory path where you installed.









Configure AWS CLI with your AWS programmatic credentials:


Go to windows command prompt and enter below commands in sequence to configure awscli with your aws programmatic credentials.

1. C:\Users\***********>aws –version

2. C:\Users\***********>aws configure

3. AWS Access Key ID : ******************

4. AWS Secret Access Key: ********************

5. Default region name [us-east-1]: us-east-1

6. Default output format [None]:


AWS Tagger command line examples for different services:


1. EC2 instances

aws-tagger --resource i-07XXXXXXX --tag "Business:Production" --tag "User:Johny"

2. S3 buckets

aws-tagger --resource demokloud-bucket --tag "Business:Production" --tag "User:Maddy"

3. RDS instances

aws-tagger --resource arn:aws:rds:us-west-1:1111XXXX:db:test-db --tag "Business:Production" --tag "User:Maddy"


NOTE: After aws-tagger we need to mention the resource id and tags to add.


Similarly we can use the above commands to execute tagger command for EFS,Load Balancers and CloudFront distributions.


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 ‘-’

Now run the below command for CSV file:

aws-tagger --csv s3bucketname\ -\ 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.