A script that runs `describe_instances` with 2,000 instance IDs fails with a filter limit error. How do you fix it?
IntermediateScenarioAWS automation with boto3
Answer
Situation read → EC2 limits the number of values in a filter or ID list per request.
What I'd do →
- Chunk the IDs into batches (for example 200) and call per batch, or use a paginator with no ID list and filter in Python.
- Write a generic
chunked()helper and reuse it for other batch-limited APIs (tag_resourcesmax 20 ARNs,delete_objectsmax 1,000 keys).
for batch in chunked(ids, 200):
for page in ec2.get_paginator("describe_instances").paginate(InstanceIds=batch): ...
Why → Every batch API has a documented limit; chunking is the standard pattern.
Interview tip → Quote a couple of real limits; it shows hands-on experience.
More on AWS automation with boto3
You are asked to write a script that stops all dev EC2 instances at 8 PM and starts them at 8 AM. How do you build it?BeginnerA script that lists all S3 objects in a bucket reports 1,000 objects, but the console says there are 48,000. What happened, and how do you fix the script?BeginnerYou need to find and delete EBS snapshots older than 90 days, but some are used by AMIs and backup plans. How do you write it safely?IntermediateYour audit script hits `ThrottlingException` / `RequestLimitExceeded` when scanning large accounts. What do you change?AdvancedYou must audit 40 AWS accounts in an Organization from one script. How do you handle credentials?AdvancedA Lambda written in Python times out at 15 minutes while processing a big S3 prefix. What are your options?Advanced