Giter Site home page Giter Site logo

lawos's Introduction

lawos - Lambda Worker SQS

npm license CircleCI Coveralls

Library to process messages from an Amazon SQS queue with an AWS Lambda worker function or your favorite other JavaScript environment. Works fine with Serverless

Examples

Install

$ > npm install lawos

Usage

Promise for every message

const AWS = require('aws-sdk');
const SQS = new AWS.SQS({apiVersion: '2012-11-05'});

const Lawos = require('lawos');
const Q = new Lawos('https://sqs.eu-west-1.amazonaws.com …', SQS);

Q.item(
  item => new Promise(done => {
    done();
  })
);

module.exports.handler = function(event, context, callback) {
  Q.work(
    () => Promise.resolve(context.getRemainingTimeInMillis() < 500)
  ).then(
    data => {
      callback(null, data);
    }
  );
};

Promise for a batch of messages

const AWS = require('aws-sdk');
const SQS = new AWS.SQS({apiVersion: '2012-11-05'});

const Lawos = require('lawos');
const Q = new Lawos('https://sqs.eu-west-1.amazonaws.com …', SQS);

Q.list(
  list => new Promise(done => {
    done();
  })
);

module.exports.handler = function(event, context, callback) {
  Q.work(
    () => Promise.resolve(context.getRemainingTimeInMillis() < 500)
  ).then(
    data => {
      callback(null, data);
    }
  );
};

Use AWS Lambda instead of Promise

const AWS = require('aws-sdk');
const Lawos = require('lawos');

const Lambda = new AWS.Lambda({apiVersion: '2015-03-31'});
const SQS = new AWS.SQS({apiVersion: '2012-11-05'});

const Q = new Lawos('https://sqs.eu-west-1.amazonaws.com …', SQS, Lambda);

Q.item('fake-function-name');
// Q.list('fake-function-name');

module.exports.handler = function(event, context, callback) {
  Q.work(
    () => Promise.resolve(context.getRemainingTimeInMillis() < 500)
  ).then(
    data => {
      callback(null, data);
    }
  );
};

License

Feel free to use the code, it's released using the MIT license.

Contributors

lawos's People

Contributors

marcusstenbeck avatar sbstjn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

lawos's Issues

NPM package redundant files

When installed via npm the coverage and tests folders are included. Removing them from the bundle will result in 90% size reduction.

Should it quit if the 'item' callback rejects?

Given an item callback like:

Q.item(
  item => new Promise((resolve, reject) => {
    someOtherService((error, result) => {
      error ? reject(error) : resolve(result)
    })
  })
)

If someOtherService results in an error, and therefore the Promise rejects, should that cause the queue to quit and not delete that particular SQS message?

doc

any decent docs for this ? like what Q.item and Q.work do exactly, quite hard to read code if one is not a promises guru

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.