This segment will help you serve an node/express application via AWS Lambda and React frontend using vercel. This tutorial will assume that you have a code editor, npm
, and git
on your computer. Additionally, we assume you have an AWS account set up.
There are a lot of files in this repository which might make it confusing on what each does.
- my-app: this folder contains the frontend React application
- .gitignore: file that restricts some files from being pushed to git, we might want to do this to prevent sensitive information (API Keys) from being public
- package.json: contains all the libraries and scripts that we are going to use
- index.js: our backend application
- Make sure you have an AWS account and an IAM role with the following permissions:
- AmazonAPIGatewayAdministrator
- AmazonS3FullAccess
- AWSCloudFormationFullAccess
- AWSLambda_FullAccess
- CloudWatchLogsFullAccess
- IAMFullAccess
- Go to the
security credentials
tab and create an access key. - Install the serverless framework
npm install -g serverless
- Configure serverless:
$ sls config credentials \ --provider aws \ --key PUBLIC_KEY \ --secret SECRET_KEY
- Install node dependencies with
npm install
- Confirm installation with offline run
sls offline start --httpPort 5000
- Deploy with
sls deploy
The code has already been written so lets verify that everything is working as expected.
- Go to the react directory
my-app
- Run
npm run start
to start the application -> your app should be running onlocalhost:3000
- If everything went well, then you should be seeing the default React app with "Testing, sending hello" on the screen.
We are going to deploy the frontend app on vercel, a common hosting platform for frontend (and now backend) applications. Also make sure that you have the repository forked.
- Make sure you have a vercel account by visiting this website.
- Add a new project and add your forked repository.
- Choose to deploy under
my-app
folder and choosecreate-react-app
. - Click Deploy