Category Archives: Uncategorized

Create AMI from EC2 Image

Published / by MasonCloud / Leave a Comment
# vim /root/bin/ami-create.sh
------

#!/bin/bash

#
# @Purpose Creates an image (AMI) of the given EC2 instance
# @Background Meant to be run as a cronjob. Requires that awscli is installed. Assumes that the
# instance running this command has the permission ec2:CreateImage assigned via IAM.
#
# @Usage: ec2-create-image <instance-id>
#

DATE=$(date +%Y-%m-%d_%H-%M)
AMI_NAME="WordPress Backup - $DATE"
AMI_DESCRIPTION="WordPress Backup - $DATE"
INSTANCE_ID=$1

printf "Requesting AMI for instance $1...\n"
aws ec2 create-image --instance-id $1 --name "$AMI_NAME" --description "$AMI_DESCRIPTION" --no-reboot

if [ $? -eq 0 ]; then
 printf "AMI request complete!\n"
 fi

------
# /root/bin/ami-create.sh i-0b84b3b0de37cce1a >> /root/log/crontab.log 2>&1

------
# aws ec2 deregister-image --image-id i-0b84b3b0de37cce1a