Skip to content

Instantly share code, notes, and snippets.

@ilyash
Last active June 5, 2018 00:53
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ilyash/df788b1f8ccf9755848ecc56c26bd2a5 to your computer and use it in GitHub Desktop.
Save ilyash/df788b1f8ccf9755848ecc56c26bd2a5 to your computer and use it in GitHub Desktop.
alias REGIONS_NAMES='aws ec2 describe-regions | jq ".Regions[].RegionName" -r'
alias TERMINATE='aws ec2 terminate-instances --instance-ids'
alias STOP='aws ec2 stop-instances --instance-ids'
alias START='aws ec2 start-instances --instance-ids'
alias MON_ENA='aws ec2 monitor-instances --instance-ids'
alias MON_DIS='aws ec2 unmonitor-instances --instance-ids'
RESIZE() {
aws ec2 modify-instance-attribute --instance-id "$1" --instance-type "{\"Value\": \"$2\"}"
}
DESC() {
aws ec2 describe-instances | jq -r '.Reservations[].Instances[] | "\(.InstanceId)%\(if .Tags then .Tags[] | select ( .Key == "Name" ) | .Value else "-" end)%\(.KeyName)%\(if .PublicIpAddress then .PublicIpAddress else "-" end)%\(.LaunchTime)%\(.InstanceType)%\(.State.Name)%\(if .Tags then [.Tags[] | select( .Key != "Name") |"\(.Key)=\(.Value)"] | join(",") else "-" end)"' | sed 's/.000Z//g' | column -t -s '%'
}
STACKS() {
aws cloudformation describe-stacks | jq -r '.Stacks[] | "\(.StackName)%\(.StackStatus)%\(.CreationTime)%\(if .Tags then [.Tags[]|"\(.Key)=\(.Value)"] | join(",") else "-" end)"' | column -t -s '%'
}
STACK_EV() {
aws cloudformation describe-stack-events --stack-name "${1:-$CUR_STACK}" | jq -r '.StackEvents[] | "\(.ResourceType) \(.LogicalResourceId) \(.ResourceStatus) \(.Timestamp)"' | tac | column -t
}
STACK_RES() {
aws cloudformation describe-stack-resources --stack-name "${1:-$CUR_STACK}" | jq -r '.StackResources[] | "\(.ResourceType) \(.LogicalResourceId) \(.PhysicalResourceId) \(.ResourceStatus) \(.Timestamp)"' | column -t
}
AZS() {
aws ec2 describe-availability-zones | jq '.AvailabilityZones[] | "\(.ZoneName)%\(.State)"' -r | column -t -s '%'
}
ZONES() {
aws route53 list-hosted-zones | jq -r '.HostedZones[] | "\(.Name)%\(.Id)"' | sort | column -t -s '%'
}
SUBNETS() {
aws ec2 describe-subnets | jq '.Subnets[] | "\(.VpcId)%\(.SubnetId)%\(.CidrBlock)%\(.AvailabilityZone)%pub=\(.MapPublicIpOnLaunch)%dflt=\(.DefaultForAz)%\(.Tags)"' -r | column -t -s '%'
}
REGIONS() {
aws ec2 describe-regions | jq '.Regions[] | "\(.RegionName)%\(.Endpoint)"' -r | column -t -s '%'
}
EACH_REGION() {
REGIONS_NAMES | while read region;do echo "+ [region $region]"; "${@/@REGION@/$region}";done
}
VPCS() {
aws ec2 describe-vpcs | jq '.Vpcs[] | "\(.VpcId)%\(.CidrBlock)%\(.State)%dflt=\(.IsDefault)"' -r | column -t -s '%'
}
TAG() {
aws ec2 create-tags --resources "$1" --tags "Key=$2,Value=$3"
}
SGS() {
aws ec2 describe-security-groups | jq -r '.SecurityGroups[] | "\(.GroupId)%\(.GroupName)%\(if .Tags then .Tags[] | select ( .Key == "Name" ) | .Value else "-" end)%\(if .Tags then [.Tags[] | select( .Key != "Name") |"\(.Key)=\(.Value)"] | join(",") else "-" end)"' | column -t -s '%'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment