Created
June 12, 2020 15:28
-
-
Save jamescarr/856b7f7d3caceef2042eaae5e9c02b9b to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env zsh | |
function aws-rds-describe() { | |
zparseopts -D -E -A opts -- o: | |
output=${opts[-o]:-"table"} | |
name=${1} | |
query=( | |
"DBInstances[]" | |
".{" | |
"DBInstanceIdentifier : DBInstanceIdentifier," | |
"Address : Endpoint.Address," | |
"Port : Endpoint.Port," | |
"InstanceCreateTime : InstanceCreateTime," | |
"DBInstanceClass : DBInstanceClass" | |
"}" | |
) | |
aws --output ${output} \ | |
rds describe-db-instances \ | |
--query "${query}" | |
} | |
function aws-groups-with() { | |
zparseopts -D -E -A opts -- o: | |
output=${opts[-o]:-"table"} | |
sg_id=${1} | |
query=( | |
"SecurityGroups[?length(IpPermissions[?contains(UserIdGroupPairs[].GroupId, \`${sg_id}\`)]) > \`0\`]" | |
".{" | |
"GroupId : GroupId," | |
"GroupName : GroupName," | |
"VpcId : VpcId," | |
"TagName : Tags[?Key==\`Name\`].Value | [0]" | |
"}" | |
) | |
aws --output ${output} \ | |
ec2 describe-security-groups \ | |
--query "${query}" | |
} | |
function aws-instances-describe() { | |
zparseopts -D -E -A opts -- o t: | |
output=${opts[-o]:-"table"} | |
tag_name=${opts[-t]:-"Name"} | |
name=${1} | |
query=( | |
"Reservations[].Instances[]" | |
".{" | |
"Name : Tags[?Key == \`Name\`].Value | [0]," | |
"State : State.Name," | |
"LaunchTime : LaunchTime," | |
"PrivateDnsName : PrivateDnsName," | |
"PublicDnsName : PublicDnsName," | |
"InstanceId : InstanceId," | |
"InstanceType : InstanceType" | |
"}" | |
) | |
aws --output ${output} \ | |
ec2 describe-instances \ | |
--filters "Name=tag:${tag_name},Values=*${name}*" \ | |
--query "${query}" | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment