Middy AutoProxyResponse Middleware
Copyright (C) Clouden 2018
Author Kenneth Falck kennu@clouden.net 2018
Overview
This Middy middleware lets you return simple JavaScript objects from Lambda function handlers and converts them into LAMBDA_PROXY responses.
When you return a response like this:
{
hello: 'world'
}
The AutoProxyRespose middleware converts it to this:
{
statusCode: 200,
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
hello: 'world'
})
}
If your response contains a statusCode attribute, it is not converted, allowing you to return a full LAMBDA_PROXY response manually.
Installation
To add the middleware to your project:
npm install --save middy-autoproxyresponse
To use the middleware in a Lambda function:
import { autoProxyResponse } from 'middy-autoproxyresponse'
async function handler(_event: any, _context: any) {
return {
hello: 'world'
}
}
export default middy(handler)
.use(autoProxyResponse())