首页 文章

Cloudformation - 无法导入资源

提问于
浏览
1

我正在创建步骤函数,并希望在 Cloud 形式代码中引用Lambda函数 . lambda已经从单独的堆栈创建,并从该堆栈导出为 LambdaA .

当我尝试将 LambdaA 导入到我的步骤功能代码中时,我遇到了问题 .

这是我的cloudformation片段 .

ABCStateMachine:
Type: 'AWS::StepFunctions::StateMachine'
Properties:
  StateMachineName: 'AbcStateMachine_1.0'
  RoleArn: 
    Fn::GetAtt: [ AbcStateMachineRole, Arn ] 
  DefinitionString: 
    Fn::Sub:
      - |-
        {
          "StartAt": "DoStuff",
          "Version": "1.0",
          "States": {
            "DoStuff" : {
              "Type": "Task",
              "Comment": "Does some stuff.,
              "Resource": {"Fn::ImportValue": "LambdaA"}, # error here
              "Next": "IsStuffDone"
            },
            "IsStuffDone": {
              "Type": "Choice",
            ...
            ...

我在Cloudformation控制台中收到以下错误:

无效的状态机定义:'/ DoStuff / Resource'处的'SCHEMA_VALIDATION_FAILED'(服务:AWSStepFunctions;状态代码:400;错误代码:InvalidDefinition .

知道这里可能有什么问题吗?

1 回答

  • 1

    你不能在 Fn::Sub 函数中使用其他内在函数 . 但是 Fn::Sub 提供了解决这个问题的方法 . 它有点像 format 函数可以在其他编程语言中工作 . 以下是您的特定情况的例子:

    ABCStateMachine:
    Type: 'AWS::StepFunctions::StateMachine'
    Properties:
      StateMachineName: 'AbcStateMachine_1.0'
      RoleArn: 
        Fn::GetAtt: [ AbcStateMachineRole, Arn ] 
      DefinitionString: 
        Fn::Sub:
          - |-
            {
              "StartAt": "DoStuff",
              "Version": "1.0",
              "States": {
                "DoStuff" : {
                  "Type": "Task",
                  "Comment": "Does some stuff.,
                  "Resource": ${LambdaToImport}, # error here
                  "Next": "IsStuffDone"
                }
                ...
              }
              ...
            }
          - LambdaToImport:
              Fn::ImportValue: LambdaA
    

相关问题