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?