Skip to content

Instantly share code, notes, and snippets.

@shrkw
Created November 28, 2015 14:33
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 shrkw/d4ce7321348d72aeb8e6 to your computer and use it in GitHub Desktop.
Save shrkw/d4ce7321348d72aeb8e6 to your computer and use it in GitHub Desktop.
depends on aws, jq command, and an argument should be image id
function run-ec2 {
source ~/.virtualenv/CP-2710/bin/activate
aws ec2 run-instances --image-id $1 --instance-type t1.micro --key-name oregon > /tmp/run-i
aws_id=$(cat /tmp/run-i | jq -r '.Instances | .[] | .InstanceId')
echo "aws_id: $aws_id"
sleep 10
aws ec2 describe-instances --instance-ids $aws_id > /tmp/run-i
aws_ip=$(cat /tmp/run-i | jq -r '.Reservations | .[] | .Instances | .[] | .PublicDnsName')
echo "aws_ip: $aws_ip"
echo 'ssh -i ~/.ssh/id_rsa.aws.oregon -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null ec2-user@$aws_ip'
echo 'aws ec2 terminate-instances --instance-ids $aws_id'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment