【发布时间】:2021-09-26 07:48:36
【问题描述】:
在创建我的 lambda 堆栈时,我使用了一个名为 LambdaExecutionRole 的角色,然后我通过 fn::GetAtt 引用了 ARN
"Role": {"Fn::GetAtt": ["LambdaExecutionRole","Arn"]},
,就像文档说的那样,然后我收到错误消息,指出指定的资源不支持 GetAtt。所以我尝试了 GetAtt,我被退回了:
Properties validation failed for resource GetECLambda with message: #/Code/S3Bucket: failed validation constraint for keyword [pattern] #/Role: expected type: String, found: JSONObject
我也试过"Role":{ "!Ref" : "LambdaExecutionRole"},
据我了解,其中一个应该返回一个字符串,因此将提供一个字符串,而不是 JSON 对象。但问题可能是字符串的定义如下:{“The Arn”},但我不确定如何避免这种情况。
我的lambda结构和作用如下:
{
"AWSTemplateFormatVersion" : "2010-09-09",
"Description" : "Stack to create the get-EC lambda",
"Resources" : {
"LambdaExecutionRole": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Version": "2012-10-17",
"Statement": [{ "Effect": "Allow", "Principal": {"Service": ["lambda.amazonaws.com"]}, "Action": ["sts:AssumeRole"] }]
},
"Path": "/",
"Policies": [{
"PolicyName": "root",
"PolicyDocument": {
"Version": "2012-10-17",
"Statement": [{ "Effect": "Allow", "Action": ["logs:*"], "Resource": "arn:aws:logs:*:*:*" }]
}
}]
}
},
"GetECLambda" : {
"Type" : "AWS::Lambda::Function",
"Properties" : {
"FunctionName": "get-ecs",
"Role":{ "!Ref" : "LambdaExecutionRole"},
"Runtime": "nodejs12.x",
"Code": {
"S3Bucket" : "arn:aws:s3:::flex-fit-lambda-functions-source",
"S3Key": "get-ecs.zip"
}
}
}
}
}
【问题讨论】:
-
我猜你不能使用 !Ref 作为 JSON 格式。正如你在这里看到的docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/… !Ref 仅适用于 YML 格式
-
@CyberEternal 是的,我发现了,所以我用 {"Ref" : "LambdaExecutionRole"} 替换了它,我仍然遇到与预期字符串相同的错误。
-
这很奇怪,因为我可以使用
"Role": { "Fn::GetAtt" : ["LambdaExecutionRole", "Arn"] },运行堆栈 -
@CyberEternal 抱歉,我说的不太对。我收到此错误:
Properties validation failed for resource GetEmergencyContactsLambda with message: #/Code/S3Bucket: failed validation constraint for keyword [pattern]这可能与我的存储桶与 ACL 中的 zip 文件有关吗?我没有修改它,因为我认为如果我可以访问它并且我正在执行堆栈,它将使用我的权限。最重要的是,我实际上无法理解该错误消息试图告诉我什么。
标签: amazon-web-services aws-lambda amazon-cloudformation amazon-iam