在移动应用程序中使用 AWS Cognito 注册时推荐的架构是什么?

What is the recommended architecture when using AWS Cognito Signup in a mobile app?

我正在尝试在我的移动应用程序中使用 AWS Cognito 进行身份验证。

目前,我的应用程序的后端将所有用户详细信息存储在 MySQL 中的用户 table 中,并且与其他 table 有关系(比如与订单 table 等)。当我使用 Cognito 注册时,我是否必须先使用 Cognito 注册用户,然后再次将这些详细信息传递到我的后端,以便它可以将详细信息存储在我的用户 table 中?

我们如何处理 Cognito 注册正确通过但当我将详细信息传递到我的应用程序后端时失败的情况(比如因为我的服务器已关闭)?

这里推荐的架构是什么?

When I user Cognito Signup, do I have to first signup the user with Cognito and then again pass on these details to my backend, so that it can store details in my User table?

是的,将用户详细信息保存在用户 table 中也很有用。这将在查询数据库以获取应用程序功能时使用。

How would we handle a case where Cognito signup goes through correctly but it fails when I pass on the details to my app's backend (say because my server was down)?

以容错方式执行此操作,在用户注册(预注册)之前使用来自 Cognito 的 Lambda triggers,Lambda 函数将包含更新数据库的代码,如果成功,Cognito 将继续注册。

When I user Cognito Signup, do I have to first signup the user with cognito and then again pass on these details to my backend, so that it can store details in my User table?

AWS Congnito 提供了在某些 Cognito 事件上调用 Lambda 函数的选项,请参阅 https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-identity-pools-working-with-aws-lambda-triggers.html

在 UserPool 触发器中,您可以定义一个 "Pre-sign up" lambda,当用户提交他们的信息进行注册时将调用该 lambda

How would we handle a case where cognito signup goes through correctly but it fails when I pass on the details to my app's backend (say because my server was down)?

根据文档:

Amazon Cognito invokes Lambda functions synchronously. When called, your Lambda function must respond within 5 seconds. If it does not, Amazon Cognito retries the call. After 3 unsuccessful attempts, the function times out. This 5-second timeout value cannot be changed

有几种选择:

  • 如果需要容错,可以使用SQS来确保可靠传递。在这种情况下,您将需要读取和处理队列

  • 您可以实现自己的错误处理(例如存储、重试、发送邮件等)