I am trying to deploy a serverless REST API with NodeJS, AWS Lambda, API Gateway, RDS and PostgreSQL.
So far I've set up the PostgreSQL RDS successfully and before start writing the functions to handle the requests to the DB I thought it'd be a good idea to test a small function first locally to check if the requests are being handled correctly.
So in the root of the project, I installed serverless-offline:
npm install serverless-offline
It threw several warnings during installation of the type:
npm WARN deprecated @hapi/[email protected]: This version has been deprecated and is no longer supported or maintained
(I'm sorry if that information is irrelevant, I'm quite new and don't know what is important and what is not.)
Then I configured my 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
And here's the 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 };
};
And the problem arose upon running
serverless offline
As it threw the error:
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
So I changed the path in serverless.yml to "path: /hello" and the error changed to:
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.
And if I change the path to "path: '*'" it throws that same last error.
I ran it again after setting the "SLS_DEBUG=*" environment variable as suggested but the result is pretty much the same, no extra debugging information.
Can anyone tell me what I am doing wrong? I have spent hours surfing the internet looking for a workaround but I didn't find any post solving this same error and the issues solved at forum.serverless.com give entangled information difficult to follow.
Can anyone help me?
If you upgrade to version 2.41.2 of serverless or greater this issue is resolved.
npm i -g [email protected]