Skip to content

Instantly share code, notes, and snippets.

@rberrelleza
Created December 6, 2017 18:18
Show Gist options
  • Save rberrelleza/9b38ea06ba83f8b88fac9b144d59e100 to your computer and use it in GitHub Desktop.
Save rberrelleza/9b38ea06ba83f8b88fac9b144d59e100 to your computer and use it in GitHub Desktop.
script to launch an AMI
#!/bin/bash
output=$(aws ec2 run-instances --image-id $1 --instance-type m3.large --key-name YOUR_KEY --security-group-ids YOUR_SG --subnet-id YOUR_SUBNET --associate-public-ip-address --block-device-mapping '[{"DeviceName": "/dev/sda1","Ebs":{"VolumeSize":60}}]')
instance=$(echo $output | grep -o '\"InstanceId\": "i-........\"' | grep -o i-........ )
tag=$(whoami)-$(date +"%Y-%m-%d_%H-%M-%S")
sleep 5
aws ec2 create-tags --resources $instance --tags Key=Name,Value=$tag
echo $instance%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment