Recipe: Worker Environments with Amazon SQS¶
Prerequisites¶
- Elastic Beanstalk application with permission to create worker tier environment.
- Amazon SQS queue available for asynchronous job delivery.
- Node.js code structure that separates web requests from background processing.
- Optional
cron.yamlrequirements for scheduled worker jobs.
What You'll Build¶
You will create a worker tier environment that receives messages from Amazon SQS, processes jobs in Node.js, and supports scheduled processing through cron.yaml where needed.
flowchart LR
A[Producer App or API] --> B[Amazon SQS Queue]
B --> C[Elastic Beanstalk Worker Environment]
C --> D[Node.js Worker Process]
E[cron.yaml schedule] --> C Steps¶
-
Create or identify an Amazon SQS queue for work items.
-
Create an Elastic Beanstalk worker environment tied to the queue.
-
Implement worker message handling in Node.js application code.
-
Add
cron.yamlfor scheduled tasks when periodic processing is required. -
Deploy worker application and submit test SQS messages.
-
Monitor processing success and failures using logs and environment health.
-
Tune queue and worker behavior for throughput goals.
- Visibility timeout aligned with processing duration.
- Retry strategy for transient failures.
- Dead-letter queue routing for poison messages.
-
Keep worker code idempotent for safe retries.
- Deduplicate by job key when applicable.
- Avoid non-transactional side effects before commit points.
- Record processing outcome for auditability.
-
Define operational runbook entries for worker incidents.
- Backlog growth response.
- Failed job triage process.
- Temporary traffic throttling actions.
-
Validate scheduled workloads from
cron.yamlseparately from queue-driven jobs.
Verification¶
- Worker environment receives and processes queue messages.
- Failed message handling paths are visible in logs and retriable as designed.
- Scheduled tasks trigger according to
cron.yamldefinitions. - Web and worker responsibilities are separated across environment tiers.
- Queue timeout and retry parameters are documented for operations.