【问题标题】:why the function Fn::GetAtt function give me error?为什么函数 Fn::GetAtt 函数给我错误?
【发布时间】:2019-05-17 10:43:28
【问题描述】:

我尝试使用 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",它在 cloud-formation 文件的开头定义。

【问题讨论】:

  • 你通过这个“资源”指的是什么:{“helloworld”:{“角色”:{“参考”:“依赖角色”。我在模板中没有看到它的定义
  • 根据 this:docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/…,您可以从“AWS::Serverless::Function”资源中获得的唯一属性是“Arn”。 “AWS::Lambda::Version”是一个独立的资源。
  • @PrabhatSingh 你想看看哪个定义?依赖角色?也就是本段前面定义的参数

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


【解决方案1】:

对于AWS::Serverless::Function 资源,您可以使用Ref 访问versionalias

更多信息,请参考以下链接:

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"
        ]
      }

【讨论】:

    猜你喜欢
    • 2022-01-11
    • 2019-12-09
    • 1970-01-01
    • 2021-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-10
    • 1970-01-01
    相关资源
    最近更新 更多