gpt4 book ai didi

node.js - 对于 AWS lambda 无服务器 nodejs 应用程序,您如何在开发环境中执行请求?

转载 作者:行者123 更新时间:2023-12-03 12:18:18 26 4
gpt4 key购买 nike

我正在接管一个 AWS lambda 无服务器 nodejs 应用程序,我正在尝试弄清楚如何在我的开发环境中执行端点。出于我的目的,我正在尝试模拟如下请求:

http://localhost:3000/find/product?hiveProductId=22002233&zipCode=44035

应用程序在 handler.js 中包含以下内容

app.route("/find/product").get(cors(), async (req, res) => {
try {
console.log(
"finding product",
req.query
);

etc...
} catch (error) {
console.error("caught error finding product: ", error);
res.status(500).json(error);
}
});

module.exports.find = serverless(app);

serverless.yml中还有如下内容:

functions:
find:
handler: handler.find
events:
- http:
path: /find/product
method: GET
memorySize: 128
timeout: 30
private: false
cors: true
integration: lambda-proxy
request:
parameters:
querystrings:
hiveProductId: true
max: false
lat: false
lon: false
allowGeoIp: false
zipCode: false
methodReponses:
- statusCode: "200"
responseBody:
description: "array of stores with product"
responseModels:
"application/json": "Stores"
- statusCode: "404"
description: "not found"
- http:
path: /find/stores
method: GET
memorySize: 128
timeout: 30
integration: lambda-proxy
private: true
request:
parameters:
querystrings:
max: false
lat: true
lon: true
documentation:
summary: "Find the closest stores"
queryParams:
- name: "lat"
description: "latitude caller for geosearch"
required: true
- name: "lon"
description: "longtitude caller for geosearch"
required: true
- name: "max"
description: "maximum stores to location to return. default is 5"
methodReponses:
- statusCode: "200"
responseBody:
description: "array of stores sorted by distance"
responseModels:
"application/json": "Stores"

我一直在使用https://www.serverless.com/framework/docs/providers/aws/cli-reference/invoke-local/供引用。 serverless invoke local 似乎是我正在寻找的。 serverless invoke local --function find 给出以下响应:

{
"statusCode": 404,
"headers": {
"x-powered-by": "Express",
"content-security-policy": "default-src 'none'",
"x-content-type-options": "nosniff",
"content-type": "text/html; charset=utf-8",
"content-length": "139"
},
"isBase64Encoded": false,
"body": "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n<meta charset=\"utf-8\">\n<title>Error</title>\n</head>\n<body>\n<pre>Cannot GET /</pre>\n</body>\n</html>\n"
}

任何有关如何正确使用 serverless invoke 的建议或指示,或不同的研究方法,或任何更有成效的文档,我们都将不胜感激。

最佳答案

这个方法我没用过,所以也不好说什么。我可以推荐无服务器离线作为不同的解决方案。 serverless-offline

关于node.js - 对于 AWS lambda 无服务器 nodejs 应用程序,您如何在开发环境中执行请求?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65298233/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com