GitXplorerGitXplorer
a

lambda-sns-dlq-error-handling

public
31 stars
5 forks
0 issues

Commits

List of commits on branch master.
Verified
c537d1dfc242c08cbff21735e9d473be53f69d4d

added diagram

aadnanrahic committed 6 years ago
Unverified
924fd8f8c226becbf7c6cb4c06a1b224b151b748

(cleanup)

aadnanrahic committed 6 years ago
Unverified
9c84caee0dfa759ddcda8adceaa41ec1a754670f

updated deps

aadnanrahic committed 6 years ago
Unverified
5ba27f41c7e033457e839b7dc1785bb81709a605

tweak service name and todos

aadnanrahic committed 6 years ago
Unverified
238b8bc8360477231f11a4f55612400a21eb01e4

added todo notes

aadnanrahic committed 6 years ago
Unverified
a4c3516365a0e08efeccbb7d747c97a7d3c7c894

initial commit

aadnanrahic committed 6 years ago

README

The README file for this repository.

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