Skip to content

Instantly share code, notes, and snippets.

@redjoker011
Created November 25, 2020 07:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save redjoker011/16204e7722e3d84b8d7691a90acfdb01 to your computer and use it in GitHub Desktop.
Save redjoker011/16204e7722e3d84b8d7691a90acfdb01 to your computer and use it in GitHub Desktop.
Fetch AWS EC2 Instance Details
#!/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