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.
I am just learning to use the AWS CLI and ran into this issue.
I am using a series of PowerShell scripts to deploy an entire AWS architecture. My createRole.ps1 script contains:
aws iam create-role `
--role-name $roleName `
--assume-role-policy-document file://myRoleTrustPolicy.json
The file myRoleTrustPolicy.json contains:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": [
"elasticmapreduce.amazonaws.com",
"datapipeline.amazonaws.com",
"lambda.amazonaws.com"
]
},
"Action": "sts:AssumeRole"
}
]
}
It is the "lambda.amazonaws.com" line that was missing from Service list that was causing the issue.
Once I fixed that, the invocation of aws lambda create-function worked great.
aws lambda create-function `
--function-name $fn `
--runtime java8 `
--role $currentRoleARN `
--handler "handleRequest" `
--memory-size 128 `
--zip-file $jarFile