テンプレートファイルが正しく記述できているか確認する (cloudformation validate-template)
YAML や JSON 形式で作成した CloudFormation 用のテンプレートファイルが、正しく記述できているかを調べることができます。
$ aws cloudformation validate-template --template-body file://template.json
Description: Sample template
Parameters: []
An error occurred (ValidationError) when calling the ValidateTemplate operation: Template format error: JSON not well-formed. (line 5, column 2)
An error occurred (ValidationError) when calling the ValidateTemplate operation: Invalid template property or properties [ABC]
スタックを作成する (cloudformation create-stack)
ローカルの YAML テンプレートから生成
$ aws cloudformation create-stack --stack-name mystack \
--template-body file://template.yml
StackId: arn:aws:cloudformation:ap-northeast-1:123456789012:stack/mystack/b810c3cd-e492-eb11-6cab-b7f82d02a2e5
S3 バケット上の YAML テンプレートから生成
$ aws cloudformation create-stack --stack-name mystack \
--template-url https://s3.xxx.xxx/.../template.yaml
パラメーターを指定する場合
$ aws cloudformation create-stack --stack-name mystack \
--template-body file://template.yml \
--parameters "ParameterKey=Key1,ParameterValue=Value1" \
"ParameterKey=Key2,ParameterValue=Value2" \
"ParameterKey=Key3,ParameterValue=Value3"
スタックの情報を取得する (cloudformation describe-stacks, describe-stack-resources)
スタックの一覧を取得する
$ aws cloudformation describe-stacks
指定したスタックの情報を取得する
$ aws cloudformation describe-stacks --stack-name <スタック名>
Stacks:
- CreationTime: '2021-04-01T12:21:20.064000+00:00'
DisableRollback: false
DriftInformation:
StackDriftStatus: NOT_CHECKED
EnableTerminationProtection: false
NotificationARNs: []
RollbackConfiguration: {}
StackId: arn:aws:cloudformation:ap-northeast-1:123456789012:stack/mystack/b810c3cd-e492-eb11-6cab-b7f82d02a2e5
StackName: mystack
StackStatus: CREATE_COMPLETE
Tags: []
指定したスタック内のリソースリストを取得する
$ aws cloudformation describe-stack-resources --stack-name <スタック名>
StackResources:
- DriftInformation:
StackResourceDriftStatus: NOT_CHECKED
LogicalResourceId: HelloBucket
PhysicalResourceId: mystack-hellobucket-npd68k1m8ut8a
ResourceStatus: CREATE_COMPLETE
ResourceType: AWS::S3::Bucket
StackId: arn:aws:cloudformation:ap-northeast-1:123456789012:stack/mystack/de70c0f6-f192-eb11-1b8b-55dc1106bc7d
StackName: mystack
Timestamp: '2021-04-01T13:54:43.857000+00:00'
スタックを削除する (cloudformation delete-stack)
$ aws cloudformation delete-stack --stack-name <STACK_NAME>
スタックが特定のステータスになるまで待機する (cloudformation wait)
スタックが CREATE_COMPLETE になるまで待機する
$ aws cloudformation wait stack-create-complete --stack-name <STACK_NAME>
チェンジセットが CREATE_COMPLETE になるまで待機する
$ aws cloudformation wait change-set-create-complete \
--stack-name <STACK_NAME> \
--change-set-name <CHANGE_SET_NAME>