我正在为我的一个项目使用AWS Amplify。我有反应在前面和快递作为后端。在我的本地主机中,我可以只向我的package.json添加一个代理并调用api,但是我如何在AWS中做到这一点呢?如何同时运行express和React并调用amplify中的api,或者我需要使用EC2吗?谢谢
发布于 2020-05-25 20:09:00
如果你想使用“常规REST api”(即非graphql,没有appsync),你很可能会配置一个带有Lambda函数集成的API Gateway。
对于lambda,您可以配置“无服务器ExpressJS函数”,并将您的快速代码放在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镜像)
https://stackoverflow.com/questions/61996486
复制相似问题