0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

学習メモ(CloudFormation#01)

Last updated at Posted at 2021-05-05

#内容
AWS CLIを用いてCloudFormationを使う
testvpcスタックを作成、削除する

#スタック作成
事前にカレントディレクトリ (c:\work\cfn) にテンプレート (01_vpc.yml) ファイルを格納済
下記コマンドを実行する。

c:\work\cfn>aws cloudformation create-stack --stack-name testvpc --template-body file://01_vpc.yml

--template-bodyのところは file://から始めないといけない。
相対パスでもOKらしい

StackId: ~~ みたいな表示のみが出てればOK

#確認(マネジメントコンソール)
image.png
ちゃんとできてる:grinning:

#確認(AWS CLI)

スタックを表示
aws cloudformation describe-stacks

c:\work\cfn>aws cloudformation describe-stacks
Stacks:
- CreationTime: '2021-05-05T19:25:45.678000+00:00'
  Description: Hands-on template for VPC
  DisableRollback: false
  DriftInformation:
    StackDriftStatus: NOT_CHECKED
  NotificationARNs: []
  RollbackConfiguration: {}
  StackId: ~~~
  StackName: testvpc
  StackStatus: CREATE_COMPLETE
  Tags: []

スタックを表示(過去作った履歴も見れる)
aws cloudformation list-stacks

--stack-status-filter CREATE_COMPLETEオプションで絞ると削除したスタックは出てこない

StackSummaries:
- CreationTime: '2021-05-05T19:25:45.678000+00:00'
  DriftInformation:
    StackDriftStatus: NOT_CHECKED
  StackId: ~~~
  StackName: testvpc
  StackStatus: CREATE_COMPLETE
  TemplateDescription: Hands-on template for VPC

作成したときのログ表示
aws cloudformation describe-stack-events --stack-name testvpc

- EventId: ~~~
  LogicalResourceId: testvpc
  PhysicalResourceId: ~~~
  ResourceStatus: CREATE_IN_PROGRESS
  ResourceStatusReason: User Initiated
  ResourceType: AWS::CloudFormation::Stack
  StackId: ~~~
  StackName: testvpc
  Timestamp: '2021-05-05T19:25:45.678000+00:00'

スタックリソースを表示
aws cloudformation list-stack-resources --stack-name testvpc

- DriftInformation:
    StackResourceDriftStatus: NOT_CHECKED
  LastUpdatedTimestamp: '2021-05-05T19:26:07.454000+00:00'
  LogicalResourceId: CFnVPC
  PhysicalResourceId: ~~~
  ResourceStatus: CREATE_COMPLETE
  ResourceType: AWS::EC2::VPC
-

#スタック削除

下記コマンドを実行
aws cloudformation delete-stack --stack-name testvpc

正常にプロンプトが返ってきたらOK。
マネジメントコンソールでも確認してみる
image.png
image.png

ちゃんと削除できてひと安心:relieved:

0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?