Skip to content

Instantly share code, notes, and snippets.

@petrabarus
Last active October 28, 2016 04:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save petrabarus/367f58fa0b4deecdac7159d9af42dccf to your computer and use it in GitHub Desktop.
Save petrabarus/367f58fa0b4deecdac7159d9af42dccf to your computer and use it in GitHub Desktop.
Get AWS Spot Instances using AWS CLI and execute command via SSH
#!/usr/bin/env bash
aws ec2 describe-spot-instance-requests | \
jq -r '.SpotInstanceRequests | .[] | select(.LaunchSpecification.InstanceType == "c4.8xlarge" and .State == "active") | .InstanceId' | \
xargs -I X sh -c "aws ec2 describe-instances --instance-id X | jq -r .Reservations[0].Instances[0].PublicDnsName" | \
xargs -I X ssh -i ~/mykey.pem ubuntu@X "echo \"Hello WOrld\""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment