Outputs for Stack Information
What you'll learn: How to use CloudFormation outputs to expose important stack values that can be referenced by other stacks or external systems.
What Are Outputs?
Outputs are the final section of a CloudFormation template that lets you export specific values from your stack after it's created. Think of outputs like the "return values" of a function—they let your stack share useful information with the outside world.
Just as you've learned about outputs in Terraform (lessons 764-767), CloudFormation outputs serve a similar purpose: making specific resource attributes visible and accessible after deployment.
Why Use Outputs?
Imagine you create a stack that provisions a VPC with subnets. Other stacks that deploy applications need to know those subnet IDs. Instead of hardcoding values or manually copying them, you define outputs in your VPC stack. Other stacks can then reference these outputs automatically.
Outputs are perfect for:
- Sharing resource IDs (like subnet IDs, security group IDs)
- Exposing endpoint URLs (like load balancer DNS names)
- Providing configuration details to external systems
- Cross-stack references in multi-stack architectures
Output Syntax
Outputs:
VPCId:
Description: "ID of the created VPC"
Value: !Ref MyVPC
WebServerURL:
Description: "Public URL of the web server"
Value: !GetAtt MyLoadBalancer.DNSName
Each output has a logical name, an optional description, and a Value that references resource attributes using functions like !Ref or !GetAtt.
Key Takeaway: CloudFormation outputs expose stack values for cross-stack references and external integration, making your infrastructure modular and interconnected—similar to how Terraform outputs share data between modules.