将用户名发送到由aws Cognito用户确认的aws Lambda函数 [英] Send username to aws Lambda function triggered by aws Cognito user confirm

查看:77
本文介绍了将用户名发送到由aws Cognito用户确认的aws Lambda函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个Lambda函数,该函数在以新确认的cognito用户命名的s3存储桶中创建一个文件夹。这将使我可以将该用户的访问权限限制为他们的文件夹。我创建了一个Lambda函数,该函数可以使用通过Lambda的测试事件对象传递的用户名在s3中创建一个文件夹。我知道cognito有一个确认事件触发器,并且我选择了要在该触发器上运行的函数,但是我不知道如何从该事件中检索用户名。下面的屏幕截图是我的Lambda代码。

我的lambda函数

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.

让我知道是否需要提供更多信息。我已经看到了有关可能使用亚马逊API网关的信息,但是在一个半小时左右的时间里,我迷上了API网关,但我还没有弄清楚如何解决此问题。

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.

谢谢!
〜Ben

Thanks! ~Ben

推荐答案

很好的问题,在文档中( https://docs.aws.amazon.com/cognito/latest /developerguide/cognito-user-pools-lambda-trigger-syntax-post-confirmation.html ),他们只说了 request.userAttributes 这显然不是

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": {}
}

因此,基本上,只需 event.userName 即可检索用户名。

So basically, just event.userName will retrieve username.

这篇关于将用户名发送到由aws Cognito用户确认的aws Lambda函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆