Send username to aws Lambda function triggered by aws Cognito user confirm

半世苍凉 提交于 2019-12-07 22:43:02

问题


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


回答1:


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": "asdfsdfsgdfg@carbtc.net"
        }
    },
    "response": {}
}

So basically, just event.userName will retrieve username.



来源:https://stackoverflow.com/questions/49580078/send-username-to-aws-lambda-function-triggered-by-aws-cognito-user-confirm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!