简体   繁体   English

如何在本地使用 AWS 无服务器后端

[英]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 在本地运行无服务器。

  1. npm i serverless-offline npm i 无服务器离线

  2. add serverless-offline in plugins of your serverless.yml file在 serverless.yml 文件的插件中添加 serverless-offline

    plugins:插件:

     - serverless-offline
  3. 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.

相关问题 使用 AWS 保护无服务器后端 Lambda - Secure a serverless backend with AWS Lambda 如何在本地运行/调试无服务器(框架)应用程序? - How to run/debug serverless(framework) application locally? 我如何像无服务器框架一样使用 AWS SAM 模板文件分离? - How can i use AWS SAM Template File separation like Serverless Framework use? 如何在 AWS 无服务器 Function 上设置 Oauth 范围? - How to setup Oauth scopes at AWS Serverless Function? 如何在 aws serverless 上安排按需任务 - How to schedule on-demand tasks on aws serverless 如何在 aws sagemaker 中创建无服务器端点? - How to create a serverless endpoint in aws sagemaker? 如何在 aws sagemaker 中调用无服务器端点? - How to invoke a serverless endpoint in aws sagemaker? “errorMessage”:在 AWS 无服务器上部署时“server.app.use 不是一个函数” - "errorMessage": "server.app.use is not a function" while deploying on AWS serverless 使用 NodeJS 在 AWS Aurora Serverless V2 上使用什么进行连接? - What to use to connect on AWS Aurora Serverless V2 using NodeJS? 如何在dbt中使用CETAS(Synapse Serverless Pool)? - How to use CETAS (Synapse Serverless Pool) in dbt?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM