Nested & cross-stack references
Compose big infrastructure.
One giant template becomes unmanageable, so CloudFormation offers two ways to compose. Nested stacks make a stack that contains other stacks: a parent template declares AWS::CloudFormation::Stack resources pointing at child templates in S3, passing parameters down and reading outputs back up. The whole tree is created, updated, and deleted as one, which is ideal for reusable building blocks (a standard VPC, a standard bucket) instantiated many times.
Resources:Network:Type: AWS::CloudFormation::StackProperties:TemplateURL: https://s3.../vpc.yamlParameters: { Cidr: 10.0.0.0/16 }App:Type: AWS::CloudFormation::StackProperties:TemplateURL: https://s3.../app.yamlParameters:SubnetId: !GetAtt Network.Outputs.PrivateSubnetId # child output -> parent
Cross-stack references
The other pattern keeps stacks separate and independently deployed, wired by exports. A producer stack exports an Output with a globally-unique name; a consumer stack reads it with !ImportValue. This suits stacks owned by different teams with different lifecycles — a long-lived networking stack exporting subnet IDs that many app stacks import — where nested stacks’ all-as-one lifecycle would be too tightly coupled.
Resources:Lb:Type: AWS::ElasticLoadBalancingV2::LoadBalancerProperties:Subnets:- !ImportValue prod-private-subnet-a- !ImportValue prod-private-subnet-b