首页 > 解决方案 > Accessing Cognito user attributes from Appsync

问题描述

Imagine that you have a simple AWS stack with Appsync, Aurora RDS and Cognito.

Obviously, Cognito manages the users registration process, where each user has a few attributes, let's say email, first_name, and last_name.

Also there is a table called users in Aurora RDS, which, among other columns, has the cognito_id column where it stores the reference to the Cognito users' IDs.

The last thing is AppSync GraphQL query that would list all the available users with fields that should come both from the users RDS table and Cognito attributes. And that's where the question arises.

If it was needed to only fetch attributes from the users table, the problem would be solved with some small and tidy SQL query that could be put into the AppSync VTL request template. But since it's also required to get the attributes from the Cognito users pool, things get complicated.

How could something like that be done in an efficient and scalable way? Or is it a bad design and there's a better way to do it?

标签: amazon-web-servicesserverless-framework

解决方案


我的经验告诉我在使用 Cognito 时不要有表 Users。我们可以在 Cognito 属性中保存的所有数据。但也许它需要你。但是,您可以将 Lambda 函数用作 AppSync 数据源。并在 Lambda 函数中从 Cognito 获取数据。


推荐阅读