Last active
October 2, 2018 21:59
-
-
Save subfission/aa53a9fd6eeac8a80bebe2e55b7c69df to your computer and use it in GitHub Desktop.
AWSCLI | Python3
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 | |
| # AWSCLI | Python3 (aws cli command pipe to python3) | |
| # | |
| # This magic one-liner will build a beautiful table view of your AWS ec2 assets. | |
| # Requires Python3 & Tabulate | |
| BOLD="$(tput bold)" | |
| ULINE="$(tput sgr 0 1)" | |
| END="$(tput sgr0)" | |
| echo | |
| echo "${ULINE}Written by Zach Jetson${END}" | |
| echo | |
| [ -z $1 ] && TABLE_FMT="fancy-grid" || TABLE_FMT="$1" | |
| aws ec2 describe-instances \ | |
| --query 'Reservations[*].Instances[*].[Placement.AvailabilityZone,InstanceId,Platform,PrivateDnsName,PrivateIpAddress,PublicDnsName,PublicIpAddress,State.Name,Tags]' \ | |
| --output json | \ | |
| python3 -c $'import json,sys,tabulate\nj=json.load(sys.stdin)\ndef f(b=None):return b["Key"]+":"+b["Value"] if b else list()\nprint(tabulate.tabulate([(x[0][0],x[0][1],x[0][2],x[0][3],x[0][4],x[0][5],x[0][6],x[0][7],"\\n".join([f(m) for m in x[0][8] if x[0][8] is not None] if x[0][8] else list()) ) for x in j if j is not None ], headers=["Zone","InstanceId","Platform","PrivateDnsName","PrivateIpAddress","PublicDnsName","PublicIpAddress","State","Tags"], tablefmt="'$TABLE_FMT'"));' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment