使用与Lamda功能和资源相同的Cognito UserPool?

Kad*_*BOT 5 lambda amazon-web-services amazon-cognito serverless-framework

我正在使用无服务器框架,我需要覆盖Lambda函数创建的UserPool的一些默认值.这样做的正确方法是什么?我serverless.yml正在创建两个user-pool(相同的名称),一个用于lambda函数,另一个用于UserPool资源:

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
Run Code Online (Sandbox Code Playgroud)

Sha*_*era 4

根据https://serverless.com/framework/docs/providers/aws/guide/resources/#aws---resources中的无服务器文档

如果您创建了遵循以下格式的 Cognito 用户池资源CognitoUserPool{normalizedPoolId},您可以为每个 lambda 函数提供normalizedPoolId 。

在您的情况下,您已将 Cognito 用户池定义为“ CognitoUserPool TestPool ”,它允许您在 lambda 中使用 TestPool 。