Skip to content

Instantly share code, notes, and snippets.

@jonmorehouse
Last active August 29, 2015 13:56
Show Gist options
  • Save jonmorehouse/9316547 to your computer and use it in GitHub Desktop.
Save jonmorehouse/9316547 to your computer and use it in GitHub Desktop.
EC2 one liners for setting up / breaking down machines
#!/usr/local/bin/bash
# create an ec2-instance and grab the instance id
instance_id=$(ec2-run-instances -g development -t t1.micro -k master $EC2_UBUNTU_AMI | grep INSTANCE | awk '{ print $2 }')
# create a tag for this instance as needed
ec2-create-tags -t Name=development $instance_id
# grab instance_id by tag
instance_id=$(ec2-describe-instances --filter "tag:Name=development" | grep INSTANCE | awk '{ print $2 }')
# grab all running instances (ids)
instance_id=$(ec2-describe-instances --filter "instance-state-name=running" | grep INSTANCE | awk '{ print $2 }')
# now start this instance
ec2-start-instances $instance_id
# stop the same instance
ec2-stop-instances $instance_id
# terminate the instance
ec2-terminate-instances $instance_id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment