GithubHelp home page GithubHelp logo

sbstjn / sqs-worker-serverless Goto Github PK

View Code? Open in Web Editor NEW
179.0 4.0 38.0 1.5 MB

Example for SQS Worker in AWS Lambda using Serverless

Home Page: https://sbstjn.com/serverless-sqs-worker-with-aws-lambda.html

License: MIT License

JavaScript 94.93% Lua 5.07%
serverless sqs worker lambda aws dynamodb

sqs-worker-serverless's Introduction

SQS Worker with Serverless ⚡️

MIT License Read Tutorial

Experimental Serverless Amazon SQS Worker with AWS Lambda.

Update: Please see Serverless Analytics for a more realistic setup using Amazon Kinesis Streams to process your data and events. You can read more about the Kinesis and Lambda connection at Serverless Analytics with Amazon Kinesis and AWS Lambda. This was only intended as an April Fools' project …

Setup

  • SQS Queue with your messages
  • SNS Topic to handle CloudWatch Alarms
  • DynamoDB table to persist configuration
  • CloudWatch Schedule as cron replacement
  • Three (scale, worker, process) AWS Lambda functions

Workflow

  • CloudWatch Alarms on queue length post to SNS
  • SNS Topic triggers scale Lambda function
  • Function scale updates configuration in DynamoDB
  • CloudWatch Schedule invokes worker every x minute(s)
  • Function worker reads configuration from DynamoDB
  • Function worker invokes process function(s)

Auto-Scaling with CloudWatch Alerts

Workers with CloudWatch Schedule

Deploy

$ > yarn install
$ > yarn deploy

Add noise to SQS

You should have some data in your queue to test this setup. Use wrk to send messages to SQS, but make sure to enable anonymous access to sendMessage for your queue first!

$ > wrk -c35 -d60 -t35 \
    -s helpers/wrk.lua \
    https://sqs.REGION.amazonaws.com/ACCOUNT-ID/YourQueueName

sqs-worker-serverless's People

Contributors

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  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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

sqs-worker-serverless's Issues

Reduce worker costs when queue is empty

Hello,

actually the worker-function is also invoked when the queue is empty. I think it would be better to control the active field of the rate-rule depending on a cloudwatch alarm too.

Inital: Rate is deactivated
Zero Messages => Deactive AWS::Events:Rule
One or more Messages in the Queue => Activate AWS::Events:Rule

What do you think?

Scale up Cloudwatch Alarm Regex typo

Hey man, thanks for putting this together! I love how it works.

Just noticed when I tried to port this to my project that the scale up Cloudwatch alarm regex has a typo: https://github.com/sbstjn/sqs-worker-serverless/blob/master/functions/scale.js#L7

The Cloudwatch alarms that were set up for me had Message being singular instead of plural.

Maybe I misconfigured something but I believe we should update:

 const regex = /(OK|ALARM):(.*)MessagesAlarm([0-9]*)/g

to

 const regex = /(OK|ALARM):(.*)MessageAlarm([0-9]*)/g

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.