Andrew
Andrew

Reputation: 85

How to get user data in AWS?

I'm trying to make a simple (React) website where a user signs in and it gets their data from a MySQL database and displays it in a table on the website. The flow is like this:

Home Page -> Sign In -> App

I want to show the user's data that is stored in a AWS RDS (MySQL) when they log into the App.

I have the domain and static hosting set up. I have a user pool set up in AWS Cognito. I set up an API Gateway with authorization and connected a basic lambda function to it. When the user signs in the are redirected to the App page with a JWT token in the header. I don't know where to go from here.

This is what I'm thinking:

I don't know how to do any of the above though (apart from SQL queries). Are these even the correct steps?

How do I get the JWT token in my code? From what I know it has to be passed with every API call? I have my invoke URL from API Gateway, how do I send a request with the JWT token?

What would the database instance look like? Would it be a collection of tables that each represent a user?

How do I do this with and without AWS Amplify?

I've been trying for a few weeks but there's so much info and I feel like I'm over complicating something that is very simple to implement.

Upvotes: 1

Views: 240

Answers (1)

smac2020
smac2020

Reputation: 10734

Another approach is to use the AWS SDK for JavaScript to query data on the backend and a React front end that displays the data.

This use case is located in the AWS Code Lib here:

Create an Aurora Serverless work item tracker

This example shows how to use the AWS SDK for JavaScript (v3) to create a web application that tracks work items in an Amazon Aurora database and emails reports by using Amazon Simple Email Service (Amazon SES). This example uses a front end built with React.js to interact with an Express Node.js backend. Services used in this example

AWS Services used in this example:

  • Aurora
  • Amazon RDS
  • Amazon RDS Data Service
  • Amazon SES

Note that this example focuses on the AWS SDK, such as the RDSDataClient) and not stuff like JWT tokens, Amplify etc

Upvotes: 1

Related Questions