You can never understand everything but you should push yourself to understand the system.
-Ryan Dahl (creator of Node.JS)
This repository aims to explain the what, why and how of working with AWS Lambda and SQS, in a simplified manner.
- Why this Combination?
- Working With SQS.
- Working with Lambda.
- Adding Triggers.
- Optimization and other concerns.
- Useful Links
Lambda and SQS both are cheap. The first 1 million request for Lambda per month is free. $0.20 per 1 million requests thereafter.
Lambda also provides automatic scaling and provisioning.
SQS offers resiliency, Durability, Security, at least once delivery and Scalability.
The cost of Amazon SQS is calculated per request, plus data transfer charges for data transferred out of Amazon SQS (unless data is transferred to Amazon EC2 instances or to AWS Lambda functions within the same region).
1. Simple Queue
2. FIFO Queue
Keep in mind AWS Lambda can only work with Simple Queue. The queue by default uses short polling but in the case of Lambda long polling is used. What is short polling and long polling? The default short polling returns immediately, even if the message queue being polled is empty, long polling doesn’t return a response until a message arrives in the message queue, or the long poll times out. You can use the AWS Management Console or the AWS SDKs (in the programming language of your choice) to create and interact with SQS.
AWS Lambda is a compute service where you can upload your code and create a Lambda function. AWS Lambda takes care of provisioning and managing the servers that you use to run the code. You don't have to worry about operating systems, patching scaling etc.
You need to understand the following to start working with Lambda
- Attaching Roles (Execution Role)
- Versioning
- Concurrency
- Function Timeout
- Handler Name
- Deploying Packages or Editing Inline
Triggers can be added once your Lambda Function is ready. Choose the function and under Add triggers, choose SQS. Configure the SQS queue and Batch Size. Lambda reads messages in batches and invokes your function once for each batch.
Batch Size specifies the maximum number of items to read from the queue and send to your function, in a single invocation. However, if your function returns an error, all items in the batch return to the queue so choose a smaller batch size.
Handling Concurrency.
Handling Errors.
Dead Letter Queue.
https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html#events-sqs-eventsource
https://docs.aws.amazon.com/lambda/latest/dg/java-programming-model.html
https://read.acloud.guru/event-driven-architecture-with-sqs-and-aws-lambda-cf2ebd529ae3