Skip to content

Cognito Events Transform to Wrong Permission #1253

@chrisoverzero

Description

@chrisoverzero

Description

When creating a Function which responds to Cognito events, like this:

Events:
  UserPoolPreAuthentication:
    Type: Cognito
    Properties:
      UserPool: !Ref TheUserPool
      Trigger: PreAuthentication

...the transformation includes this permission:

"TheFunctionCognitoPermission": {
  "Type": "AWS::Lambda::Permission",
  "Properties": {
    "Action": "lambda:invokeFunction",
    "FunctionName": {
      "Ref": "TheFunction"
    },
    "EventSourceToken": {
      "Ref": "TheUserPool"
    },
    "Principal": "cognito-idp.amazonaws.com"
  }
}

...which I believe is incorrect and causing invocations to fail, blocking (pre-)authentication. The EventSourceToken appears only to be used for Alexa something-something. Permissions for invocation by Cognito should be using SourceArn. (With Fn:GetAtt of the Arn of TheUserPool, natch.)

Steps to Reproduce

  1. Create a SAM template which responds to Cognito events.
  2. Attempt to log in to a Cognito User Pool protected resource.
  3. Note that the error response includes an description of "PreAuthentication invocation failed due to error AccessDeniedException".

Observed Result

The Function is never invoked. Its CloudWatch log stream is never even created.

Expected Result

The, uh, the Function is invoked? I'm not sure what to put here. I'd expect the AWS::Lambda::Permission resource to be well-formed and correct for the service which is expected to be performing the invocation, I guess?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions