Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between an Output & an Export

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'?

like image 912
Kirk Broadhurst Avatar asked Jun 18 '20 02:06

Kirk Broadhurst


People also ask

What is different between output and outcome?

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.

What are different outputs?

There are four basic types of output: audio output, graphics output, text output, and video output.

What is the difference between outcome?

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.

What is the difference between outputs and inputs?

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?

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.

What is the difference between input and output devices?

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.

What's the difference between project outputs and outcomes?

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.

What is the difference between an output and an action?

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!


Video Answer


2 Answers

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:

  1. Deploy instance.yaml and wait for its completion.
  2. Note it outputs values (i.e. instance-id) - usually done programmatically, not manually.
  3. Deploy 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:

  1. Upload parrent template (eip.yaml) to s3
  2. In eip.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:

  1. Deploy instance.yaml and wait till it completes.
  2. Deploy 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.

like image 141
Marcin Avatar answered Oct 17 '22 16:10

Marcin


Short answer from here, use export between stacks, and use output with nested stacks.

Export

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.

Output

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.

like image 43
jumping_monkey Avatar answered Oct 17 '22 15:10

jumping_monkey