Setting up proxy for Express & React on AWS Amplify

Viewed 1392

Im using AWS Amplify for one of my project. I have React in the front and Express as backend. In my localhost I can just add a proxy to my package.json and make call for the api but how can I do so in the AWS? How can I run both express and React side by side and call the api in the amplify or do i need to use EC2? thanks

1 Answers

if you want to use a "regular REST api" (i.e. non-graphql, no appsync) you'd most likely configure an API Gateway with a Lambda function integration.

For the lambda you can then configure "Serverless ExpressJS function" and have your express code in the lambda.

Here is an example:

$amplify add api
Scanning for plugins...
Plugin scan successful
? Please select from one of the below mentioned services: REST
? Provide a friendly name for your resource to be used as a label for this category in the project: myapi
? Provide a path (e.g., /book/{isbn}): /items
? Choose a Lambda source Create a new Lambda function
? Provide a friendly name for your resource to be used as a label for this category in the project: mylambda
? Provide the AWS Lambda function name: mylambda
? Choose the function runtime that you want to use: NodeJS
? Choose the function template that you want to use:
  CRUD function for DynamoDB (Integration with API Gateway)
  Hello World
  Lambda trigger
❯ Serverless ExpressJS function (Integration with API Gateway)

Local lambda invocation for local development is also possible (usually via a lambda docker image)

Related