Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The role defined for the function cannot be assumed by Lambda

I'm getting the error "The role defined for the function cannot be assumed by Lambda" when I'm trying to create a lambda function with create-function command.

aws lambda create-function
--region us-west-2
--function-name HelloPython
--zip-file fileb://hello_python.zip
--role arn:aws:iam::my-acc-account-id:role/default
--handler hello_python.my_handler
--runtime python2.7
--timeout 15
--memory-size 512

like image 573
Midhun Sudhakar Avatar asked Apr 05 '16 07:04

Midhun Sudhakar


People also ask

Can a Lambda function assume a role?

Note: A Lambda function can assume an IAM role in another AWS account to do either of the following: Access resources—For example, accessing an Amazon Simple Storage Service (Amazon S3) bucket. Do tasks—For example, starting and stopping instances.

How do I restrict access to Lambda function?

You can further restrict access using lambda:AddPermission and lambda:RemovePermission to a principal that is included in a passed policy. You can also limit lambda:UpdateEventSourceMapping and lambda:DeleteEventSourceMapping to a particular event source mapping.


1 Answers

I got the error "The role defined for the function cannot be assumed by Lambda" because i had not updated the roles "Trust Relationship" config file. I didn't encounter the timeout issues as in the linked answer in the comments.

The comments in the above answers pointed out that you need to add the following.

  1. Go to 'IAM > Roles > YourRoleName'
    • (Note: if your role isn't listed, then you need to create it.)
  2. Select the 'Trust Relationships' tab
  3. Select 'Edit Trust Relationship'

Mine ended up like the below.

{   "Version": "2012-10-17",   "Statement": [     {       <your other rules>     },     {       "Effect": "Allow",       "Principal": {         "Service": "lambda.amazonaws.com"       },       "Action": "sts:AssumeRole"     }   ] } 
like image 83
Emile Avatar answered Sep 16 '22 21:09

Emile