我有以下问题..。结果,我无法在无服务器的nodejs框架中的无服务器离线插件上测试我的aws lambda函数。无法执行简单的GET请求。
我能够使用serverless deploy命令部署到aws,但是为了更好地使用无服务器脱机部署团队的开发经验,我遵循了这个指南https://fauna.com/blog/develop-using-serverless-offline,但在成功运行serverless offline命令之后执行简单的get请求时却陷入了困境。这是在成功运行serverless offline时得到的。

但是,当我通过postman向链接http://localhost:3000/发出get请求时,我会得到以下错误

它基本上说找不到节点:url模块,但我做了npm安装url,但仍然抛出相同的错误。我将在下面插入项目树和文件:

handler.js
//"use strict";
console.log("AJAJAJAJAJAJAJAJAJAAJAJ");
console.log("Printing module");
console.log(module.exports);
module.exports.hello = async (event) => {
console.log("whaaaaat");
return {
statusCode: 200,
body: JSON.stringify(
{
message: "Go Serverless v3.0! Your function executed successfully!",
input: event,
},
null,
2
),
};
};serverless.yml
org: ortizjorge97
app: aws-node-http-api-project
service: aws-node-http-api-project
frameworkVersion: '3'
provider:
name: aws
runtime: nodejs14.x
plugins:
- serverless-offline
- serverless-bundle
- serverless-dotenv-plugin
functions:
hello:
handler: handler.hello
events:
- httpApi:
path: /
method: getpackage.json
{
"name": "aws-node-http-api-project",
"version": "1.0.0",
"description": "<!-- title: 'AWS Simple HTTP Endpoint example in NodeJS' description: 'This template demonstrates how to make a simple HTTP API with Node.js running on AWS Lambda and API Gateway using the Serverless Framework.' layout: Doc framework: v3 platform: AWS language: nodeJS authorLink: 'https://github.com/serverless' authorName: 'Serverless, inc.' authorAvatar: 'https://avatars1.githubusercontent.com/u/13742415?s=200&v=4' -->",
"main": "handler.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"serverless-bundle": "^5.5.0",
"serverless-dotenv-plugin": "^4.0.2",
"url": "^0.11.0"
},
"devDependencies": {
"serverless-offline": "^10.2.0"
}
}我是aws的新手,所以我不知道会发生什么。
我在用
发布于 2022-10-15 11:57:05
您需要将实际的无服务器包本身安装为一个dev依赖项。试试这个:
npm i -D serverless
注意到:记得检查无服务器离线的文档,以了解找到支持的无服务器包版本。
发布于 2022-11-22 07:43:29
https://stackoverflow.com/questions/73821950
复制相似问题