From e6f65c229b881ad1fdd65b072167c2d1733e6577 Mon Sep 17 00:00:00 2001 From: Drew Beaupre Date: Tue, 10 Nov 2015 08:38:10 -0800 Subject: [PATCH] Adding optional files to contain JSON objects for clientContext and identity to be passed into the lambda_invoke command. --- tasks/lambda_invoke.js | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/tasks/lambda_invoke.js b/tasks/lambda_invoke.js index 18ab6a3..a951c99 100644 --- a/tasks/lambda_invoke.js +++ b/tasks/lambda_invoke.js @@ -22,13 +22,36 @@ module.exports = function (grunt) { var options = this.options({ 'handler': 'handler', 'file_name': 'index.js', - 'event': 'event.json' + 'event': 'event.json', + 'client_context': 'client_context.json', + 'identity': 'identity.json' }); grunt.log.writeln(""); var done = this.async(); + var clientContext = null; + + //since clientContext should be optional, skip if doesn't exist + try{ + clientContext = JSON.parse(fs.readFileSync(path.resolve(options.client_context), "utf8")); + } catch (e) { + if (e.code !== 'ENOENT') { + throw e; + } + } + + var identity = null; + //since identity should be optional, skip if doesn't exist + try{ + identity = JSON.parse(fs.readFileSync(path.resolve(options.identity), "utf8")); + } catch (e) { + if (e.code !== 'ENOENT') { + throw e; + } + } + var context = { done: function (error, result) { if (error === null) { @@ -53,8 +76,8 @@ module.exports = function (grunt) { }, awsRequestId: 'LAMBDA_INVOKE', logStreamName: 'LAMBDA_INVOKE', - clientContext: null, - identity: null + clientContext: clientContext, + identity: identity }; var lambda = require(path.resolve(options.file_name));