ものぐさ向けシリーズ
コマンドラインでcentosを起動します。
AMIは centos6 with hvm です。
launch_centos_micro.sh
#/bin/sh
instanceName=$1
awsprofile=$2
if [ "$awsprofile" = "" ]; then
awsprofile=default
fi
SUBNET="{subnet}"
KEYPAIR="{keypair}"
GROUP="{security group}}"
AMI="ami-13614b12"
STORAGE='[{"DeviceName": "/dev/sda1", "Ebs":{"SnapshotId": "snap-51dd93d6", "VolumeSize": 30, "VolumeType": "standard"}}]'
TYPE="t2.micro"
result_id=`aws ec2 run-instances --profile ${awsprofile} --image-id ${AMI} --instance-type ${TYPE} --subnet-id ${SUBNET} --block-device-mappings "${STORAGE}" --key-name ${KEYPAIR} --security-group-ids ${GROUP} | grep INSTANCE | awk '{ print $8 }'`
if [ "$result_id" = "" ]; then
echo "instance_id not found ..."
exit 1
fi
TAGS=[{\"Key\":\"Name\",\"Value\":\"${instanceName}\"}]
if [ "$instanceName" != "" ]; then
aws ec2 create-tags --profile ${awsprofile} --resources $result_id --tags $TAGS
fi
echo $result_id
使い方は
./launch_centos_micro.sh {name} {aws profile}
です。


