【问题标题】:Getting an ARN for an imported Kinesis stream为导入的 Kinesis 流获取 ARN
【发布时间】:2019-12-27 10:05:10
【问题描述】:

我有两个嵌套的 Cloudformation 堆栈 - 第一个模板需要定义 Kinesis 流,第二个模板需要使用对该流的 ARN 的引用,作为进一步嵌套堆栈的参数。

所以看来我需要从第一个模板中“导出”流,然后将其“导入”到第二个模板中(遵循 AWS 文档中关于跨堆栈导入/导出值的说明)-

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

我的导出代码 [截断] 看起来像这样 -

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

虽然我的导入代码 [截断] 看起来像这样 -

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

然后我收到以下 Cloudformation 错误 -

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

怀疑我犯了这个错误-

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

假设我正确导出和导入 Kinesis 流,那么我应该如何获取其 Arn 值?

【问题讨论】:

    标签: amazon-web-services amazon-cloudformation amazon-kinesis


    【解决方案1】:

    我可以想到两种可能的方法:

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

    抱歉没有仔细阅读

    或者我更喜欢什么

    2) 直接导出需要的值作为输出:Value: !GetAtt MyKinesisStream.Arn

    希望有帮助!

    【讨论】:

    • "first" 似乎是相对的 :)
    【解决方案2】:

    当你导出Outputs中的东西时,它只是一个字符串,你不能再在导入模板中GetAtt

    您需要做的是额外导出 ARN:

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

    【讨论】:

    • 很高兴知道您已经成功了!您能否同时发布第一个堆栈中的输出设置和第二个(嵌套)堆栈中的导入代码,因为我目前遇到了完全相同的问题。谢谢!
    • @user3792245 请参阅我对 Outputs 的回答和导入代码的 OP 问题。
    • 谢谢@lexicore。我可以在第一个堆栈中看到输出,但是当我尝试在第二个堆栈中导入它时,我收到以下错误“无效的模板参数属性 'Fn::GetAtt'”
    • @user3792245 您可能想问一个单独的问题。并确保包含您的模板(它们的minimal reproducible example 版本)。
    猜你喜欢
    • 1970-01-01
    • 2020-06-22
    • 2022-08-11
    • 2018-10-12
    • 1970-01-01
    • 2016-03-31
    • 2020-05-12
    • 2021-12-18
    • 1970-01-01
    相关资源
    最近更新 更多