aws-lambdaterraformamazon-iamrolespolicy

The provided execution role does not have permissions to call DescribeNetworkInterfaces on EC2


When I input any code in this function (e.g. console.log();) and click "Save", an error occurs:

The provided execution role does not have permissions to call DescribeNetworkInterfaces on EC2

exports.handler = (event, context, callback) => {
  callback(null, 'Hello from Lambda');
  console.log(); // here is my code   
};

I bound the function with Role: lambda_excute_execution(Policy:AmazonElasticTranscoderFullAccess).

And this function is not bound with any triggers now.

And then, I give the role AdministratorAccess Policy, I can save my source code correctly.

This role could run Functions successfully before today.

Does anyone know this error?


Solution

  • This error is common if you try to deploy a Lambda in a VPC without giving it the required network interface related permissions ec2:DescribeNetworkInterfaces, ec2:CreateNetworkInterface, and ec2:DeleteNetworkInterface (see AWS Forum).

    For example, this a policy that allows to deploy a Lambda into a VPC:

    {
      "Version": "2012-10-17",
      "Statement": [
        {
          "Effect": "Allow",
          "Action": [
            "ec2:DescribeNetworkInterfaces",
            "ec2:CreateNetworkInterface",
            "ec2:DeleteNetworkInterface",
            "ec2:DescribeInstances",
            "ec2:AttachNetworkInterface"
          ],
          "Resource": "*"
        }
      ]
    }