How to Handle Rate Limits on an API with AWS Lambda?

December 24, 2025 4 answers
Asked by !chalkboard agenda
I'm dealing with a situation where we have an ad-hoc burst operation that runs once or twice a month, sending thousands of messages to a queue processed by a Lambda function that communicates with a third-party API. We've encountered issues with API rate limiting, where we consume our limit within minutes. This means our current method of retrying failed messages isn't working, as we sometimes need to wait up to an hour before retrying. I've experimented with adjusting concurrency limits and visibility time-outs, but I'm looking for a more controlled solution. Would using Step Functions be a good approach? I've never used them before and need some guidance.

Answers

!close the ledger
Step Functions could be a perfect match for your needs! They handle wait states directly and can implement stateful retries, which is ideal for dealing with rate limits. Plus, they have a cost-effective pricing model at $0.025 for a thousand transitions.
Reply to this answer
paper lantern frame~
Consider using a Fargate service that manages queue processing. This allows you to scale based on the number of messages and gives you centralized control over rate limits compared to the Lambda functions. You might need to modify your code to support threading or parallel processing.
Reply to this answer
.starter.culture
There's actually a helpful blog that goes over strategies for optimizing message delivery to third-party services with AWS Lambda and Step Functions. It could give you some valuable insights!
Reply to this answer
CLOTHESPIN
One approach you can try is to keep the message in the queue instead of sending it to the dead letter queue (DLQ). You can do this by using partial batch responses. Set the visibility timeout for the message to one hour. This way, it will stay on the queue and will retry after that hour, giving you a controlled retry strategy.
Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions