简体   繁体   English

在 AWS Amplify 上为 Express 和 React 设置代理

[英]Setting up proxy for Express & React on AWS Amplify

Im using AWS Amplify for one of my project.我在我的一个项目中使用 AWS Amplify。 I have React in the front and Express as backend.我在前端有 React,后端有 Express。 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?在我的本地主机中,我可以将代理添加到我的 package.json 并调用 api 但我如何在 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?如何同时运行 express 和 React 并在放大中调用 api 还是我需要使用 EC2? thanks谢谢

if you want to use a "regular REST api" (ie non-graphql, no appsync) you'd most likely configure an API Gateway with a Lambda function integration. if you want to use a "regular REST api" (ie 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.对于 lambda,您可以配置“无服务器 ExpressJS 功能”并将您的快速代码放在 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)本地 lambda 调用也可以用于本地开发(通常通过 lambda docker 映像)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM