I am trying to write a Lambda function that makes a folder in an s3 bucket named after a newly confirmed cognito user. This will allow me to keep that user's access limited to their folder. I have created a Lambda function that can create a folder in s3 using a username passed through Lambda's test event object. I know cognito has a "confirmation event" trigger, and I have selected my function to run on that trigger, but I do not know how to retrieve the username from that event. Screenshot below is of my Lambda code.
my lambda function.
Let me know if I need to provide more information. I've seen stuff about possibly using amazon's API gateway but in the hour and a half or so that I've messed with API gateway I haven't come any closer to figuring out how to solve this problem.
Thanks! ~Ben
Amazon Cognito can automatically verify email addresses or phone numbers. To do this verification, Amazon Cognito sends a verification code or a verification link. For email addresses, Amazon Cognito can send a code or a link in an email message. For phone numbers, Amazon Cognito sends a code in an SMS text message.
When a user updates their email address or phone number in your app, Amazon Cognito immediately sends a message with a verification code to a user if you configured your user pool to automatically verify that attribute. The user must then provide the code from the verification message to your app.
You can trigger a Lambda function on DynamoDB table updates by subscribing your Lambda function to the DynamoDB Stream associated with the table. You can associate a DynamoDB Stream with a Lambda function using the Amazon DynamoDB console, the AWS Lambda console, or Lambda's registerEventSource API.
Good question, at documentation (https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-pools-lambda-trigger-syntax-post-confirmation.html) they say only about request.userAttributes
which obviously doesn't contain username.
As I checked, whole event object for post-confirmation trigger looks like this:
{
"version": "1",
"region": "eu-central-1",
"userPoolId": "eu-central-1_45YtlkflA",
"userName": "user4",
"callerContext": {
"awsSdkVersion": "aws-sdk-java-console",
"clientId": "4736lckau64in48dku3rta0eqa"
},
"triggerSource": "PostConfirmation_ConfirmSignUp",
"request": {
"userAttributes": {
"sub": "a2c21839-f9fc-49e3-be9a-16f5823d6705",
"cognito:user_status": "CONFIRMED",
"email_verified": "true",
"email": "[email protected]"
}
},
"response": {}
}
So basically, just event.userName
will retrieve username.
UPDATE
Recent documentation:
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