【发布时间】:2021-09-28 11:15:12
【问题描述】:
我正在尝试使用 cloudformation 模板中的现有角色(存在于 AWS 账户中)来设置 lambda 函数,我计划在多个 AWS 账户中使用它。
在 CF 模板中,我使用参数来设置角色的名称,然后在 Lambda 函数的角色属性中使用 Ref。这就是我的模板的样子,
"Parameters" : {
"ExistingRoleName" : {
"Type" : "String",
"Default" : "MyCustomRole"
}
"Resources" : {
"CustomLambdaFunction" : {
"Type" : "AWS::Lambda::Function",
"Properties" : {
"MemorySize" : "128",
"Role" : { "Ref" : "ExistingRoleName" },
}
},
...
但是,CF 模板失败并出现以下错误:
Properties validation failed for resource CustomLambdaFunction with message: #/Role: failed validation constraint for keyword [pattern]
这是因为 Cloudformation 中的 Lambda 资源需要角色 arn 而不是我在此文档中看到的 RoleNameaws-resource-lambda-function
基于我这样更新CF,
"Resources" : {
"CustomLambdaFunction" : {
"Type" : "AWS::Lambda::Function",
"Properties" : {
"MemorySize" : "128",
"Role" : "arn:aws:iam::AccountID:role/MyCustomRole",
}
},
但是,我仍然看到同样的错误。
Properties validation failed for resource CustomLambdaFunction with message: #/Role: failed validation constraint for keyword [pattern]
我想知道我是否在这里遗漏了什么?
【问题讨论】:
-
arn 看起来不错。也许您实际使用的那个不正确,此处未显示。
-
另外,我猜
AccountID只是一个占位符,而不是您真实代码中的实际字符串?
标签: amazon-web-services aws-lambda amazon-cloudformation