Is there a dev server that runs AWS Lambdas locally? My requirements would be
nodejs server, no ruby or go or anything need to install other than node and npm packageswget / curl or an API testing tool to send various events tojs file that the server uses as lambda and the server should restart / update when I change that fileHere's a solution that does not require serverless or claudiajs.
I usually just write my own little express script for this purpose. I always just use Lambda Proxy integration so it's simpler.
Something like this...
const bodyParser = require('body-parser')
const express = require('express')
// Two different Lambda handlers
const { api } = require('../src/api')
const { login } = ('../src/login')
const app = express()
app.use(bodyParser.json())
// route and their handlers
app.post('/login', lambdaProxyWrapper(login))
app.all('/*', lambdaProxyWrapper(api))
app.listen(8200, () => console.info('Server running on port 8200...'))
function lambdaProxyWrapper(handler) {
return (req, res) => {
// Here we convert the request into a Lambda event
const event = {
httpMethod: req.method,
queryStringParameters: req.query,
pathParameters: {
proxy: req.params[0],
},
body: JSON.stringify(req.body),
}
return handler(event, null, (err, response) => {
res.status(response.statusCode)
res.set(response.headers)
return res.json(JSON.parse(response.body))
})
}
}
Then, run it with nodemon so it watches the files and reloads as necessary.
nodemon --watch '{src,scripts}/**/*.js' scripts/server.js
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With