2 min read | by Jordi Prats
Lambda functions sometimes might need to interact with other AWS services that depending on how we are configuring it might need some explicit permissions to be set.
For example, if we try to assign a role with the following policy that only allows ssm:PutParameter to a lambda function:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowCreateUpdateDescribeSSMParameters",
"Effect": "Allow",
"Action": [
"ssm:PutParameter",
],
"Resource": "*"
}
]
}
We won't be able to execute the lambda function because it is not allowed to use the VPC to access private resources while the function is running. We'll get an error similar to:
We'll have to add a new policy (or update the existing policy) to explicitly allow some EC2 operations:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowCreateUpdateDescribeSSMParameters",
"Effect": "Allow",
"Action": [
"ssm:PutParameter",
"ssm:DescribeParameters",
"ssm:GetParameter*"
],
"Resource": "*"
},
{
"Sid": "LambdaExecution",
"Effect": "Allow",
"Action": [
"ec2:DescribeNetworkInterfaces",
"ec2:CreateNetworkInterface",
"ec2:DeleteNetworkInterface"
],
"Resource": "*"
}
]
}
Posted on 06/02/2023