CloudFormation Stack Export
Welcome to CloudAffaire and this is Debjeet.
In the last blog post, we have discussed CloudFormation StackSets.
In this blog post, we are going to discuss how to share information between stacks using Stack Export.
CloudFormation Stack Export:
To share information between stacks, we can export a stack’s output values. Other stacks that are in the same AWS account and region can then import the exported values. To export a stack’s output value, we can use the Export field in the Output section of the stack’s template. To import those values, we can use the Fn::ImportValue function in the template for the other stacks.
In this demo, we are going to create two stacks, one for VPC creation and one for Subnet creation. The VPC creation stack will output the vpc-id data and using Fn:ImportValue function in the subnet creation stack, we will import the vpi-id required to create the Subnet.
Step 1: Login to AWS console and navigate to ‘CloudFormation’.
Step 2: Create a stack named ‘myVpcSTACK’ with below YAML code.
- Key: "Name"
Description: VPC id
Value: !Ref myVPC
Or you can use Stack_export_demo_create_vpc.yaml from below GitHub repo.
Observe: We have exported the VPC-ID value from myVpcSTACK stack in the form of output.
You can also view all the exports under ‘Export’ tab.
Next, we are going to create another stack for subnet creation using exported vpi-id of the 1st stack.
Step 3: Create a stack named ‘mySubnetSTACK’ with below YAML code.
Description: "Source stack name"
- Key: "Name"
Or you can use Stack_export_demo_create_subnet.yaml from below GitHub repo.
Note: You have to pass the 1st stack name (myVpcSTACK) as a parameter in the 2nd stack.
You can view the stack import details under ‘Export details’ of the export.
Hope you have enjoyed this article. In the next blog post, we will CloudFormation stack change sets.
To get more details on CloudFormation, please refer below AWS documentation