Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using DependsOn with Fn::ImportValue in Cloudformation

Is it possible to use DependsOn with Fn::ImportValue like this?

"DependsOn": {"Fn::ImportValue": {
            "Fn::Sub": "${MyStack1}-VPCGatewayAttachment"
        }}

To be specific, I have my VPC and InternetGatewayAttchment in one stack. I'm import this stack in Stack2 where I have my ELB and I'm trying to use DependsOn to depend on this attachment

like image 722
masterforker Avatar asked Dec 11 '16 08:12

masterforker


People also ask

What is FN :: ImportValue?

Fn::ImportValue. The intrinsic function Fn::ImportValue returns the value of an output exported by another stack. You typically use this function to create cross-stack references. In the following example template snippets, Stack A exports VPC security group values and Stack B imports them.

How do you reference output in CloudFormation?

Listing exported output values Amazon CloudFormation shows the names and values of the exported outputs for the current region and the stack from which the outputs are exported. To reference an exported output value in a stack's template, use the export name and the Fn::ImportValue function.

How do you reference existing resources in CloudFormation?

To import existing resources into a CloudFormation stack, you need to provide: A template that describes the entire stack, including both the resources to import and (for existing stacks) the resources that are already part of the stack. Each resource to import must have a DeletionPolicy attribute in the template.

How do you add condition in CloudFormation?

You can use intrinsic functions, such as Fn::If , Fn::Equals , and Fn::Not , to conditionally create stack resources. These conditions are evaluated based on input parameters that you declare when you create or update a stack.


1 Answers

You should not use DependsOn like this. It is only needed when creating dependencies between resources within a template. Specifically it is used to override the sequence Cloudformation creates resources.

The FN::ImportValue is inherently a dependent function since the Exported Value must exist before stack generation. So just reference your Import Value in the appropriate resource.

like image 112
George M Whitaker Avatar answered Sep 18 '22 23:09

George M Whitaker