ものぐさ用AMIをコマンドラインで作るスクリプトです。 インスタンスがとまっていないと失敗するようにしています。
#!/bin/sh
instanceId=$1
name=$2
description=$3
if [ "$instanceId" = "" ]; then
echo "usage: $0 {instance_id} {name} {desc}"
exit 1
fi
if [ "$name" = "" ]; then
echo "usage: $0 {instance_id} {name} {desc}"
exit 1
fi
if [ "$description" = "" ]; then
echo "usage: $0 {instance_id} {name} {desc}"
exit 1
fi
status_result=`mktemp`
aws ec2 describe-instance-status --instance-ids $instanceId > $status_result
if [ "`cat $status_result | grep STATUS`" != "" ]; then
echo "instance not stop, please wait or halt instance"
exit 1
fi
rm -f $status_result
aws ec2 create-image --instance-id $instanceId --name $name --description "$description"


