aws-cli icon indicating copy to clipboard operation
aws-cli copied to clipboard

Not authorized to perform lambda:InvokeFunction from Cognito User pool trigger

Open JakubMatejka opened this issue 10 years ago • 2 comments

When I update my user pool which includes setting trigger on CustomMessage event like this:

aws cognito-idp update-user-pool --region us-east-1 --user-pool-id us-east-1_z4LAANIWH   --policies '{"PasswordPolicy":{"MinimumLength":8,"RequireUppercase":true,"RequireLowercase":true,"RequireNumbers":true,"RequireSymbols":false}}'   --email-configuration SourceArn=arn:aws:ses:us-east-1:061240556736:identity/... --auto-verified-attributes email   --lambda-config '{"CustomMessage": "arn:aws:lambda:us-east-1:061240556736:function:dev-portal-jm13-dev-authEmailTrigger"}'

and then run lambda function which creates user (using signUp on CognitoIdentityServiceProvider), it fails on such error:

arn:aws:lambda:us-east-1:061240556736:function:dev-portal-jm13-dev-authEmailTrigger invocation failed with error User: arn:aws:sts::745623467555:assumed-role/awscognitoidentityproviderservice-ec2-InstanceRole-QACF32J6RTZ3/i-081606d9e9943df60 is not authorized to perform: lambda:InvokeFunction on resource: arn:aws:lambda:us-east-1:061240556736:function:dev-portal-jm13-dev-authEmailTrigger (Service: AWSLambda; Status Code: 403; Error Code: AccessDeniedException; Request ID: b8d009ff-9b66-11e6-b7e6-eb8cd4c4168f)

However when I clear the trigger and set it again using aws console, the lambda function ends successfully. It is reproducible so when I clear the trigger again and set using cli, the lambda function will fail.

I use cli version aws-cli/1.11.10 Python/2.7.10 Darwin/16.1.0 botocore/1.4.67 on macOS 10.12.1.

JakubMatejka avatar Oct 26 '16 10:10 JakubMatejka

And it looks that the problem is not limited to cli only. When I update the pool using Javascript SDK:

  const emailArn = `arn:aws:ses:${region}:${accountId}:identity/${email}`;
  const messageHandlerArn = `arn:aws:lambda:${region}:${accountId}:function:${name}-${stage}-authEmailTrigger`;
  const provider = new aws.CognitoIdentityServiceProvider({ region });
  provider.updateUserPool({
    UserPoolId: poolId,
    Policies: {
      PasswordPolicy: {
        MinimumLength: 8,
        RequireLowercase: true,
        RequireNumbers: true,
        RequireSymbols: false,
        RequireUppercase: true,
      },
    },
    EmailConfiguration: {
      SourceArn: emailArn,
    },
    AutoVerifiedAttributes: [
      'email',
    ],
    LambdaConfig: {
      CustomMessage: messageHandlerArn,
    },
  }, err => cb(err));

The lambda function fails on the same error too.

JakubMatejka avatar Oct 26 '16 10:10 JakubMatejka

If the behavior is the same between the cli and javascript, then this is an api issue. I would recommend asking on the service forum for api help. The console is probably doing something non-obvious under the hood to make it work, but somebody there should know what that is.

JordonPhillips avatar Oct 26 '16 19:10 JordonPhillips