aws-core-utils
Advanced tools
Comparing version 5.0.13 to 5.0.14
@@ -119,3 +119,3 @@ 'use strict'; | ||
// Fail the Lambda callback | ||
failCallback(callback, err, awsContext, failureMsg, failureCode, allowedHttpStatusCodes); | ||
failCallback(callback, err, awsContext, undefined, undefined, allowedHttpStatusCodes); | ||
} | ||
@@ -122,0 +122,0 @@ } |
{ | ||
"name": "aws-core-utils", | ||
"version": "5.0.13", | ||
"version": "5.0.14", | ||
"description": "Core utilities for working with Amazon Web Services (AWS), including ARNs, regions, stages, Lambdas, AWS errors, stream events, Kinesis, DynamoDB.DocumentClients, etc.", | ||
@@ -5,0 +5,0 @@ "author": "Byron du Preez", |
@@ -1,2 +0,2 @@ | ||
# aws-core-utils v5.0.13 | ||
# aws-core-utils v5.0.14 | ||
@@ -52,4 +52,18 @@ Core utilities for working with Amazon Web Services (AWS), including ARNs, regions, stages, Lambdas, AWS errors, stream events, Kinesis, DynamoDB.DocumentClients, etc. | ||
const apiLambdas = require('aws-core-utils/api-lambdas'); | ||
const appErrors = require('core-functions/app-errors'); | ||
const BadRequest = appErrors.BadRequest; | ||
// Example Lambda handler function | ||
const standardOptions = require('my-options.json'); // or whatever options you want to use to configure stage handling, logging, custom settings, ... | ||
const standardSettings = undefined; // or whatever settings object you want to use to configure stage handling, logging, custom settings, ... | ||
function exampleFunction(event, context) { /* ... */ } // implement and name your own function that does the actual work | ||
// Simplest approach - generate your API Gateway exposed Lambda's handler function | ||
module.exports.handler = apiLambdas.generateHandlerFunction(standardSettings, standardOptions, exampleFunction); | ||
// OR ... using all optional arguments to change the allowed HTTP status codes and customise logging in the handler function | ||
module.exports.handler = apiLambdas.generateHandlerFunction(standardSettings, standardOptions, exampleFunction, 'info', | ||
[400, 404, 500], 'Invalid request ...', 'Failed to ...', 'Finished ...'); | ||
// OR ... develop your own Lambda handler function (e.g. simplistic example below - see apiLamdas.generateHandlerFunction for a better version) | ||
module.exports.handler = (event, awsContext, callback) => { | ||
@@ -59,8 +73,20 @@ // Configure a standard context | ||
try { | ||
const standardOptions = require('my-options.json'); // or whatever options you want to use to configure stage handling, logging, custom settings, ... | ||
const standardSettings = {}; // or whatever settings you want to use to configure stage handling, logging, custom settings, ... | ||
apiLambdas.configureStandardContext(context, standardSettings, standardOptions, event, awsContext); | ||
// ... execute Lambda specific code passing the context to your functions as needed | ||
// executeMyLambdaFunction(arg1, arg2, ..., context); | ||
exampleFunction(event, context) | ||
.then(response => { | ||
context.info('Finished ...'); | ||
callback(null, response); | ||
}) | ||
.catch(err => { | ||
// Fail your Lambda callback and map the error to one of the default set of HTTP status codes: | ||
// i.e. [400, 401, 403, 404, 408, 429, 500, 502, 503, 504] | ||
if (err instanceof BadRequest || appErrors.getHttpStatus(err) === 400) { | ||
context.warn('Invalid request ...' + err.message); | ||
} else { | ||
context.error('Failed to ...', err.stack); | ||
} | ||
apiLambdas.failCallback(callback, err, awsContext); | ||
}); | ||
@@ -70,2 +96,3 @@ } catch (err) { | ||
// i.e. [400, 401, 403, 404, 408, 429, 500, 502, 503, 504] | ||
context.error('Failed to ...', err.stack); | ||
apiLambdas.failCallback(callback, err, awsContext); | ||
@@ -75,3 +102,3 @@ } | ||
// ALTERNATIVELY: | ||
// ALTERNATIVES for failCallback: | ||
// Fail your Lambda callback and map the error to one of a specified set of HTTP status codes | ||
@@ -368,2 +395,5 @@ apiLambdas.failCallback(callback, err, awsContext, 'My error msg', 'MyErrorCode', [400, 404, 418, 500, 508]); | ||
### 5.0.14 | ||
- Fixed defect in `generateHandlerFunction` function of `api-lambdas.js` module | ||
### 5.0.13 | ||
@@ -370,0 +400,0 @@ - Added new `generateHandlerFunction` function to `api-lambdas.js` module |
{ | ||
"name": "aws-core-utils-tests", | ||
"description": "Unit tests for aws-core-utils modules", | ||
"version": "5.0.13", | ||
"version": "5.0.14", | ||
"author": "Byron du Preez", | ||
@@ -6,0 +6,0 @@ "license": "Apache-2.0", |
363530
619