Note the error -- it expects role
instead of policy
.
IAM Policies are documents that define permissions and can't be attached directly to lambda functions. Create an IAM Role and attach the managed policy to the role. Think of the role as a container for your policy; policies can't be attached directly to lambda functions, but roles can. You can freely attach and detach managed and inline policies to your roles.
Option 1: Fix this error from AWS Console with a pre-defined policy:
- Create a new IAM Role for your lambda function.
- During creation, attach the
AmazonCognitoReadOnly
managed policy.
- Replace the ARN in your
role
definition with your new role's ARN.
Option 2: Define actions of AmazonCognitoReadOnly policy in serverless.yml:
This effectively converts the managed policy to an inline policy. Warning: this is untested.
provider:
...
iamRoleStatements:
- Effect: Allow
Action:
- cognito-identity:Describe*
- cognito-identity:Get*
- cognito-identity:List*
- cognito-idp:Describe*
- cognito-idp:AdminGetUser
- cognito-idp:List*
- cognito-sync:Describe*
- cognito-sync:Get*
- cognito-sync:List*
- iam:ListOpenIdConnectProviders
- iam:ListRoles
- sns:ListPlatformApplication
Resource: *
Further Reading: