Created
April 12, 2015 17:36
-
-
Save nmagee/72f5d9ba12efeca40b63 to your computer and use it in GitHub Desktop.
Create an EC2 AMI using your InstanceId
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# This script creates a series of prompts to create an AMI of an EC2 instance from a few AWS profiles | |
# Note that the YYYYmmdd- is added to the name of the AMI automatically | |
set -e | |
clear | |
# Check for AWS CLI tools | |
type aws >/dev/null 2>&1 || { echo >&2 "\n\n I require the AWS CLI but it's not installed. Please visit http://aws.amazon.com/cli/ and install it. Aborting.\n"; exit 1; } | |
# Interview the user | |
echo "" | |
read -p " What AWS profile does this instance belong to? (Leave blank for default): " profile | |
read -p " What is the Instance ID of the server you want to AMI: " instanceid | |
read -p " What is the name you want to give this AMI? (No spaces - DATE is prepended): " aminame | |
read -p " Describe this AMI in plain language (Max 256 chars): " amidesc | |
read -p " Is it okay to reboot the instance? (y/N): " rebootx | |
case $rebootx in | |
[Yy]* ) rebootv="--reboot"; break;; | |
[Nn]* ) rebootv="--no-reboot";; | |
* ) echo "Please answer Y or N";; | |
esac | |
# Assemble a date prefix + the ami name | |
amidatename=`date +%Y%m%d`-$aminame | |
# Give feedback to the user and teach them what the manual call would look like | |
echo "\n AWS Profile: $profile" | |
echo " Instance ID: $instanceid" | |
echo " AMI Name: $amidatename" | |
echo " AMI Description: $amidesc" | |
echo " Reboot: $rebootx\n" | |
echo " The API call being made to AWS is:" | |
echo " aws --profile $profile ec2 create-image --instance-id $instanceid --name $amidatename --description \"$amidesc\" $rebootv" | |
# Make the actual call | |
aws --profile $profile ec2 create-image --instance-id $instanceid --name $amidatename --description "$amidesc" $rebootv | |
# Confirm. TODO - create a ping query to let the user know when AMI is complete. | |
echo "Your AMI request has been queued. Please wait for it to complete." | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment