我正在尝试创建Lambda角色,并将其附加为允许所有ElasticSearch集群操作的策略。
下面是代码-
resource "aws_iam_role" "lambda_iam" {
name = "lambda_iam"
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [{
"Action": [
"es:*"
],
"Effect": "Allow",
"Resource": "*"
}]
}
EOF
}
resource "aws_lambda_function" "developmentlambda" {
filename = "lambda_function.zip"
function_name = "name"
role = "${aws_iam_role.lambda_iam.arn}"
handler = "exports.handler"
source_code_hash = "${filebase64sha256("lambda_function.zip")}"
runtime = "nodejs10.x"
}
我收到以下错误
Error creating IAM Role lambda_iam: MalformedPolicyDocument: Has prohibited field Resource
有关Resource的Terraform文档说,您可以为所有用户指定一个“ *”。 Principal字段也不是必填字段,因此这不是问题。我仍然将其更改为
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "es.amazonaws.com"
},
"Effect": "Allow",
"Sid": ""
}
]
}
EOF
}
但是那个说-
Error creating Lambda function: InvalidParameterValueException: The role defined for the function cannot be assumed by Lambda.
我的lambda函数定义很简单
resource "aws_lambda_function" "development_lambda" {
filename = "dev_lambda_function.zip"
function_name = "dev_lambda_function_name"
role = "${aws_iam_role.lambda_iam.arn}"
handler = "exports.test"
source_code_hash = "${filebase64sha256("dev_lambda_function.zip")}"
runtime = "nodejs10.x"
}
lambda文件本身不包含任何内容,但我不知道这是否可以解释错误。
我这里缺少什么吗?
假定角色策略是角色的信任策略(允许承担角色),而不是角色的权限策略(角色授予假定实体的权限)。] >
Lambda执行角色需要两种类型的策略。
发生立即错误,“ Lambda无法假定为函数定义的角色”
,因为它需要权限策略中的"Principal": {"Service": "lambda.amazonaws.com"}
,而不是es.amazonaws.com
。我不使用terraform,但是看起来它可能是基于resource "aws_iam_policy"
的https://www.terraform.io/docs/providers/aws/r/lambda_function.html,我认为这是您正在使用的参考。