Amazon SQS overflow from AWS Lambda Managed Instances to Standard AWS Lambda

Client → Amazon SQS Queue → AWS Lambda Managed Instances → AWS Lambda Burst tier → Amazon DynamoDB Idempotency

Run a steady SQS workload on Lambda Managed Instances and open a Standard Lambda burst tier on the same queue when a temporary traffic burst outpaces it.

A single SQS queue is polled by two event source mappings: one always-on mapping to a worker running on Lambda Managed Instances (LMI), which provides a cost-optimized and reservable compute baseline, and one mapping to a Standard Lambda worker that is disabled at deploy time and therefore costs nothing at steady state.
LMI does not scale on queue depth; its managed scaler reacts to the CPU utilization and multi-concurrency saturation of its own execution environments. Keeping both tiers on one queue is what preserves that signal. A router that rate-limited LMI's input would cap its CPU, silence its scaler, and leave the burst tier carrying the load indefinitely.
A controller invoked once a minute polls the queue's live depth with GetQueueAttributes every 10 seconds, and toggles the burst mapping with UpdateEventSourceMapping. Two thresholds form a dead band: above the open threshold the burst tier opens immediately, and it closes only once depth is below the close threshold, flat or falling over a 30-second window, and a minimum dwell time has elapsed. Polling replaces the CloudWatch depth alarms this pattern originally used, because a load test measured 2m 15s of metric-publish and alarm-evaluation lag, more than half the total time to engage the burst tier, and irreducible on a metric SQS publishes once a minute. The controller is on the control plane and never touches a workload message.
Both tiers run the same handler and share a DynamoDB idempotency table that records a claim before processing and a completion after it, so a retryable failure is redelivered rather than mistaken for a duplicate. A CloudWatch dashboard charts work completed per tier, so you can see the burst tier absorb a spike and then hand the workload back as LMI scales up.

< Back to all patterns

GitHub icon Download this pattern (.zip)

GitHub icon View this pattern on GitHub


Clone repo

git clone https://github.com/aws-samples/serverless-patterns/cd serverless-patterns/sqs-lmi-standard-lambda-overflow/python/sam

Deploy

sam validate --lintsam buildsam deploy --guided


Testing

See the README for the two load-test scenarios. A handful of messages will not demonstrate this pattern: the backlog must reach the open threshold before the burst tier can engage, and LMI needs roughly 17 minutes to scale through a 10x burst.

Cleanup

Delete the stack: aws cloudformation delete-stack --stack-name STACK_NAME. Deleting the stack terminates the Lambda Managed Instances.

Created by:

Mitesh Purohit

Mitesh Purohit

Sr Solution Architect, AWS

Brian Krygsman

Brian Krygsman

Solutions Architect at AWS