'Cross referencing Stacks using export variable

Given that I have following stacks -

Stack-A

  • Output variable with export name output-resource-1

Stack-B

  • Has a parameter named base-stack-name which will be initialized to Stack-A during sam deploy

Stack-C

  • Has parameter named 'parent-stack-name' which will be initialized to 'Stack-B' during sam deploy

Now in Stack-C, I am trying to use resource exported in Stack-A. However Stack-C parameters can only accept one stack name as a parameter which is 'Stack-B'. Idea is to use the reference to Stack-A available in Stack-B to access the export variable in Stack-A while creating Stack-C.

So I tried using something like this

Output section of Stack-A definition

  StackAResource:
    Description: StackAResource.
    Value:
      Fn::GetAtt: Database.Endpoint
    Export:
      Name:
        Fn::Sub: ${AWS::StackName}-outout-resource-1

Stack-C definition where above exported resource is trying to be accessed. Stack-C has a parameter named parent-stack-name

- Name: SomeResource
  Value:
    Fn::ImportValue:
      Fn::Sub:
        - ${stackAexportvariable}-output-resource-1
        - stackAexportvariable:
              Fn::Sub: ${parent-stack-name}-base-stack-name

The sam deploy for Stack-C keeps failing and I am not sure how I can get this to work. Any pointers would be appreciated.

I could easily add another parameter for Stack-C base-stack-name and access the exported variable. However as Stack-C is already accepting parent-stack-name, which has the information about base-stack-name , trying to get rid of additional user input.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source