Build Worker Environments with SQS¶
This tutorial introduces Elastic Beanstalk worker environments for asynchronous processing. It follows AWS guidance for queue-driven processing and scheduled tasks with cron.yaml.
Prerequisites¶
- Existing Elastic Beanstalk application.
- SQS queue access and IAM permissions.
- Worker tier environment created or planned.
- Python Flask app that can accept worker POST payloads.
What You'll Build¶
You will build:
- A worker-tier Elastic Beanstalk environment.
- SQS-driven message handling endpoint in Flask.
- Scheduled task definition with
cron.yaml.
Steps¶
- Create or identify worker environment.
- Add Flask endpoint for worker message processing.
from flask import Flask, request
application = Flask(__name__)
@application.post("/")
def process_message():
payload = request.get_json(silent=True) or {}
# Process payload according to your application contract.
return {"received": bool(payload)}
- Add
cron.yamlfor scheduled worker tasks.
- Set environment variables needed by worker logic.
- Deploy to worker environment.
- Observe queue consumer behavior and event logs.
flowchart LR
A[Producer] --> B[SQS Queue]
B --> C[EB Worker Daemon]
C --> D[Flask POST Endpoint]
E[cron.yaml Schedule] --> C Verification¶
Validate worker workflow:
eb status "$WORKER_ENV_NAME"
aws sqs get-queue-attributes --queue-url "$QUEUE_URL" --attribute-names ApproximateNumberOfMessages --region "$REGION"
Expected outcomes:
- Worker environment reports healthy state.
- Queue messages are consumed and processed.
- Scheduled entries from
cron.yamltrigger at expected intervals.