Amazon Bedrock Batch Inference with On-Demand SLA Fallback

Runs Amazon Bedrock batch inference as the primary cost-effective path, with automatic fallback to on-demand inference using a Distributed Map when the SLA deadline is at risk. Uses the callback (task token) pattern to suspend execution cheaply while waiting for the batch job, and the saga pattern to ensure a clean terminal state on any failure.

An Amazon S3 upload triggers a Registrar AWS Lambda function that starts the AWS Step Functions execution. The workflow submits an Amazon Bedrock batch inference job, records the job ARN in Amazon DynamoDB, then suspends using the callback (task token) pattern — consuming no compute while waiting.
The execution resumes through one of three triggers: the batch job completing (Amazon EventBridge), a stuck-job Amazon CloudWatch alarm (Amazon SNS → Lambda function), or an AWS Step Functions timeout. All three converge on the same fallback path: stop the batch job, reconcile which records were not yet processed, redrive them through a Distributed Map using on-demand Bedrock InvokeModel calls, and merge the results into a single output file.

< Back to all workflows

GitHub icon View this workflow on GitHub


Clone repo

git clone https://github.com/aws-samples/step-functions-workflows-collection/tree/main/bedrock-batch-with-sla/cd step-functions-workflows-collection/bedrock-batch-with-sla

Deploy

npm installcdk bootstrap aws://<ACCOUNT_ID>/<REGION>cdk deploy -c modelId=us.anthropic.claude-sonnet-4-6 -c slaTotalMinutes=360


Testing

See the GitHub repo for detailed testing instructions.

Cleanup

Delete the stack: cdk destroy.

Created by:

Subha Venugopal

Subha Venugopal

Subha is a Sr.Solution Architect at AWS. She is passionate about improving healthcare delivery and making it accessible to all.

Follow on LinkedIn