Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to synchronise RDS DB and Cognito

I'm pretty new in all the AWS Tools BTW. Anyhow, I already created the Cognito User Pool and I can create and login new users but I also need those fields in my RDS database.

Yesterday I was reading docs and tutorials about the problem but looks like there is a lot of ways to synchronise two data sources. I don't know if something like AppSync has the options to do that or I need to write a two steps lambda, so I'm looking for advice for more experienced users like you guys.

like image 906
aarkerio Avatar asked Feb 03 '19 19:02

aarkerio


People also ask

When using Amazon Cognito Sync to sync information back to Cognito the smallest amount of data you can operate on is?

Amazon Cognito associates this data with an identity in your identity pool so that your app can access it across logins and devices. To sync this data between the Amazon Cognito service and an end user's devices, invoke the synchronize method. Each dataset can have a maximum size of 1 MB.

Which method is used to push data into Amazon Cognito Sync store?

If you're new to Amazon Cognito Sync, use AWS AppSync . Like Amazon Cognito Sync, AWS AppSync is a service for synchronizing application data across devices. It enables user data like app preferences or game state to be synchronized.

What is AWS Cognito sync?

Amazon Cognito Sync is an AWS service and client library that makes it possible to sync application-related user data across devices. Amazon Cognito Sync can synchronize user profile data across mobile devices and the web without using your own backend.


2 Answers

You can have only the basic required attributes for authentication in the cognito user pool such as username, name, email and phone number and the rest of the meta data in some other database such as RDS or DynamoDB.
Within dynamo or RDS you can create a one to one mapping of the username in cognito and the rest of the metadata. Like for example:

*username* -> pk
employee_id
address
user_type
first_name
last_name
marital_status
gender

From implementation point of view:
Expose lambda to create and update a user. Create a user in cognito using only the required attributes earlier defined using the cognito APIs, next insert the meta data for that user in the database of your choice. Same goes for your PUT API with a slight change that you will have to update user pool and user meta data in the database.

like image 187
Gautam Jain Avatar answered Sep 22 '22 01:09

Gautam Jain


Short answer:

You can replicate Cognito User Pool data to a SQL table by listening to Cognito events (using AWS Lambda, for example).

Long answer:

I think you can have Cognito User Pools as authentication/user data Bounded Context, in other words a single source of truth for authentication and user data.

And other BC's in need of user data (for example Sales context) can use some kind of data replication architecture to sync user data as read only, for internal complex queries, or just decoupling from Cognito.

One example of data replication in this case could be listening to Cognito events (AWS Lambda can help with that) to replicate user data to a Bounded Context (just the part of the data you need for that context).

But remember that the replicated data is read only, the original Cognito data should be the single source of truth.

like image 30
Josmar Avatar answered Sep 19 '22 01:09

Josmar