I'm getting this error: Error: Error creating Lambda function: InvalidParameterValueException: The provided execution role does not have permissions to call CreateNetworkInterface on EC2
when trying to create a lambda with IAM permissions like this with custom Lambda role:
...
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}",
]
}
}
...
Creating the lambda works perfectly without any condition (as pointed out in AWS Lambda:The provided execution role does not have permissions to call DescribeNetworkInterfaces on EC2) but I need the role to be able to match the VPC (or ec2:Subnet
arn).
Note: I tried the condition.test with ArnEquals
and StringEquals
.