Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Output a list in cloud formation

I have a parameter:

  ClusterSubnets:
    Description: Subnets where cluster will reside.
                Typically private.  Use mutiples, each in a different AZ for HA.
    ConstraintDescription: comma separated list of valid Subnet IDs
    Type: List<AWS::EC2::Subnet::Id>

I'm trying to output this:

  ClusterSubnets:
    Description: Subnets used by cluster
    Value: !Ref ClusterSubnets
    Export:
      Name: !Sub "${AWS::StackName}-ClusterSubnets"

But I get this error: Template format error: The Value field of every Outputs member must evaluate to a String.

How can I export a list?

like image 734
Neil H Watson Avatar asked Nov 30 '17 16:11

Neil H Watson


People also ask

What is output in cloud formation?

All. The optional Outputs section declares output values that you can import into other stacks (to create cross-stack references), return in response (to describe stack calls), or view on the AWS CloudFormation console. For example, you can output the S3 bucket name for a stack to make the bucket easier to find.

How do I export output from CloudFormation?

To export a stack's output value, use the Export field in the Output section of the stack's template. To import those values, use the Fn::ImportValue function in the template for the other stacks. For a walkthrough and sample templates, see Walkthrough: Refer to resource outputs in another AWS CloudFormation stack.

What is output in AWS?

Outputs enable you to get access to information about resources within a stack. For example, you can output an EC2 instance's Public DNS name once it is created. Furthermore, output values can be imported into other stacks. These are known as cross-stack references.

How do you reference output from another CloudFormation stack?

To create a cross-stack reference, use the export field to flag the value of a resource output for export. Then, use the Fn::ImportValue intrinsic function to import the value in any stack within the same AWS Region and account. AWS CloudFormation identifies exported values by the names specified in the template.


1 Answers

You need to join the elements of the list into a string. Try something like this:

ClusterSubnets:
    Description: Subnets used by cluster
    Value: !Join
        - ','
        - !Ref ClusterSubnets
    Export:
        Name: !Sub "${AWS::StackName}-ClusterSubnets"

Here is the relevant AWS documentation.

like image 195
Miles Avatar answered Dec 01 '22 20:12

Miles