Use same Cognito UserPool with Lamda Function and Resources?

Viewed 1035

I'm using the serverless framework and I need to override some default values for the UserPool created by the Lambda function. What's the correct way to do it? My serverless.yml is creating two user-pool (same name), one for the lambda function and another for the UserPool resource:

service: userpool

custom:
  stage: dev
  poolName: user-pool

provider:
  name: aws
  runtime: nodejs6.10
  stage: ${opt:stage, self:custom.stage}

functions:
  preSignUp:
    handler: handler.preSignUp
    events:
      - cognitoUserPool:
          pool: ${self:custom.poolName}
          trigger: PreSignUp

resources:
  Resources:
    UserPool:
      Type: "AWS::Cognito::UserPool"
      Properties:
        UserPoolName: ${self:custom.poolName}
        AliasAttributes:
          - email
        AutoVerifiedAttributes:
          - email
        Schema:
          - Name: name
            AttributeDataType: String
            Mutable: true
            Required: true
          - Name: email
            AttributeDataType: String
            Mutable: false
            Required: true
3 Answers

This problem solved in a better way in new release:

Add support for existing Cognito User Pools

Your function event should look like this:

functions:
  preSignUp:
    handler: handler.preSignUp
    events:
      - cognitoUserPool:
          pool: ${self:custom.poolName}
          trigger: PreSignUp
          existing: true

No need to add additional "CognitoUserPool" in front of the resource definition.

Related