Skip to content

Instantly share code, notes, and snippets.

@gweakliem
Last active July 30, 2019 16:21
Show Gist options
  • Save gweakliem/20a0570285615122550ee805003eca5b to your computer and use it in GitHub Desktop.
Save gweakliem/20a0570285615122550ee805003eca5b to your computer and use it in GitHub Desktop.
Stupid AWS Tricks

All these assume OSX bash. Most should be portable to Linux.

brew install spark to get the nifty sparklines stuff

Price history of the last 12 hours of c5.18xlarge instances

aws ec2 describe-spot-price-history --instance-types c5.18xlarge --product-descriptions "Linux/UNIX"  --start-time $(date -v-12H -u +"%Y-%m-%dT%H:%M:%S.000Z") --query "SpotPriceHistory[].SpotPrice" --output text

As a sparkline:

$ aws ec2 describe-spot-price-history --instance-types c5.18xlarge --product-descriptions "Linux/UNIX"  --start-time $(date -v-12H -u +"%Y-%m-%dT%H:%M:%S.000Z") --query "SpotPriceHistory[].SpotPrice" --output text | spark
▁▁▁█▁▁▁▁▁

Which region has the best spot price for a particular instance type?

aws ec2 describe-spot-price-history --instance-types m4.4xlarge --product-descriptions "Linux/UNIX"  --start-time $(date -v-1H -u +"%Y-%m-%dT%H:%M:%S.000Z") --query "SpotPriceHistory[*].[AvailabilityZone,SpotPrice]|sort_by(@,&[1])|[0][0]" --output text

Generate a list of hosts for an EMR cluster EMR won't generate public DNS names for the individual nodes in an EMR cluster. You can generate a list of the DNS entries for the machines in an EMR cluster and merge them into /etc/hosts so the links in the hadoop console are navigable.

CLUSTER_ID=$(aws emr list-clusters --active --query "Clusters[?Name=='$CLUSTER_NAME'].Id" --output text)
echo "Cluster id is '$CLUSTER_ID'"
aws emr list-instances --cluster-id $CLUSTER_ID \
    --query 'Instances[?PrivateIpAddress!="None"].{ip:PrivateIpAddress,dns:PrivateDnsName}' \
    --output text | awk '{ print $2 "\t" $1}' > ~/emr-hosts
# merge ~/emr-hosts with /etc/hosts

Filter a list of ELB Target Groups by a name prefix

aws --profile dev elbv2 describe-target-groups --query 'TargetGroups[?starts_with(TargetGroupName,`dev`)].{TargetGroupArn:TargetGroupArn,TargetGroupName:TargetGroupName}'
@gweakliem
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment