如何在AWS Lambda中获取Cognito身份ID [英] How to get the Cognito Identity id in AWS Lambda
问题描述
如何获取调用AWS Lambda函数的用户的身份ID(由AWS Cognito登录)?我是否必须在Lambda函数上使用SDK来获取身份ID?
How can I get the identity id of the user (logged in by AWS Cognito) that invoked an AWS Lambda function? Do I have to use the SDK on the Lambda function to get the identity id?
推荐答案
每个文档,它看起来像信息有关身份提供者的信息只能通过Mobile SDK进行调用。
Per the docs, it looks like information about the identity provider would only be available for an invoke through the Mobile SDK.
要解决此问题,一种选择是将身份ID作为一部分手动传递给函数事件的假设您正在做类似 AWS.config.credentials = new AWS.CognitoIdentityCredentials(...)
的操作,那么您应该能够通过获取ID。 AWS.config.credentials.identityId
(刷新凭据后)。
To get around this, one option is to pass the identity ID to the function manually as part of the event. Assuming you are doing something like AWS.config.credentials = new AWS.CognitoIdentityCredentials(...)
then you should be able to get the ID via AWS.config.credentials.identityId
(after the credentials are refreshed).
编辑:身份验证是让Cognito / IAM处理它,并假定如果用户可以成功调用Lambda函数,则表示他们被允许。在这种情况下,要管理每个用户的验证,请查看白名单。
EDIT: A better option for identity validation is to let Cognito/IAM handle it, and assume that if a user can successfully invoke a Lambda function, that means they are allowed to. In this case to manage per-user validation, take a look at whitelisting.
这篇关于如何在AWS Lambda中获取Cognito身份ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!