Created
November 25, 2020 07:48
-
-
Save redjoker011/16204e7722e3d84b8d7691a90acfdb01 to your computer and use it in GitHub Desktop.
Fetch AWS EC2 Instance Details
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Fetch and Filter Running EC2 Instance by name | |
# https://docs.aws.amazon.com/cli/latest/reference/ec2/describe-instances.html | |
# Query: | |
# Name: Instance Name | |
# DnsName: Public DNS Name | |
# State: Instance State | |
# AZ: Availability Zone | |
# Filter: | |
# Filter by name | |
# Filter running instances(code = 16) | |
# Profile: | |
# Use ec2-manager(default profile is used as default) | |
aws ec2 describe-instances \ | |
--query | |
'Reservations[*].Instances[*].{Name:Tags[?Key==`Name`]|[0].Value,DnsName:PublicDnsName,State:State,Instance:InstanceId,AZ:Placement.AvailabilityZone}' \ | |
--filters Name=tag-value,Values='CHANGE TO INSTANCE NAME' Name=instance-state-code,Values=16 \ | |
--profile ec2-manager | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment