Giter Site home page Giter Site logo

baselrabia-trufla / scaling-based-on-aws-sqs Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nirf/scaling-based-on-aws-sqs

0.0 0.0 0.0 1.15 MB

Deep dive on how to scale instances based on AWS SQS

JavaScript 46.13% HCL 50.61% Dockerfile 3.26%

scaling-based-on-aws-sqs's Introduction

scaling-based-on-aws-sqs

Deep dive on how to scale instances based on AWS SQS

Video Tutorial

Scaling based on Amazon SQS Tutorial

Architecture

Architecture

backlog-per-instance-calculator

Serverless framework project for building applications on AWS Lambda

calculateBacklogPerInstance Lambda

Lambda function that is triggered every minute, calculates backlog per instance and publish a custom metric

backlog per instance = SQS.ApproximateNumberOfMessages / runningInstances

logAutoScalingGroupEvents Lambda

Lambda function that is triggered by selected events of aws.autoscaling (debugging lambda)

  • 'EC2 Instance Launch Successful'
  • 'EC2 Instance Launch Unsuccessful'
  • 'EC2 Instance Terminate Successful'
  • 'EC2 Instance Terminate Unsuccessful'

sqs-worker

A naive implementation of a dockerized nodejs sqs-worker
Each message handling takes 1 min to complete
Whenever a new EC2 instance is launched, it pulls and run this container sqs-worker container

Accepts the following environment variables:

AWS_PROFILE=<profile>
or
AWS_ACCESS_KEY_ID=<access-key>
AWS_SECRET_ACCESS_KEY=<secret-key>

AWS_REGION=<region>
QUEUE_URL=<sqs-queue-url>
LOCALSTACK_ENABLED=<boolean> - you should have localstack installed

infra

Terraform - Infrastructure as code

Running instructions

Terraform and serverless framework must be installed!
Running order is important!

infra

Creating ssh keys

scaling-based-on-aws-sqs/infra> ssh-keygen -t rsa
Enter file in which to save the key: <full-path>/scaling-based-on-aws-sqs/infra/mykey

Running terraform

scaling-based-on-aws-sqs/infra> terraform init
scaling-based-on-aws-sqs/infra> terraform apply

Serverless

scaling-based-on-aws-sqs/backlog-per-instance-calculator> npm i -g serverless
scaling-based-on-aws-sqs/backlog-per-instance-calculator> npm i
scaling-based-on-aws-sqs/backlog-per-instance-calculator> serverless deploy

Publish messages to the SQS Q

Copy the created queue-url and region (from terraform output or from AWS console) and paste it in publishMessages.js
The script publishes batchSize messages to the queue, in each round, and sleeps sleepInMs between each iteration

scaling-based-on-aws-sqs/backlog-per-instance-calculator> npm run publish

Useful commands for debugging

Lets you watch the logs of a specific function.

scaling-based-on-aws-sqs/backlog-per-instance-calculator> serverless logs -f logAutoScalingGroupEvents -t
scaling-based-on-aws-sqs/backlog-per-instance-calculator> serverless logs -f calculateBacklogPerInstance -t

Cleanup

Cleanup order is important!

Serverless

scaling-based-on-aws-sqs/backlog-per-instance-calculator> serverless remove

infra

scaling-based-on-aws-sqs/infra> terraform destroy

Links

This project is inspired by Scaling based on Amazon SQS
Lambda functions are deployed using Serverless Framework
Infrastructure as code Terraform
Node.js middleware engine for AWS Lambda middy

scaling-based-on-aws-sqs's People

Contributors

dependabot[bot] avatar nirf avatar

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.