Search code examples
amazon-web-servicesaws-cloudformation

How to pass parameters between one cloud formation to another cloud formation template


How to pass parameters between one cloud formation template file to another cloud formation template file in aws ? I am not talking about the nested templates , as I understand they are seperate resource blocks within one CFT only , please correct me if I am wrong.


Solution

  • Check out the official documentation for cross-stack references and how it can be used.

    The basic idea is that you'll have shared resources put into their own stack so that other stacks can reference those resources. This leads to less copy/paste in all of your cloud formation templates.

    For example, you might have multiple related web applications that use the same security group rules for their servers. Rather than defining the same exact security group multiple times in each cloud formation template for each web application, you can put that security group into its own template/stack, declare the security group id as an output, and then in all of your web applications' cf templates, you can import that security group id and reference it for your instance's security group. This leads to less duplicate code, and a separation of concerns, as a network engineer can manage the security around the VPC/subnets/security groups and you only need to worry about your servers/applications.