【问题标题】:CloudFormation - Unable to import lambda arn in DefinitionString for StepFunctions StateMachineCloudFormation - 无法在 StepFunctions StateMachine 的 DefinitionString 中导入 lambda arn
【发布时间】:2019-12-12 12:03:57
【问题描述】:

我正在创建 StepFunctions,它引用在单独的 cloudformation 堆栈中创建的 Lambda 函数。 我将 Lambda arn 导出到 CloudFormation 导出。 我想通过导入导出的值来实现从 StepFunctions 引用该 Lambda 函数。

这是我的 cloudformation sn-p。

  StepFunction:
    Type: 'AWS::StepFunctions::StateMachine'
    Properties:
      RoleArn: !GetAtt IamRole.Arn
      DefinitionString: 
        Fn::Sub:
          - |-
            {
              "StartAt": "MessageGenerator",
              "States": {
                "MessageGenerator": {
                  "Comment": "generate queue message.",
                  "Type": "Task",
                  "Resource": "${LambdaMessageGenerator}",
                  "ResultPath": "$",
                  "OutputPath": "$",
                  "Next": "WaitSeconds"
                },
                ...
              }
            }
          - LambdaMessageGenerator:
              Fn::ImportValue: some-export-name

我按照下面的答案做了这个。 Cloudformation - Unable to Import resource

但是,aws cloudformation deploy 命令失败,我收到以下错误。

Invalid State Machine Definition: 'SCHEMA_VALIDATION_FAILED: Value is not a valid resource ARN at /States/MessageGenerator/Resource' (Service: AWSStepFunctions; Status Code: 400; Error Code: InvalidDefinition; Request ID: 01713d53-4605-11e9-9cf3-c15ff9ce09ae)

有人可以帮帮我吗?

【问题讨论】:

  • 能否分享一下您的导出配置?
  • 您是否尝试过删除 Sub 并对 Lambda ARN 进行硬编码,以确保它与您的 DefinitionString 中的任何其他内容都不相关?
  • 解决方案好吗?我什至坚持这一点

标签: aws-lambda amazon-cloudformation aws-step-functions


【解决方案1】:

尝试使用这一行: "Resource": "arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:${LambdaFunctionName}"

在这种情况下,您只需传递 lambda 函数的名称。

【讨论】:

    【解决方案2】:

    为什么不直接使用ImportValue 函数的缩写形式?

    DefinitionString: 
        Fn::Sub:
          - |-
            {
              "StartAt": "MessageGenerator",
              "States": {
                "MessageGenerator": {
                  "Comment": "generate queue message.",
                  "Type": "Task",
                  "Resource": "${LambdaMessageGenerator}",
                  "ResultPath": "$",
                  "OutputPath": "$",
                  "Next": "WaitSeconds"
                },
                ...
              }
            }
          - LambdaMessageGenerator: !ImportValue some-export-name
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-05-21
      • 2019-03-15
      • 2016-04-08
      • 1970-01-01
      • 1970-01-01
      • 2020-10-23
      • 2019-12-23
      • 1970-01-01
      相关资源
      最近更新 更多