処理の実行
CloudFormationスタックを作成します。
変数の確認:
cat << END
# CLOUDFORMATION_STACK_NAME:"handson-cli-iam-instance-profile"
CLOUDFORMATION_STACK_NAME="${CLOUDFORMATION_STACK_NAME}"
# CLOUDFORMATION_TEMPLATE_URL:"http://prototype-handson-cli.s3.ap-northeast-1.amazonaws.com/template-cloudformation/handson/_downloads/ea518e8eeff4f0529ed924b6071b6b5c/handson-cli-iam-basic-instance-profile.template"
CLOUDFORMATION_TEMPLATE_URL="${CLOUDFORMATION_TEMPLATE_URL}"
END
コマンド:
aws cloudformation create-stack \
--stack-name ${CLOUDFORMATION_STACK_NAME} \
--template-url ${CLOUDFORMATION_TEMPLATE_URL}
結果(例):
{
"StackId": "arn:aws:cloudformation:ap-northeast-1:<AWSアカウントID>:stack/handson-cli-iam-instance-profile/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
}
完了確認
「CloudFormationスタック"handson-cli-iam-instance-profile"が存在する。」ことを確認します。
コマンド:
aws cloudformation list-stacks \
--query "StackSummaries[? \
StackName == \`${CLOUDFORMATION_STACK_NAME}\` \
&& StackStatus != \`DELETE_COMPLETE\` \
].StackName" \
--output text
結果(例):
handson-cli-iam-instance-profile
「CloudFormationスタック"handson-cli-iam-instance-profile"のステータスが"CREATE_COMPLETE"になっている。」ことを確認します。
コマンド:
cloudformation_stack_status=$(\
aws cloudformation list-stacks \
--query "StackSummaries[? \
StackName == \`${CLOUDFORMATION_STACK_NAME}\` \
&& StackStatus != \`DELETE_COMPLETE\` \
].StackStatus" \
--output text \
) \
&& echo ${cloudformation_stack_status}
結果(例):
注釈
ステータスがROLLBACKになった場合は、イベントを確認して原因を特定します。
コマンド:
aws cloudformation describe-stack-events \
--stack-name ${CLOUDFORMATION_STACK_NAME}
結果(例):