aws-lambda-invoker
Advanced tools
Comparing version 1.0.1 to 2.0.0
26
index.js
@@ -19,3 +19,3 @@ 'use strict'; | ||
_invokeWithType(invocationType, functionName, payload, clientContext, cb) { | ||
_invokeWithType(invocationType, options, cb) { | ||
const logger = this.logger; | ||
@@ -25,3 +25,3 @@ cb = cb || function defaultCB(err, result) { | ||
if (err) { | ||
logger && logger.error({ err, functionName }, 'failed to invoke lambda'); | ||
logger && logger.error({ err, options }, 'failed to invoke lambda'); | ||
err._logged = true; | ||
@@ -36,10 +36,8 @@ reject(err); | ||
if (!functionName || !payload) { | ||
return cb(new Error('functionName and payload are required parameters.')); | ||
if (!options.functionName || !options.payload) { | ||
return cb(new Error('functionName and payload are required properties of the options parameter.')); | ||
} | ||
logger && logger.debug({ | ||
functionName, | ||
payload, | ||
clientContext, | ||
options, | ||
invocationType | ||
@@ -51,5 +49,5 @@ }, 'trying to invoke lambda'); | ||
InvocationType: invocationType, | ||
FunctionName: functionName, | ||
Payload: JSON.stringify(payload), | ||
ClientContext: this._formatClientContext(clientContext) | ||
FunctionName: options.functionName, | ||
Payload: JSON.stringify(options.payload), | ||
ClientContext: this._formatClientContext(options.clientContext) | ||
}) | ||
@@ -61,9 +59,9 @@ .promise() | ||
invoke(functionName, payload, clientContext, cb) { | ||
return this._invokeWithType('RequestResponse', functionName, payload, clientContext, cb); | ||
invoke(options, cb) { | ||
return this._invokeWithType('RequestResponse', options, cb); | ||
} | ||
invokeAsync(functionName, payload, clientContext, cb) { | ||
return this._invokeWithType('Event', functionName, payload, clientContext, cb); | ||
invokeAsync(options, cb) { | ||
return this._invokeWithType('Event', options, cb); | ||
} | ||
} |
{ | ||
"name": "aws-lambda-invoker", | ||
"version": "1.0.1", | ||
"version": "2.0.0", | ||
"description": "asynchronously invoke a lambda function", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -23,7 +23,8 @@ # lambda-invoker | ||
## invoke(functionName, payload, clientContext, cb) | ||
## invoke(options, cb) | ||
Method to synchronously invoke a lambda function. | ||
- **functionName** - { String, required } - the lambda function you wish to invoke. | ||
- **payload** - { Object, required } - the payload you wish to send to the lambda function. | ||
- **clientContext** - { Object, base64-encoded } - used to pass client-specific information to the lambda function being invoked via the context variable. | ||
- **options** - { Object, required } - invoke options for lambda | ||
- **functionName** - { String, required } - the lambda function you wish to invoke. | ||
- **payload** - { Object, required } - the payload you wish to send to the lambda function. | ||
- **clientContext** - { Object, base64-encoded } - used to pass client-specific information to the lambda function being invoked via the context variable. | ||
- **cb** - { function } - takes params err and result and is called on success or failure of invoking the lambda function. By default returns a promise that rejects on error or resolves with the result from invoking the lambda. | ||
@@ -38,4 +39,8 @@ | ||
module.exports.handler = function(event, context, cb) { | ||
const clientContext = { requestId: context.awsRequestId }; | ||
invoker.invoke('testFunctionName', { data: 'blah' }, clientContext, cb); | ||
const invokeOptions: { | ||
functionName: 'testFunctionName', | ||
payload: { data: 'blah' }, | ||
clientContext: { requestId: context.awsRequestId } | ||
}; | ||
invoker.invoke(invokeOptions, cb); | ||
}; | ||
@@ -46,5 +51,6 @@ ``` | ||
Method to asynchronously invoke a lambda function. | ||
- **functionName** - { String, required } - the lambda function you wish to invoke. | ||
- **payload** - { Object, required } - the payload you wish to send to the lambda function. | ||
- **clientContext** - { Object, base64-encoded } - used to pass client-specific information to the lambda function being invoked via the context variable. | ||
- **options** - { Object, required } - invoke options for lambda | ||
- **functionName** - { String, required } - the lambda function you wish to invoke. | ||
- **payload** - { Object, required } - the payload you wish to send to the lambda function. | ||
- **clientContext** - { Object, base64-encoded } - used to pass client-specific information to the lambda function being invoked via the context variable. | ||
- **cb** - { function } - takes params err and result and is called on success or failure of invoking the lambda function. By default returns a promise that rejects on error or resolves with the result from invoking the lambda. | ||
@@ -59,5 +65,9 @@ | ||
module.exports.handler = function(event, context, cb) { | ||
const clientContext = { requestId: context.awsRequestId }; | ||
invoker.invokeAsync('testFunctionName', { data: 'blah' }, clientContext, cb); | ||
const invokeOptions: { | ||
functionName: 'testFunctionName', | ||
payload: { data: 'blah' }, | ||
clientContext: { requestId: context.awsRequestId } | ||
}; | ||
invoker.invokeAsync(invokeOptions, cb); | ||
}; | ||
``` |
6695
70
53