numo-labs / aws-lambda-helper

:lollipop: Collection of helper methods for lambda
GNU General Public License v3.0
22 stars 2 forks source link

You have to initialise AWSHelper everywhere you need to use it. #19

Closed jruts closed 8 years ago

jruts commented 8 years ago

The current implementation forces you to instantiate the AWSHelper like this:

var AwsHelper = require('aws-lambda-helper');
...
var awsHelper = AwsHelper(context);
awsHelper.Lambda.invoke(...);
...

You have to do this in every place you need the helper, or you can pass the awsHelper around.

Would it not be nicer to do this instead:

var AwsHelper = require('aws-lambda-helper');
...
AwsHelper.init(context);
AwsHelper.Lambda.invoke(...);
...

From the moment of initialisation you can now require AwsHelper and everything will be available for you without reinitialising or without passing the awsHelper around.

This makes mocking in tests a lot easier too, because now it requires you to initialise the AwsHelper before you can access it's functions to mock.

It would be very handy if we could just do

simple.mock(AwsHelper.Lambda, 'invoke')...
nelsonic commented 8 years ago

@jruts agree that this will be fewer lines to type. and simplifies usage. :+1:

jruts commented 8 years ago

This was fixed in https://github.com/numo-labs/aws-lambda-helper/pull/20/commits