In CloudFormation we have the ability to output some values from a template so that they can be retrieved by other processes, stacks, etc. This is typically the name of something, maybe a URL or something generated during stack creation (deployment), etc.
We also have the ability to 'export' from a template. What is the difference between returning a value as an 'output' vs as an 'export'?
Defining business outcomes and outputsThe outcomes are what the business wants or needs to achieve. The outputs are the actions or items that contribute to achieving an outcome.
There are four basic types of output: audio output, graphics output, text output, and video output.
Output is what is created at the end of a process. Outcome is the level of performance or achievement that occurred because of the activity or programs. Outputs are immediate results. Often referred as first level results.
An input device is connected to a computer that sends out data into the computer, while an output device is connected to a computer that receives incoming data.
What is an Output? These are the direct immediate-term results associated with a business project or rather what a business has achieved in the short term. An output results into an outcome.
Input devices An input device can send data to another device, but it cannot receive data from another device. An output device can receive data from another device and generate output with that data, but it cannot send data to another device. An input/output device can receive data from users or another device and also send data to another device.
Project Outputs vs. Outcomes - proposalforNGOs What’s the Difference? Project Outputs vs. Outcomes Both outputs and outcomes are direct results from a project. The two are similar enough that they are often lumped together, but there are some key differences between outputs and outcomes.
There is a slight difference in those terms, but within OKR methodology they mean the same. The output is an action that you take towards your goals. One thing is for sure, they are not measurable outcomes!
Regular output values can't be references from other stacks. They can be useful when you chain or nest your stacks and their scope/visibility is local. Exported outputs are visible globally within account and region, and can be used by any future stack you are going to deploy.
Chaining
When you chain your stacks, you deploy one stack, take it outputs, and use as input parameters to the second stack you are going to deploy.
For example, let's say you have two templates called instance.yaml
and eip.yaml
. The instance.yaml
outputs its instance-id (no export), while eip.yaml
takes instance id as an input parameter.
To deploy them both, you have to chain them:
instance.yaml
and wait for its completion.eip.yaml
and pass instance-id as its input parameter.Nesting
When you nest stacks you will have a parent template and a child template. Child stack will be created from inside of the parent stack. In this case the child stack will produce some outputs (not exports) for the parent stack to use.
For example, lets use again instance.yaml
and eip.yaml
. But this time eip.yaml
will be parent and instance.yaml
will be child. Also eip.yaml
does not take any input parameters, but instance.yaml
outputs its instance-id (not export)
In this case, to deploy them you do the following:
eip.yaml
) to s3eip.yaml
create the child instance stack using AWS::CloudFormation::Stack and the s3 url from step 1.This way eip.yaml
will be able to access the instance-id from the outputs of the nested stack using GetAtt
.
Cross-referencing
When you cross-reference stacks, you have one stack that exports it outputs so that they can be used by any other stack in the same region and account.
For example, lets use again instance.yaml
and eip.yaml
. instance.yaml
is going to export its output (instance-id). To use the instance-id eip.yaml
will have to use ImportValue in its template without the need for any input parameters or nested stacks.
In this case, to deploy them you do the following:
instance.yaml
and wait till it completes.eip.yaml
which will import the instance-id.Altough cross-referencing seems very useful, it has one major issue, which is that its very difficult to update or delete cross-referenced stacks:
After another stack imports an output value, you can't delete the stack that is exporting the output value or modify the exported output value. All of the imports must be removed before you can delete the exporting stack or modify the output value.
This is very problematic if you are starting your design and your templates can change often.
When to use which?
Use cross-references (exported values) when you have some global resources that are going to be shared among many stacks in a given region and account. Also they should not change often as they are difficult to modify. Common examples are: a global bucket for centralized logging location, a VPC.
Use nested stack (not exported outputs) when you have some common components that you often deploy, but each time they can be a bit different. Examples are: ALB, a bastion host instance, vpc interface endpoint.
Finally, chained stacks (not exported outputs) are useful for designing loosely-coupled templates, where you can mix and match templates based on new requirements.
Short answer from here, use export
between stacks, and use output
with nested stacks.
To share information between stacks, export a stack's output values. Other stacks that are in the same AWS account and region can import the exported values.
With nested stacks, you deploy and manage all resources from a single stack. You can use outputs from one stack in the nested stack group as inputs to another stack in the group. This differs from exporting values.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With