[RFC] Queues #12
Replies: 3 comments 6 replies
-
Alerting@BenEllerby mentioned the possibility of alerting via different methods, including Slack webhooks. That's very interesting, I'm curious to see if others have that running with SNS. I've found this AWS article but it mentions using a Lambda function for the trigger. If anyone knows of a simpler approach please share! |
Beta Was this translation helpful? Give feedback.
-
I don't know if it's outside the scope of this, but the amount of yml required to create a webhook endpoint for a queue is huge. In my current Bref.sh project about half of my serverless.yml file is just the setup for a webhook endpoint that dumps the body of the webhook into a queue. Conversely the queue handler is tiny. |
Beta Was this translation helpful? Give feedback.
-
Is it possible to subscribe to all dead letter queues and consume messages from them? |
Beta Was this translation helpful? Give feedback.
-
The goal of this discussion is to get feedback on the "Queues" component.
If you are new to Lift, a quick intro: it's a Serverless plugin that can be installed via npm and enabled in any serverless.yml file.
Here is what we are planning so far.
Use case
Some tasks are too long to be processed synchronously, for example in an API response.
Instead, they can be processed in the background via a job queue and worker.
Quick start
How it works
The "asynchronous processing" component deploys the following resources:
Permissions
Lift will automatically add IAM permissions to all Lambda functions in the stack:
sqs:SendMessage
to the SQS queueThat way, by default all functions can publish into SQS without having to set up IAM (in the spirit of "it works by default").
References
The component will introduce
${queues:xxx}
variables to easily reference queues inserverless.yml
, without using CloudFormation.For example:
In the example above,
${queues:report-generation.queueUrl}
will reference the created queue.Configuration reference
Worker
The Lambda "worker" function is configured inside the queue, instead of being defined in the
functions
section.The only required value is the
handler
: this should point to the code that handles SQS messages. The handler should be written to handle SQS events, for example in JavaScript:All settings allowed for functions can be used under the
worker
key. For example:Lift will automatically configure the function to be triggered by SQS. It is not necessary to define
events
on the function.Alarm
It is possible to configure email alerts in case jobs end up in the dead letter queue:
Retries
Default: 3 retries.
The
maxRetries
option configures how many times each job will be retried when failing.If the job still fails after reaching the max retry count, it will be moved to the dead letter queue for storage.
Retry delay
When Lambda fails processing a SQS job (i.e. the code throws an error), the job will be retried after a delay. That delay is also called "Visibility Timeout" in SQS.
By default, Lift configures the retry delay to be 6 times the worker functions timeout, per AWS' recommendation. Since Serverless deploy functions with a timeout of 6 seconds by default, that means that jobs will be retried every 36 seconds.
It is possible to change the function's timeout, the retry delay will be configured accordingly:
It is also possible to set the retry delay directly:
Lift will throw an error if the retry delay is lower than the function's timeout.
Batch size
When the SQS queue contains more than 1 job to process, it can invoke Lambda with a batch of multiple messages at once.
By default, Lambda will be invoked with up to 10 messages at a time. It is possible to change the batch size between 1 to 10 000.
Batch window
If the batch size is greater than 10, SQS will wait for some time to collect jobs (i.e. to build the batch).
If the batch size is less than 10, this setting has no effect.
By default, Lift sets a batch window of maximum 5 seconds. That means that during 5 seconds, messages are collected into a batch before invoking Lambda.
The window maximum duration can be lowered (for less latency) or increased (to get larger batches):
Beta Was this translation helpful? Give feedback.
All reactions