0

I want to create a few Groups in my AWS Cognito UserPool. I have a stack that is creating the user pool so want to add code similar to

    [
      {
        groupName: 'administrators',
        description:
          'Members can administor this app - our staff only.',
      },
      {
        groupName: 'foo',
        description:
          'bar',
      },
      {
        groupName: 'legends',
        description: 'stars of the game',
      },
    ].forEach((groupProps) => {
      new CfnUserPoolGroup(this, getId(groupProps.groupName), {
        userPoolId,
        ...groupProps,
      });
    });

However, I don't know the userPoolId the first time the Stack runs.

I do happen to know the user pool id for each of my environments now, and this change won't re-create the user pools, so I could pass the user pool id in as a prop, but this will not work for initial creation of the user pool.

There is no userPool.addGroup({groupName, description}); method that I can find

I am using:

    "aws-cdk-lib": "2.64.0",
    "aws-sdk": "2.1312.0",

I think I will need to create a new stack, that is passed in the userPoolId (either as a prop derived from the created userPool, or exported/imported using CfnOutput()), and create the new UserPoolGroups in that stack. That seems a little complicated for what could be a simple task.

Is there an easier way for me to create UserPoolGroups using cdk?

NULL pointer
  • 1,116
  • 1
  • 14
  • 27
  • Not sure I understand the issue - you can just pass the UserPool's `userPoolId` prop, this will work within the same stack. – gshpychka May 04 '23 at 10:56
  • This stack creates the user pool, so I don't know the `userPoolId` when I call this stack. I can add a client to a newly created stack without knowing the userPoolId using userPool.addClient() - but I can't add a new group this way, as there is no userPool.addGroup() method. – NULL pointer May 06 '23 at 06:37
  • Cloudformation will know the pool id after it creates it - it will create the user pool first and then your resource. Just pass the User Pool's `userPoolId` prop, it will be resolved during deployment, after the user pool is created. – gshpychka May 06 '23 at 17:40

0 Answers0