Export tags for a list of Amazon EC2 instances to a CSV file
Created by Sida Ju (AWS) and Pac Joonhyun (AWS)
Summary
This pattern shows how to programmatically export tags for a list of Amazon Elastic Compute Cloud (Amazon EC2) instances to a CSV file.
By using the example Python script provided, you can reduce how long it takes to review and categorize your Amazon EC2 instances by specific tags. For example, you could use the script to quickly identify and categorize a list of instances that your security team has flagged for software updates.
Prerequisites and limitations
Prerequisites
Python 3 installed and configured
AWS Command Line Interface (AWS CLI) installed and configured
Limitations
The example Python script provided in this pattern can search Amazon EC2 instances based on the following attributes only:
Instance IDs
Private IPv4 addresses
Public IPv4 addresses
Tools
Python
is a general-purpose computer programming language. virtualenv
helps you create isolated Python environments. AWS Command Line Interface (AWS CLI) is an open-source tool that helps you interact with AWS services through commands in your command-line shell.
Code repository
The example Python script for this pattern is available in the GitHub search-ec2-instances-export-tags
Epics
Task | Description | Skills required |
---|---|---|
Clone the GitHub repository. | NoteIf you receive errors when running AWS CLI commands, make sure that you’re using the most recent AWS CLI version. Clone the GitHub search-ec2-instances-export-tags
| DevOps engineer |
Install and activate virtualenv. |
For more information, see the virtualenv User Guide | DevOps engineer |
Install dependencies. |
| DevOps engineer |
Configure an AWS named profile. | If you haven’t already, configure an AWS named profile that includes the required credentials to run the script. To create a named profile, run the aws configure command. For more information, see Using named profiles in the AWS CLI documentation. | DevOps engineer |
Task | Description | Skills required |
---|---|---|
Create the input file. | Create an input file that contains a list of the Amazon EC2 instances that you want the script to search and export tags for. You can list instance IDs, private IPv4 addresses, or public IPv4 addresses. ImportantMake sure that each Amazon EC2 instance is listed on its own line in the input file. Input file example
| DevOps engineer |
Run the Python script. | Run the script by running the following command in the terminal:
NoteReplace To get a list of supported parameters and their description, run the following command:
For more information and to see an output file example, see the | DevOps engineer |
Related resources
Configuring the AWS CLI (AWS CLI User Guide)