Justin
Justin

Reputation: 4853

Getting an ARN for an imported Kinesis stream

I have two nested Cloudformation stacks - the first template needs to define a Kinesis stream, the second needs to use a reference to that stream's ARN, as an argument to a further nested stack.

So it seems I need to "export" the stream from the first template, and "import" it into the second (following AWS docs on importing/exporting values across stacks) -

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-importvalue.html

My export code [truncated] looks like this -

Outputs:
  MyKinesisStreamOutput:
    Value:
      Ref: MyKinesisStream
    Export:
      Name: my-kinesis-stream      
Resources:
  MyKinesisStream:
    Properties:
      Name:
        Ref: AppName
      ShardCount: 1
    Type: AWS::Kinesis::Stream

Whilst my import code [truncated] looks like this -

MyNestedStack:
  Type: AWS::CloudFormation::Stack
  Properties:
    TemplateURL: !Sub "https://s3.${AWS::Region}.amazonaws.com/my-nested-stack.yaml"
    Parameters:
      AppName: my-nested-stack
      KinesisStream:
        Fn::GetAtt:
          - Fn::ImportValue:
              my-kinesis-stream
          - Arn

But then I get the following Cloudformation error -

Template error: every Fn::GetAtt object requires two non-empty parameters, the resource name and the resource attribute

and suspect I am falling foul of this -

For the Fn::GetAtt logical resource name, you cannot use functions. You must specify a string that is a resource's logical ID.

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-getatt.html

Assuming I am exporting and importing the Kinesis stream correctly, how then am I supposed to get its Arn value ?

Upvotes: 2

Views: 2111

Answers (2)

lexicore
lexicore

Reputation: 43671

When you export something in Outputs, it's just a string, you can no longer GetAtt on it in the importing template.

What you need to do is to additionally export ARN:

Outputs:
  MyKinesisStream:
    Value: !Ref MyKinesisStream
    Export:
      Name: my-kinesis-stream
  MyKinesisStreamArn:
    Value: !GetAtt MyKinesisStream.Arn
    Export:
      Name: my-kinesis-stream-arn

Upvotes: 7

gapvision
gapvision

Reputation: 1029

I can think of two potential ways:

1) Fn::GetAtt:[!ImportValue my-kinesis-stream, Arn]

Sorry wasn't reading carefully enough

or what I would prefer

2) Directly export the required value as output: Value: !GetAtt MyKinesisStream.Arn

Hope that helps!

Upvotes: 2

Related Questions