[AWS] Lab: CloudFormation nested stack
Overview:
- Create an S3 Bucket to store CloudFormation template
- Create Root Stack CloudFormation stack
- Create multi childstacks in rootestack
Create an S3 Bucket to store CloudFormation template
Update two files to the bucket:
noretain.json:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | { "AWSTemplateFormatVersion" : "2010-09-09" , "Resources" : { "S3Bucket" : { "Type" : "AWS::S3::Bucket" , "Properties" : { "AccessControl" : "PublicRead" , "WebsiteConfiguration" : { "IndexDocument" : "index.html" , "ErrorDocument" : "error.html" } } }, "BucketPolicy" : { "Type" : "AWS::S3::BucketPolicy" , "Properties" : { "PolicyDocument" : { "Id" : "MyPolicy" , "Version" : "2012-10-17" , "Statement" : [ { "Sid" : "PublicReadForGetBucketObjects" , "Effect" : "Allow" , "Principal" : "*" , "Action" : "s3:GetObject" , "Resource" : { "Fn::Join" : [ "" , [ "arn:aws:s3:::" , { "Ref" : "S3Bucket" }, "/*" ] ] } } ] }, "Bucket" : { "Ref" : "S3Bucket" } } } }, "Outputs" : { "WebsiteURL" : { "Value" : { "Fn::GetAtt" : [ "S3Bucket" , "WebsiteURL" ] }, "Description" : "URL for website hosted on S3" }, "S3BucketSecureURL" : { "Value" : { "Fn::Join" : [ "" , [ "https://" , { "Fn::GetAtt" : [ "S3Bucket" , "DomainName" ] } ] ] }, "Description" : "Name of S3 bucket to hold website content" } } } |
s3static.json
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | { "AWSTemplateFormatVersion" : "2010-09-09" , "Resources" : { "S3Bucket" : { "Type" : "AWS::S3::Bucket" , "Properties" : { "AccessControl" : "PublicRead" , "WebsiteConfiguration" : { "IndexDocument" : "index.html" , "ErrorDocument" : "error.html" } }, "DeletionPolicy" : "Retain" }, "BucketPolicy" : { "Type" : "AWS::S3::BucketPolicy" , "Properties" : { "PolicyDocument" : { "Id" : "MyPolicy" , "Version" : "2012-10-17" , "Statement" : [ { "Sid" : "PublicReadForGetBucketObjects" , "Effect" : "Allow" , "Principal" : "*" , "Action" : "s3:GetObject" , "Resource" : { "Fn::Join" : [ "" , [ "arn:aws:s3:::" , { "Ref" : "S3Bucket" }, "/*" ] ] } } ] }, "Bucket" : { "Ref" : "S3Bucket" } } } }, "Outputs" : { "WebsiteURL" : { "Value" : { "Fn::GetAtt" : [ "S3Bucket" , "WebsiteURL" ] }, "Description" : "URL for website hosted on S3" }, "S3BucketSecureURL" : { "Value" : { "Fn::Join" : [ "" , [ "https://" , { "Fn::GetAtt" : [ "S3Bucket" , "DomainName" ] } ] ] }, "Description" : "Name of S3 bucket to hold website content" } } } |
Create Root Stack CloudFormation stack
- Create template in Designer
- Create a root stack template
{ "AWSTemplateFormatVersion" : "2010-09-09", "Resources" : { "myStack" : { "Type" : "AWS::CloudFormation::Stack", "Properties" : { "TemplateURL" : "https://<YOUR_SE_BUCKET>/noretain.json", "TimeoutInMinutes" : "60" } } } }
3. Validate template and create stack
4. Give stack a name and accept all default configuration.
What we have done is creating a rootStack and a child stack.
In rootStack, it only has childStack
In childStack, it has S3.
If we delete the Root Stack, Child Stack will be deleted as well. And S3 in Childstack will also be deleted.
Create multi ChildStaks in RootStack
Create CloudFormation rootStack:
{ "AWSTemplateFormatVersion" : "2010-09-09", "Resources" : { "myStack" : { "Type" : "AWS::CloudFormation::Stack", "Properties" : { "TemplateURL" : "https://<your_s3_bucket>/s3static.json", "TimeoutInMinutes" : "60" } }, "myStack2" : { "Type" : "AWS::CloudFormation::Stack", "Properties" : { "TemplateURL" : "https://<your_s3_bucket>/noretain.json", "TimeoutInMinutes" : "60" } } } }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
2020-04-10 [RxJS] Building an RxJS Operator
2020-04-10 [RxJS] Build an Event Combo Observable with RxJS (takeWhile, takeUntil, take, skip)
2018-04-10 [Tailwind] Style Elements on hover and focus with Tailwind’s State Variants
2018-04-10 [Tailwind] Apply mobile-first Responsive Classes in Tailwind
2018-04-10 [Tailwind] Create Custom Utility Classes in Tailwind
2018-04-10 [Tailwind] Get started with Tailwindcss
2017-04-10 [tmux] Copy and paste text from a tmux session