Describe the bug
Using the add to group. When signing up for a new account I see the following error in cloudwatch
UnhandledPromiseRejectionWarning: InvalidParameterException: 2 validation errors detected: Value '' at 'groupName' failed to satisfy constraint: Member must have length greater than or equal to 1; Value '' at 'groupName' failed to satisfy constraint: Member must satisfy regular expression pattern: [\p{L}\p{M}\p{S}\p{N}\p{P}]
Amplify CLI Version
3.17.0
To Reproduce
Expected behavior
add user to group
Desktop (please complete the following information):
User was created but not added to group as expected.
User was created but not added to group as expected.
Can you show the code of the function pls
@aireater As requested by @davidbiller Could you please share the lambda function code and the group name of the group that you're trying to add the user to?
I ended up deleting it altogether and shelving the functionality while i worked on other features.
In amplify 4.5 i created a new branch and env and updated auth to create the post confirmation add to group. i wanted to isolate my changes and be able to rollback without affecting my stable dev env. it worked.
Then I merged my changes into my dev branch and ran auth update and pushed the file changes to git. I'm using amplify console for CI/CD. This time I got a malformed json exception. I did amplify push from my cli and then it worked.
After i did the push i noticed that the cf templates for the post confirmation lambda (and another lambda) were updated to use the dev env instead of the alpha env.
I realise now that I should have not merged my changes across the branches but just run the amplify auth update in my dev branch. It also seems like these updates are not being pushed via amplify console and must be done using the cli. Is that correct?
Just hit this problem again after upgrading node from version 8 to 10. I'm going to try running auth update.
Here's the error:
code: "UserLambdaValidationException"
​
message: "PostConfirmation failed with error InvalidParameterException: 2 validation errors detected: Value '' at 'groupName' failed to satisfy constraint: Member must satisfy regular expression pattern: [\p{L}\p{M}\p{S}\p{N}\p{P}]+; Value '' at 'groupName' failed to satisfy constraint: Member must have length greater than or equal to 1."
​
name: "UserLambdaValidationException"
Running auth update then building on the server didn't work but pushing from the cli did.
Still having this issue. Here's the code that amplify cli generated:
/* eslint-disable-line */ const aws = require('aws-sdk');
exports.handler = async (event, context, callback) => {
const cognitoidentityserviceprovider = new aws.CognitoIdentityServiceProvider({ apiVersion: '2016-04-18' });
const groupParams = {
GroupName: process.env.GROUP,
UserPoolId: event.userPoolId,
};
const addUserParams = {
GroupName: process.env.GROUP,
UserPoolId: event.userPoolId,
Username: event.userName,
};
try {
await cognitoidentityserviceprovider.getGroup(groupParams).promise();
} catch (e) {
await cognitoidentityserviceprovider.createGroup(groupParams).promise();
}
try {
await cognitoidentityserviceprovider.adminAddUserToGroup(addUserParams).promise();
callback(null, event);
} catch (e) {
callback(e);
}
};
It seems like this issue comes up every time we onboard a new dev and they run amplify env pull dev
where is the group name stored? Is it supposed to be in the cf template? I found this:
"Parameters": {
"GROUP": {
"Type": "String",
"Default": ""
},
I'm thinking that if i can't debug this on my own I'm going to write my own lambda so I don't keep having this problem come up intermittently. Something here keeps breaking.
I have confirmed by adding logging that process.env.GROUP is an empty string.
I ran auth update to see if that would fix it and now "userPoolGroups": true, when it was false. what should this be set to?
I changed this to:
"Parameters": {
"GROUP": {
"Type": "String",
"Default": "Customers"
},
which is what we want. Does that make sense? The error is gone for now.
Confirmed I am getting this too, despite group name being present in team-provider-info.json, it is not updating the value of the Lambda's environment variable.
I also came up against this issue. I was able to solve it using kldeb's approach: https://github.com/aws-amplify/amplify-cli/issues/2841#issuecomment-605198394
Here is a more detailed description of what to do:
1) Open folder amplify > backend > function, find your PostConfirmation function folder and then XXXX-cloudformation-template.json file.
2) Towards the top you will see:
"Parameters": {
"GROUP": {
"Type": "String",
"Default": ""
},
Insert your user group in the blank string next to "Default".
Then run amplify push and it should update and then work from then on.
I feel like a whole bunch of issues could be solved by improving the team-provider-info.json recovery when you perform an env checkout or pull. I always have to restore values from git history as it's totally annoying.
This issue is caused by the fact that functions loose their local settings when you pull or checkout a new env. To get it to work again you need to add the value back (This is where the value comes from originally, and the "default" setting earlier is to hack around this bug):
{
"dev": {
"awscloudformation": {
...
},
"categories": {
"auth": {
...
},
"function": {
"{your-app}PostConfirmation": {
"GROUP": "public"
},
...
},
"notifications": {
...
}
}
}
}
Most helpful comment
I also came up against this issue. I was able to solve it using kldeb's approach: https://github.com/aws-amplify/amplify-cli/issues/2841#issuecomment-605198394
Here is a more detailed description of what to do:
1) Open folder amplify > backend > function, find your PostConfirmation function folder and then XXXX-cloudformation-template.json file.
2) Towards the top you will see:
"Parameters": { "GROUP": { "Type": "String", "Default": "" },Insert your user group in the blank string next to "Default".
Then run
amplify pushand it should update and then work from then on.