在 cloudformation 模板中的 Step 函数中使用 Ref 作为 Resource

Using Ref for Resource in Step function inside cloudformation template

我在 cloudformation 中有一个步骤函数。 cloudformation 堆栈还创建了 Lambdas,我将在 step 函数中将其用作资源。我有类似的东西

TestLambda:
  Type: "AWS::Lambda::Function"
  Properties:
    Handler: "test_lambda.lambda_handler"
    Role: "arn:aws:iam::1234342334:role/Lambda"
    Code:
      ZipFile: !Sub |
        from __future__ import print_function
        import boto3
        def lambda_handler(event, context):
          print(event)
    Runtime: "python2.7"

  ....

TestStateMachine:
  Type: AWS::StepFunctions::StateMachine
  Properties:
    StateMachineName: "Test"
    DefinitionString: |-
      {
        "StartAt": "State1",
        "States": {
          "State1" : {
            "Type" : "Task",
            "Resource" : "${!GetAtt TestLambda.Arn}",
            "Next": "State2?"
          },
      ... 
      ...

全部在一个 cloudformation 模板中。

"SCHEMA_VALIDATION_FAILED: Value is not a valid resource ARN"

我也尝试了 !GetAtt TestLambda.Arn,但没有成功。我想要在单个 cloudformation 模板中创建 lambda 和 stepfunction。如果有更好、更清洁的方法,请告诉我。

谢谢

您应该为此使用 Fn::Sub 函数:

TestStateMachine:
  Type: AWS::StepFunctions::StateMachine
  Properties:
    StateMachineName: "Test"
    DefinitionString: 
      Fn::Sub:
        |-
          {
            "StartAt": "State1",
            "States": {
              "State1" : {
                "Type" : "Task",
                "Resource" : "${TestLambda.Arn}",
                "Next": "State2?"
          },