代码之家  ›  专栏  ›  技术社区  ›  user504909

为什么函数fn::getatt函数给出错误?

  •  0
  • user504909  · 技术社区  · 6 年前

    我尝试使用fn::getatt函数计算权限并引用。我的cloudformation json是: 定义的资源部分是:

    "Resources": {
    "helloworld": {
      "Properties": {
        "AutoPublishAlias": "live",
        "Handler": "index.handler",
        "Runtime": "nodejs6.10",
        "CodeUri": "s3://ss-sheng/src/helloWorld.zip",
        "Role": {
          "Ref": "dependrole"
        },
        "Timeout": 3,
        "ReservedConcurrentExecutions": 5,
        "Tags": {
          "PROJECT": "My Point",
          "COST_CENTRE": "6400073401",
          "BUSINESS_UNIT": "My Programs",
          "BUSINESS_CONTACT": "Greg Windsor",
          "TIER": "Development"
        }
      },
      "Type": "AWS::Serverless::Function"
    },
    "helloworldpermission": {
      "DependsOn": "helloworld",
      "Properties": {
        "Action": "lambda:InvokeFunction",
        "FunctionName": {
          "Fn::Join": [
            ":",
            [
              {
                "Ref": "helloworld"
              },
              {
                "Fn::GetAtt": [
                  "helloworld",
                  "Version"
                ]
              }
            ]
          ]
        },
        "Principal": "apigateway.amazonaws.com"
      },
      "Type": "AWS::Lambda::Permission"
    }
    }
    

    我得到错误:

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

    我已经给他们两个参数“helloworld”和“version”。 为什么lambda函数仍然显示错误?

    helloworld引用无服务器函数helloworld。

    我使用“transform”:“aws::serverless-2016-10-31”,这是在云形成文件的开头定义的。

    1 回复  |  直到 6 年前
        1
  •  0
  •   Biplob Biswas    6 年前

    为了 AWS::Serverless::Function 资源,您可以访问 version alias 使用 Ref

    有关详细信息,请参阅以下链接:

    https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#referencing-lambda-version--alias-resources

    因此,而不是

    {
            "Fn::GetAtt": [
              "helloworld",
              "Version"
            ]
          }
    

    应该是,

    {
            "Fn::Ref": [
              "helloworld",
              "Version"
            ]
          }