Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use same Cognito UserPool with Lamda Function and Resources?

Tags:

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
like image 997
KadoBOT Avatar asked Aug 10 '17 11:08

KadoBOT


1 Answers

As per the Serverless documentation in https://serverless.com/framework/docs/providers/aws/guide/resources/#aws---resources

If you have created a Cognito User Pool resource which follows this format CognitoUserPool{normalizedPoolId}, you can give the normalizedPoolId for each of your lambda functions.

In your case you have defined the Cognito User Pool as "CognitoUserPoolTestPool" which allows you to use TestPool in your lambdas.

like image 125
Shamal Perera Avatar answered Oct 17 '22 03:10

Shamal Perera