Upload of images with ReactJS and AWS serverless
-
To speed up development I decided to use Cognito signin/signup instead of my own UI signin/signup.
-
Each time a user confirms his email code when signing up, the
setup-user
lambda function is executed to create a dynamoDB table for this specific user, where image information will be savedd. -
When the dashboard is shown the
ImagesList
component requests all the images of the user andget-user-images
lambda function is used to get all the images of this specific user. -
When the user uploads an image,
get-signed-s3-url
lambda function is used to get a signed s3 url to upload the image in S3 and aftersave-user-image
lambda function is used to save the metadata in dynamoDB
- node
- Your port 3000 needs to be free
- Clone the repository
- Use the file
/api/cloudFormationTemplate.yml
to deploy the resources in AWS, you need to fill only 2 fields:- Stack Name: any name
- AllowedCallbacks: http://localhost:3000
- Once the resources are deployed in AWS, replace the respective variables in
/client/src/env.tsx
- CLIENT_ID -> (Cognito -> users-pool -> App clients -> App client id)
- API_ADDRESS -> (API Gateway -> APIs -> api-prod -> Stages -> prod -> Invoke URL)
- Run in
/client
the commandnpm install
and afternpm start
- Finally go to Cognito -> users-pool -> App integration -> App client settings -> Hosted UI -> Click on Launch Hosted UI