我收到此错误:Error: Error creating Lambda function: InvalidParameterValueException: The provided execution role does not have permissions to call CreateNetworkInterface on EC2
尝试使用自定义 Lambda 角色创建具有 IAM 权限的 lambda 时:
...
statement {
sid = "MyCustomLamdaStatementDescribe"
actions = [
"ec2:DescribeNetworkInterfaces",
]
resources = ["*"]
}
statement {
sid = "MyCustomLamdaStatementCreateDelete"
actions = [
"ec2:AttachNetworkInterface",
"ec2:CreateNetworkInterface",
"ec2:DeleteNetworkInterface",
"ec2:AssignPrivateIpAddresses",
"ec2:UnassignPrivateIpAddresses",
"ec2:DescribeVpcs"
]
resources = [
"*"
]
condition {
test = "ArnEquals"
variable = "ec2:vpc"
values = [
"arn:aws:ec2:${var.my_region}:${var.my_account_id}:vpc/${var.my_vpc_id}",
]
}
}
...
创建 lambda 可以在没有任何条件的情况下完美运行(如 AWS Lambda 中所指出的:提供的执行角色没有权限在 EC2 上调用 DescribeNetworkInterfaces),但我需要该角色能够匹配 VPC(或ec2:Subnet
arn)。
ArnEquals
注意:我用and尝试了 condition.test StringEquals
。