How to specify an existing cognito user pool in servreless.yml?

aws

#1

I am trying to write the lambda function for custom message used for cognito user pool. I have something like this in my serverless.yml

events:

  • cognitoUserPool:
    pool: my_pool
    trigger: CustomMessage

“my_pool” is the pool name of an existing cognito user pool. After deployment, a new pool named “my_pool” is created. I deleted the new “my_pool”, and hoping my old “my_pool” will be used.

When I try to deploy again, I got an error like this: "User pool us-west-2_xxxxxxx does not exist. " “us-west-2_xxxxxxx” is the pool id of the newly created “my_pool”, which I already deleted.

My question is how can I specify an existing user pool in serverless.yml? I don’t need serverless to create a new pool for me. Is there a way to specify the pool id or pool arn?

Thanks!


#2

I have the same question.
I was hoping that overriding the AWS resource would help, but it didn’t work for me:

See section: “Override AWS CloudFormation Resource”


#3

I am having the same problem, using serverless to manage my backend services on AWS.

I’ve divided my project into two stacks: one that defines all the lambdas, and another that defines only resources, such as DynamoDB tables, and User Pools.

I’m now stuck not knowing how to define my PreSignUp trigger in the service stack, so that it will reference a User Pool that’s already been created. I can always manually go into the User Pool console and select the correct lambda, but that just seems wrong…

I’ve tried using an ARN where pool is specified, but I get a validation error (no colons accepted for example):

- cognitoUserPool:
    pool: "arn:aws:cognito-idp:us-east-1:XXXX:userpool/us-east-1_XXXXX"
    trigger: PreSignUp

The above does not work, so I’d like to know how to do this correctly.


#4

I am having the very same issue. I do not want to create the user pool again. Why can we not reference an already existing Arn for user pool?


#5

Well looks like I’m in the same boat with everyone else on this thread. Has nobody figured out a way to deal with this? I also have an existing user pool created and would love to just define my serverless.yml file to point to this user pool, but I cannot figure out how to do this.


#6

I found this in cloudformation docs, Im a newb so not really sure how this works, but I I think serverless uses cloudformation under the hood?

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-cognito-userpoolclient.html


#7

I am also dividing my app into 2 stacks as @tcchau is doing and ended up doing it backwards. The Cloudformation stack that defines the Cognito user pool specifies the ARN for the lambda trigger rather than letting Serverless try to connect the trigger to the user pool. This works because Cloudformation and/or Cognito does not seem to care that the user pool trigger configuration references a lambda that might not exist. This is ugly but gets around having to manually connect the pool to the trigger


#8

Thanks guys, I appreciate the response.