Skip to content

Instantly share code, notes, and snippets.

@jwoffindin
Created August 26, 2013 04:48
Show Gist options
  • Save jwoffindin/6338180 to your computer and use it in GitHub Desktop.
Save jwoffindin/6338180 to your computer and use it in GitHub Desktop.
VOLUME_ID=$(cat /tmp/staging-volume)
ec2-detach-volume ${VOLUME_ID}
# Detach
while [[ $(ec2-describe-volumes $VOLUME_ID | cut -f 6) != 'available' ]] ; do
echo "waiting...."
done
# Snapshot and create AMI
SNAPSHOT_ID=$(ec2-create-snapshot ${VOLUME_ID} | cut -f 2)
echo ${SNAPSHOT_ID} > /tmp/ami-snapshot
while [[ $(ec2-describe-snapshots ${SNAPSHOT_ID} | cut -f 4) != 'completed' ]] ; do
echo 'waiting for snapshot'
done
# Register
AKI="aki-3d990e07"
AMI_ID=$(ec2-register --name "Snapshot"$(date +'%y%m%d%H%M%S') --architecture x86_64 --kernel ${AKI} --root-device-name /dev/sda2 -s ${SNAPSHOT_ID} | cut -f 2)
echo ${AMI_ID} > /tmp/ami-id
ec2-describe-image ${AMI_ID}
while [[ $(ec2-describe-images ${AMI_ID} | awk '$1 == "IMAGE" { print $5 }') != 'available' ]] ; do
echo 'waiting for image to become available'
done
echo "booting image"
INSTANCE_ID=$(ec2-run-instances ${AMI_ID} | awk '$1 == "INSTANCE" { print $2 }')
echo ${INSTANCE_ID} > /tmp/instance-id
ec2-get-console-output ${INSTANCE_ID}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment