aws-lambda-helper
Collection of helper methods for lambda
Installation
$ npm install aws-lambda-helper --save
Usage
var AwsHelper = ; exports { ... //Initialise the helper by passing in the context AwsHelper; ... }
Invoke a Lamda function
var AwsHelper = ; exports{ // assume : context.invokedFunctionArn = invokedFunctionArn: 'arn:aws:lambda:eu-west-1:123456789:function:mylambda:prod' //Initialise the helper by passing in the context AwsHelper; console; //prints: prod console; //prints: eu-west-1 console; //prints: 123456789 var params = FunctionName: 'MyAmazingLambda' Payload: 'hello': 'world' Qualifier: '' ; AwsHelperLambda; }
Logging JSON messages
var AwsHelper = ; exports{ // assume : context.invokedFunctionArn = invokedFunctionArn: 'arn:aws:lambda:eu-west-1:123456789:function:mylambda:prod' //Initialise the helper by passing in the context AwsHelper; var log = AwsHelper; log; // Returns a boolean: is the "info" level enabled? // This is equivalent to `log.isInfoEnabled()` or // `log.isEnabledFor(INFO)` in log4j. log; // Log a simple string message (or number). log; // Uses `util.format` for msg formatting. log; // The first field can optionally be a "fields" object, which // is merged into the log record. log; // Special case to log an `Error` instance to the record. // This adds an "err" field with exception details // (including the stack) and sets "msg" to the exception // message. log; // ... or you can specify the "msg". log; // To pass in an Error *and* other fields, use the `err` // field name for the Error instance.}
Pushing Data Back to Client(s) Via WebSocket Server
var params = id: sessionId // the id provided by the WebSocket Server AKA "connectionId" bucketId: 12345 // the id of this rticular search request userId: 'UniqueFingerprint' // the super long string that uniquely identifies a client items: // your list of one or more tiles or packages go here url: '/userId/connectionId/bucketId/itemId' // url for S3 object. // note: url should not have .json in it.;AwsHelper;
Retrieving a Search Result (Artile Tile or Package)
When a user shares a result tile (e.g. an article or package) we retrieve the result they saw from S3:
var params = url: '/userId/connectionId/bucketId/itemId' // supplied by front-end;AwsHelper;
Environment Variables
You will require an the following Environment Variables to push results to S3 and retrieve them later:
export WEBSOCKET_SERVER_URL=get_this_from_codeship
export AWS_S3_SEARCH_RESULT_BUCKET=get_this_from_codeship
export SEARCH_RESULT_TOPIC=arn:aws:sns:eu-west-1:123456789:my-awesome-topic
(see below for complete list of required Environment Variables)
if you get stuck get the Environment Variables from CodeShip: https://codeship.com/projects/143221/configure_environment