Has anyone set up user groups in a cognito user pool in serverless framework? I understand that I can create both a user pool and a user group in the resources section of the .yml file, but the problem I'm facing is that the user group requires the user pool Id (which I don't get back until the user pool is created). I could always deploy without the user groups and then do a second deployment with the user groups after I have the user pool Id, but I'm curious if anyone has had any experience or ideas on how to do this in one single deployment. I'm sure many of you have come across this, but for reference I've added serverless's docs on resources as well as AWS docs on adding user pool and user group resources below. Thanks for the help everyone!!
Serverless docs: https://serverless.com/framework/docs/providers/aws/guide/resources/
User Pool Docs: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-cognito-userpool.html
User Group Docs: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-cognito-userpoolgroup.html
You can create a Cognito user pool and add groups to it in a single deployment. All you need to do is to give the reference of the user pool in the group section. The following code in serverless .yml file creates a Cognito user pool and adds a group to it.
resources:
Resources:
CognitoUserPool:
Type: AWS::Cognito::UserPool
Properties:
UserPoolName: test-user-pool
UsernameAttributes:
- email
AutoVerifiedAttributes:
- email
CognitoUserPoolGroupA:
Type: AWS::Cognito::UserPoolGroup
Properties:
Description: "Description for group A"
GroupName: "group-a"
UserPoolId:
Ref: CognitoUserPool #Refers to the user pool created above
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With