serverless / serverless/serverless

Only one Cognito User Pool can be configured per function

Open
#11,314 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
46.9k
Forks
5.7k
Avg merge
10h 7m
Merged PRs (30d)
57

Description

Are you certain it's a bug?
  • Yes, it looks like a bug
Is the issue caused by a plugin?
  • It is not a plugin issue
Are you using the latest v3 release?
  • Yes, I'm using the latest v3 release
Is there an existing issue for this?
  • 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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the multiple-pool event definitions in docs/providers/aws/events/cognito-user-pool.md and reproduce the failure using resources/cognito_hooks.yml with two existing pools on one function. Trace the cognitoUserPool event handling and verify that deployment accepts both pool definitions without the one-pool error.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, javascript
Domain
authentication, backend, cloud
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.