serverless icon indicating copy to clipboard operation
serverless copied to clipboard

Only one Cognito User Pool can be configured per function

Open prateeknischal opened this issue 3 years ago • 0 comments

Are you certain it's a bug?

  • [X] Yes, it looks like a bug

Is the issue caused by a plugin?

  • [X] It is not a plugin issue

Are you using the latest v3 release?

  • [X] Yes, I'm using the latest v3 release

Is there an existing issue for this?

  • [X] I have searched existing issues, it hasn't been reported yet

Issue description

I am trying to configure the same set of functions for 2 existing cognito user pools as mentioned in the Multiple User Pool event definitions which allows using multiple cognitoUserPool keys. It fails with an error saying 2 cognito pools can't be configured at the same time with the same function.

Service configuration (serverless.yml) content

service: admin-api

frameworkVersion: ">=2.24.0"

custom:
  ...
  dynamodb:
    start:
      migrate: true
    stages: [dev, stg]

package:
  patterns:
    - '!node_modules/**'
    - '!python/**'
    - '!python.zip'
    - '!.venv'
    - 'resources/**'
    - '!requirements.txt'
    - '!serverless.yml'
    - '!package.json'
    - '!package-lock.json'

provider:
  name: aws
  region: ap-south-1
  runtime: python3.9
  stage: ${opt:stage}
  environment:
    ...
  iam:
    role:
      statements:
        ...

functions:
  - ${file(./resources/cognito_hooks.yml)}

resources:
  - ${file(./resources/api_gateway_authorizer.yml)}
  - ${file(./resources/cognito_user_pool_a.yml)}
  - ${file(./resources/cognito_user_pool_b.yml)}

The cognito_hooks.yml file has

CreateAuthChallenge:
  handler: cognito_hooks/create_auth_challenge.create_auth_challenge
  tags:
    env: ${self:provider.stage}
  events:
    - cognitoUserPool:
        pool: UserPoolA-${self:provider.stage}
        trigger: CreateAuthChallenge
        existing: true
        forceDeploy: true
    - cognitoUserPool:
        pool: UserPoolB-${self:provider.stage}
        trigger: CreateAuthChallenge
        existing: true
        forceDeploy: true

Command name and used flags

sls deploy --config serverless.yml --stage stg --verbose

Command output

✖ Stack admin-api-stg failed to deploy (2s)
Environment: linux, node 16.16.0, framework 3.16.0 (local) 3.17.0v (global), plugin 6.2.2, SDK 4.3.2
Credentials: Local, "default" profile
Docs:        docs.serverless.com
Support:     forum.serverless.com
Bugs:        github.com/serverless/serverless/issues

Error:
Only one Cognito User Pool can be configured per function. In "admin-api-stg-DefineAuthChallenge" you're attempting to configure "UserPoolA-stg" and "UserPoolB-stg" at the same time.

Environment information

Framework Core: 3.16.0 (local) 3.17.0 (global)
Plugin: 6.2.2
SDK: 4.3.2

prateeknischal avatar Aug 07 '22 07:08 prateeknischal