AWS::CloudFormation::Stack resources whose TemplateURL properties point at child templates stored in Amazon S3. This pattern helps you split large templates into smaller, reusable units and manage them together.
What you’ll build in this walkthrough
- One parent stack that creates two nested (child) stacks.
- Each child stack provisions a single S3 bucket.
- Child templates are stored in an S3 bucket and referenced by the parent template.
- Reuse common infrastructure components across multiple stacks.
- Keep templates readable and maintainable by breaking them into logical units.
- Apply independent updates to child templates while keeping a single parent orchestration point.
- If you have an existing demo stack or related S3 buckets, delete them to get a clean environment.
- After deleting the stack, verify the nested resources (for example, the buckets) are removed.
- Create an S3 bucket to host your CloudFormation templates. Bucket names must be globally unique. In this lesson we use
eden-kodekloud-bkt-961as an example. - Keep templates in the same AWS region where you will create the parent stack.

- When creating the parent stack, choose the “Amazon S3 URL” option for the template source so CloudFormation can retrieve the parent template from your bucket.

- In your project folder (for example in Visual Studio Code) create two files:
first-s3-bkt.yamlsecond-s3-bkt.yaml

first-s3-bkt.yaml
second-s3-bkt.yaml
- Logical IDs (here
FirstBucketandSecondBucket) must be valid CloudFormation logical IDs (alphanumeric, no spaces or special characters). - Child templates can be simple (as shown) or contain parameters, outputs, and many resource types in real-world usage.
- Upload
first-s3-bkt.yamlandsecond-s3-bkt.yamlinto your template bucket. - Open an object’s details and copy its Amazon S3 object URL (the HTTPS object URL). You will use this full URL in the parent template as
TemplateURL.

- Create
parent.yamlin your project. The parent template declaresAWS::CloudFormation::Stackresources pointing to the child template object URLs you uploaded.
parent.yaml (replace these example URLs with the exact S3 object URLs you copied):
parent.yaml to the same S3 bucket (so CloudFormation can retrieve it), then create a new CloudFormation stack that uses the parent template’s S3 URL:
- In the CloudFormation console, choose Create stack -> With new resources (standard).
- Select Amazon S3 URL as the template source and paste the
parent.yamlobject URL.

- CloudFormation reads
parent.yamland provisions two nested stacks as resources:FirstS3StackandSecondS3Stack. - Each nested stack is created independently using the child template referenced by its
TemplateURLand will create the S3 bucket described in that template. - By default, deleting the parent stack deletes the nested stacks and their resources, unless you specify a
DeletionPolicy: Retainor similar retention setting on the nested resources.
Callouts and important reminders
Make sure the S3 object URLs you use in
TemplateURL are the HTTPS object URLs (for example https://bucket-name.s3.<region>.amazonaws.com/first-s3-bkt.yaml). The child templates must be accessible to CloudFormation and must be in the same region as the parent stack. If your S3 bucket blocks public access, ensure CloudFormation can retrieve the objects (for example by granting s3:GetObject to the CloudFormation service principal or using an appropriate bucket policy/role). If templates are stored in a different account or region, ensure the appropriate permissions and cross-account/cross-region considerations are addressed.Logical resource names (CloudFormation logical IDs) cannot contain spaces. Use names like
FirstBucket or SecondBucket. Also ensure your S3 bucket names for storing templates are unique and that the object URLs are correct before creating the parent stack.- Nested stacks let you modularize and reuse CloudFormation templates while managing them from a single parent stack.
- Store child templates in S3 and reference them from a parent template using the
AWS::CloudFormation::Stackresource and itsTemplateURLproperty. - When the parent stack is created, CloudFormation automatically creates the nested stacks and their resources; when the parent is deleted, nested stacks are deleted by default (unless retention policies are applied).