I am taking over an AWS lambda serverless nodejs app and I am trying to figure out how to execute an endpoint in my development environment. For my purposes I am trying to simulate a request like the following:
http://localhost:3000/find/product?hiveProductId=22002233&zipCode=44035
the app includes the following in 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);
There is also the following in 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"
I have been using https://www.serverless.com/framework/docs/providers/aws/cli-reference/invoke-local/ for a reference. serverless invoke local
seems like what I'm looking for. serverless invoke local --function find
gives the following response:
{
"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"
}
Any advice or pointers on how to use serverless invoke
correctly, or a different approach to look into, or any documentation that would be more fruitful, would be greatly appreciated.