[英]How to use AWS serverless backend locally
I joined a project which was half developed and I am trying to understand how to run the backend APIs locally.我加入了一个开发了一半的项目,我试图了解如何在本地运行后端 API。
So when a client hit a request it will go to AWS API Gateway goes to Lambda which then the lambda function which will get a response from the handler and send it back to the client.
因此,当客户端发出请求时,它将 go 到 AWS API 网关转到 Lambda,然后 lambda function 将从处理程序获得响应并将其发送回客户端。
I am still learning about this and not sure if it is written or not but I guess this is how the backend is working.我仍在了解这一点,不确定它是否已编写,但我想这就是后端的工作方式。 But here comes the problem there is no script to run the backend locally for development there is only one deploy script in the package.json which is
但是问题来了,没有脚本可以在本地运行后端进行开发,package.json 中只有一个部署脚本,它是
#!/bin/bash
rm -rf node_modules/
yarn install --frozen-lockfile
SLS_DEBUG=* sls deploy -v
which is a bash script so is there any way to test this backend locally before actually deploying it every time i make changes.这是一个 bash 脚本,所以在每次我进行更改时实际部署它之前,有什么方法可以在本地测试这个后端。
You should use serverless-offline to run serverless locally.您应该使用 serverless-offline 在本地运行无服务器。
npm i serverless-offline npm i 无服务器离线
add serverless-offline in plugins of your serverless.yml file在 serverless.yml 文件的插件中添加 serverless-offline
plugins:插件:
- serverless-offline
then you can run it locally as serverless offline start
然后你可以在本地运行它作为
serverless offline start
You could use Invoke Local to run the function locally before doing the sls deploy
在执行
sls deploy
之前,您可以使用Invoke Local在本地运行 function
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.