How to specify Cognito User Pool authorizer by ARN not name?

I have “external” UserPool on my AWS account - by external I mean that it’s created through AWS console, not by serverless / CloudFormation template. I want it to stay “external” to serverless stack, I don’t want to specify it in serverless.yml Resources. It works as authorizer (I am passing user pool arn as ENV variable to sls cli/config) however it fails when I want to set preSignUp trigger. From docs it states that I should pass user pool name to cognitoUserPool event. However serverless instead of using existing user pool it creates another one with exactly same name. I am looking for an option to pass user pool ARN instead of name to preSignUp trigger to reference existing user pool. Is it possible? Here is part of my serverless.yml

functions:
  graphql:
    handler: dist/app.handler
    events:
      - http:
          path: graphql
          method: post
          cors: true
          authorizer:
            name: authorizer
            arn: ${env:MEMBER_POOL_ARN} # <- this one works
  convertTextToSpeech:
    handler: dist/backgroundTasks/convertTextToSpeech.handler
    events:
      - sns:
          topicName: convertTextToSpeech
          displayName: Convert text to speech
  preSignUp:
    handler: dist/hooks/preSignUp.handler
    events:
      - cognitoUserPool:
          pool: ${env:MEMBER_POOL_NAME} # <- this one creates another pool with same name (note that I am passing name here, not ARN; passing ARN here generates config validation error)
          trigger: PreSignUp
1 Like

@alekbe any luck with this? Also having the same issues

Serverless can only setup Lambda triggers for Cognito User Pools that it creates because the Lambda trigger configuration is part of the CloudFormation template for the Cognito User Pool. You can still use Serverless to deploy functions that will be used by a User Pool setup outside of Serverless but you need to manually configure the User Pool to use those function. You may also be able to find or write a plugin to handle this for you using a custom event.

I have had the same problem and have a workaround for it. See Linking Lambda Function to an Exiting User Pool

Ok got it. Thanks mate!