【问题标题】:Setting up proxy for Express & React on AWS Amplify在 AWS Amplify 上为 Express 和 React 设置代理
【发布时间】:2020-05-25 05:46:30
【问题描述】:

我在我的一个项目中使用 AWS Amplify。我在前端有 React,后端有 Express。在我的本地主机中,我可以将代理添加到我的 package.json 并调用 api,但我如何在 AWS 中这样做?我怎样才能同时运行 express 和 React 并在放大中调用 api 还是我需要使用 EC2? 谢谢

【问题讨论】:

  • AFAIK,使用 Amplify,不必使用 EC2Express。您的后端可以替换为AWS AppSync

标签: node.js reactjs amazon-web-services aws-amplify


【解决方案1】:

如果您想使用“常规 REST api”(即非 graphql,没有 appsync),您很可能会配置一个带有 Lambda 函数集成的 API 网关。

对于 lambda,您可以配置“无服务器 ExpressJS 函数”并将您的 express 代码放在 lambda 中。

这是一个例子:

$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)

本地开发的本地 lambda 调用也是可能的(通常通过 lambda docker 映像)

【讨论】:

  • 你能详细说明一下吗,我如何使用现有的 lambda?
猜你喜欢
  • 2021-12-12
  • 2020-09-20
  • 2022-11-09
  • 2021-01-30
  • 2020-08-30
  • 2022-07-29
  • 1970-01-01
  • 1970-01-01
  • 2021-07-16
相关资源
最近更新 更多