
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
lambda-wrap
Advanced tools
Simple async function wrapper for AWS lambda and serverless library
co
(optional)
const { lambdaWrap } = require('lambda-wrap');
const wrap = lambdaWrap({
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Credentials': 'true',
},
callbackWaitsForEmptyEventLoop: false, // usefull for mongodb
verboseError: true // include error stack in response (possible to )
verboseLog: true // include headers and body in error log
});
wrap.before((event) => {
if (event.body && `${event.headers['content-type']}`.match(/^application\/json/)) {
event.body = JSON.parse(event.body);
}
});
// or you can set custom logger
wrap.logger = console;
wrap.finally((error, response) => {
// close connections or send logs
});
module.exports.myHandler = wrap(async (event) => {
// return json body
return {
body: {
objectAttribute: true
}
};
})
Return new error object.
lambdaWrap
function. You can pass options to override or assign new
attributes to event
object. For example add custom headers:
const headers = {
'X-Auth-Token': 'my-token'
};
const wrap = lambdaWrap({ headers });
It returns an instance of LambdaWrap
- wrap
object. This object can
be used for specifying additional properties:
wrap.responseHandler = customResponseFunction;
Finally, wrap
object can be used as a function to wrap any generator
function and thus create lambda handler:
const handler = wrap(async (event) => {
return {
body: 'Hello world'
};
});
Returns: function
- - the wrap function
Param | Type | Description |
---|---|---|
[globalOptions] | LambdaWrapOptions | Use to override or assign new attributes |
Return new error object.
Kind: global function
Param | Type | Description |
---|---|---|
message | string | Error message. |
code | integer | Error code. |
FAQs
AWS Serverless wrapper for async generators
The npm package lambda-wrap receives a total of 52 weekly downloads. As such, lambda-wrap popularity was classified as not popular.
We found that lambda-wrap demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.