Thực hiện các bước dưới đây theo đúng thứ tự. Các lệnh CLI được chạy trong VS Code terminal, EC2 instance dùng làm môi trường làm việc sẽ được xóa ở cuối cùng.
cfn-aws-three-tier-demo.
Nhập cfn-aws-three-tier-demo

Đợi stack cfn-aws-three-tier-demo đạt trạng thái DELETE_COMPLETE trước khi tiếp tục:
aws cloudformation wait stack-delete-complete --stack-name cfn-aws-three-tier-demo
Xóa stack cfn-vpc-demo và đợi xóa xong:
aws cloudformation delete-stack --stack-name cfn-vpc-demo
aws cloudformation wait stack-delete-complete --stack-name cfn-vpc-demo

cfn-lambda-demo.
Đợi xóa xong.
Xóa log group được tạo khi test Lambda function (nếu có):
aws cloudformation delete-stack --stack-name cfn-lambda-demo
aws cloudformation wait stack-delete-complete --stack-name cfn-lambda-demo
aws logs delete-log-group --log-group-name /aws/lambda/CfnLambdaDemo

cfn-aws-three-tier-demo, RDS tạo một final snapshot cho database demo-database.
Tìm và xóa snapshot này:
aws rds describe-db-snapshots --db-instance-identifier demo-database --query "DBSnapshots[].DBSnapshotIdentifier" --output text
aws rds delete-db-snapshot --db-snapshot-identifier <snapshot_id>

cf-templates- để lưu template.
Tìm và xóa bucket này:
aws s3 ls | grep cf-templates
aws s3 rb s3://<cf_templates_bucket_name> --force

Chỉ xóa bucket cf-templates- nếu bucket này không còn được dùng cho các CloudFormation stack khác trong tài khoản.
cfn-keypair.
Xóa file cfn-keypair.pem trên máy tính cá nhân:
aws ec2 delete-key-pair --key-name cfn-keypair

cfn-workspace-ec2.
launch-wizard-<n>).
cfn-workspace-key.cfn-workspace-key.pem.Host cfn-workspace trong file ~/.ssh/config.
IaC-Role.
Chúc mừng bạn đã hoàn thành workshop Giới thiệu Infrastructure as Code với AWS CloudFormation.