Skip to content

Commit ec61276

Browse files
committed
parse event JSON payload
1 parent 27c67d0 commit ec61276

3 files changed

Lines changed: 20 additions & 2 deletions

File tree

lambda-example.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ exports.shouldFail = function(event, context){
66
context.fail('buuuu');
77
}
88

9-
exports.throwError = function(){
9+
exports.throwError = function(event, context){
1010
throw new Error('random error');
1111
}
12+
13+
exports.parseEvent = function(event, context){
14+
context.succeed(event.someProperty);
15+
}

lambda-sandbox-run.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,12 @@ exports.run = function(lambdaName, handlerName, eventPayLoad){
2626
}
2727

2828
handlerName = handlerName || 'handler';
29-
eventPayLoad = eventPayLoad || {};
29+
30+
if( eventPayLoad ){
31+
eventPayLoad = JSON.parse(eventPayLoad);
32+
}else{
33+
eventPayLoad = {};
34+
}
3035

3136
try{
3237
lambdaFunction = require(process.cwd() + '/' + lambdaName + '.js');

tests/lambda-sandbox-run-spec.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ describe('AWS Lambda Function', function (){
1010
});
1111
});
1212

13+
describe('send event pay load', function () {
14+
it('should call succeed and parse JSON', function (){
15+
spyOn(lambdaRunner.aws, 'succeed').andCallThrough();
16+
var event = '{"someProperty":"works"}';
17+
lambdaRunner.run('lambda-example', 'parseEvent', event);
18+
expect(lambdaRunner.aws.succeed).toHaveBeenCalledWith('works');
19+
});
20+
});
21+
1322
describe('failed execution', function () {
1423
it('should call fail', function (){
1524
spyOn(lambdaRunner.aws, 'fail').andCallThrough();

0 commit comments

Comments
 (0)