Skip to content

Instantly share code, notes, and snippets.

@Gabriellpweb
Created May 7, 2018 14:29
Show Gist options
  • Save Gabriellpweb/167c253b7d0ca43e6e23921585dab91d to your computer and use it in GitHub Desktop.
Save Gabriellpweb/167c253b7d0ca43e6e23921585dab91d to your computer and use it in GitHub Desktop.
List EC2 instances
#!/bin/bash
#
# USAGE: ec2ls sa-east-1
# OUTPUT:
# Id ImageId Type PublicIp PrivateIp PrivateDNS
# i-0XX326X41X0254X25 ami-999X105X t2.small null 192.168.1.111 ip-192-168-1-111.sa-east-1.compute.internal
#
#
aws --region $1 ec2 describe-instances \
| jq '.Reservations[].Instances[] | "\(.InstanceId) \(.ImageId) \(.InstanceType) \(.PublicIpAddress) \(.PrivateIpAddress) \(.PrivateDnsName)"' \
| sed -e 's/\"//g' \
| column -t -N Id,ImageId,Type,PublicIp,PrivateIp,PrivateDNS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment