GithubHelp home page GithubHelp logo

ardeshir / lambda-sns-dlq-error-handling Goto Github PK

View Code? Open in Web Editor NEW

This project forked from adnanrahic/lambda-sns-dlq-error-handling

0.0 3.0 0.0 9 KB

Sample project for showing the ability to publish an SNS topic and trigger a function from the topic. Code is structured to create a timeout/crash so the dead letter queue SNS topic gets published, in turn triggering the error handler function.

JavaScript 100.00%

lambda-sns-dlq-error-handling's Introduction

Trigger AWS Lambda with SNS with DLQ error handling

Sample project for showing the ability to publish an SNS topic and trigger a function from the topic. Code is structured to create a timeout/crash so the dead letter queue SNS topic gets published, in turn triggering the error handler function.

Explanation

  • The init function is the only exposed function, which is hooked up to API Gateway. It takes a single number parameter which it validates, upon success it publishes an SNS topic and sends along the number value.
  • The SNS topic will trigger a second function called calculate. This function will perform the calculation and log out the result to the console. This mimics a heavy computational background task such as data processing, image manipulation or machine learning calculations.
  • If either of the two functions fail the dead letter queue SNS topic will receive a message and trigger the error function.

Every function will try to retry its execution upon failure a total of 3 times. Using the dead letter queue as a pool for your error logs is a smart use-case.

Causing a crash

Adding a crazy huge number will trigger a factorial calculation that'll crash because of a Maximum call stack size exceeded rangeError.

curl -H "Content-Type: application/json" \
  -d '{"number":10000000}' \
  https://<id>.execute-api.<region>.amazonaws.com/dev/init

This will trigger the error function where you can handle the error as you wish.


The service is only a basic proof of concept which shows the use case of SNS triggering lambda functions and dead letter queues. The actual code is trivial and not exciting at all, but it serves the sole purpose of explaining what the *@$# is going on. ๐Ÿ˜„


TODO

  • add SQS resources
  • create setup where DLQ uses SQS
  • create stream between init and calculate with SQS
  • add SSM params instead of secrets.json

lambda-sns-dlq-error-handling's People

Contributors

adnanrahic avatar

Watchers

sepahsalar avatar James Cloos avatar  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.