How to pass cognito user information to lambda?

匿名 (未验证) 提交于 2019-12-03 08:44:33

问题:

I'm developing application based on API Gateway and Lambda. I configured POST /subscribe as "AWS_IAM". So now it cannot accessible directly, but I can access to API with Cognito authentication.

Now problem is my Lambda doesn't know who is the API caller. How to know that?

I have 2 users: "Bob" and "John". My Lambda need to know that caller is Bob or John.

Thanks,

回答1:

You can get the Cognito Identity ID from the identity property of the context parameter (context.identity) as explained in the context Object Properties section of the Lambda Programming Model help topic. Once you have the Cognito unique identifier, you can use Cognito Sync's APIs with your developer credentials to look up information stored about this user in Cognito or you can use that identifier to map the ID to user information stored in elsewhere.

Make sure that API Gateway is configured for AWS_IAM (as you mentioned) and make sure that "Invoke with caller credentials" is checked under the method's "Integration Request" settings.



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