无服务器离线抛出“配置错误”或“无法读取未定义的属性‘选项’”

我正在尝试使用 NodeJS、AWS Lambda、API Gateway、RDS 和 PostgreSQL 部署无服务器 REST API。

到目前为止,我已经成功设置了 PostgreSQL RDS,在开始编写函数来处理对数据库的请求之前,我认为最好先在本地测试一个小函数以检查请求是否得到正确处理。

所以在项目的根目录下,我安装了 serverless-offline:

npm install serverless-offline

它在安装类型时发出了几个警告:

npm WARN 已弃用 @hapi/pez@4.1.2:此版本已弃用,不再支持或维护

(如果这些信息无关紧要,我很抱歉,我是新手,不知道什么是重要的,什么不重要。)

然后我配置了我的serverless.yml

service: serverless-node-postgres-rds-rest-api

app: serverless-app

frameworkVersion: '2'

provider:
  name: aws
  runtime: nodejs12.x
  lambdaHashingVersion: 20201221

plugins:
  - serverless-offline

configValidationMode: error

functions:
  hello:
    handler: handler.hello
    events:
      - httpApi:
          path: hello
          method: get

这是handler.js

'use strict';

module.exports.hello = async (event) => {
  return {
    statusCode: 200,
    body: JSON.stringify(
      {
        message: 'Go Serverless v1.0! Your function executed successfully!',
        input: event,
      },
      null,
      2
    ),
  };

  // Use this code if you don't use the http event with the LAMBDA-PROXY integration
  // return { message: 'Go Serverless v1.0! Your function executed successfully!', event };
};

运行时出现问题

无服务器离线

因为它抛出了错误:

Serverless: Running "serverless" installed locally (in service node_modules)
 
 Serverless Error ----------------------------------------
 
  Configuration error at 'functions.hello.events[0].httpApi.path': value 'hello' does not satisfy pattern /^(?:*|/S*)$/
 
  Get Support --------------------------------------------
     Docs:          docs.serverless.com
     Bugs:          github.com/serverless/serverless/issues
     Issues:        forum.serverless.com
 
  Your Environment Information ---------------------------
     Operating System:          darwin
     Node Version:              14.15.4
     Framework Version:         2.40.0 (local)
     Plugin Version:            4.5.3
     SDK Version:               4.2.2
     Components Version:        3.9.2

所以我将serverless.yml 中的路径改为“path:/hello”,错误改为:

Type Error ----------------------------------------------
 
  TypeError: Cannot read property 'options' of undefined
      at module.exports (/Users/randresverap/Development/Node/serverless-node-postgres-rds-rest-api/node_modules/serverless/lib/utils/telemetry/generatePayload.js:133:66)
      at async PluginManager.run (/Users/randresverap/Development/Node/serverless-node-postgres-rds-rest-api/node_modules/serverless/lib/classes/PluginManager.js:607:35)
      at async Serverless.run (/Users/randresverap/Development/Node/serverless-node-postgres-rds-rest-api/node_modules/serverless/lib/Serverless.js:325:5)
      at async /usr/local/lib/node_modules/serverless/scripts/serverless.js:634:9
 
     For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.

如果我将路径更改为“路径:'*'”,它会抛出同样的最后一个错误。

我按照建议设置了“SLS_DEBUG=*”环境变量后再次运行它,但结果几乎相同,没有额外的调试信息。

谁能告诉我我做错了什么?我花了几个小时上网寻找解决方法,但我没有找到任何解决相同错误的帖子,并且在 forum.serverless.com 上解决的问题提供了难以理解的纠缠信息。

谁能帮我?

以上是无服务器离线抛出“配置错误”或“无法读取未定义的属性‘选项’”的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>