Your script must process 50,000 S3 keys and must be resumable if it crashes midway. How do you design it?
AdvancedScenarioAutomation scripting & CLI design
Answer
Situation read → Long-running batch, partial failure is likely, reprocessing must be safe.
What I'd do →
- Make per-item work idempotent (re-copying or re-tagging the same object is harmless).
- Record progress durably: a checkpoint file written atomically every N items with the last processed key (S3 lists keys in lexicographic order, so
StartAfter=last_keyresumes the listing), or a DynamoDB/SQLite table of done keys. - Handle SIGTERM: finish the current item, write the checkpoint, exit.
- Collect failures in a separate file for retry instead of aborting the run.
- For bigger jobs, use S3 Batch Operations or fan out via SQS workers.
Why → Checkpoint plus idempotency means a crash costs minutes, not a full rerun.
Interview tip → Mention StartAfter; it shows you know how S3 listing works.
More on Automation scripting & CLI design
Your team has a 300-line Bash script that parses JSON with `jq`, loops over AWS accounts and retries with `sleep`. It breaks every month. Do you rewrite it in Python?BeginnerA colleague's script deletes files older than 30 days from `/var/log/app`. You are asked to review it before it goes into cron. What do you look for?IntermediateYou need a script that ops engineers run from laptops and that CI runs nightly. How do you design its interface?IntermediateA script reads a 15 GB access log to count 5xx errors per endpoint, and the box runs out of memory. How do you fix it?BeginnerYou must run the same Python automation on 40 servers that have Python 3.6, 3.9 and 3.12. What do you do?IntermediateA cron job that runs a Python script fails silently. Nobody noticed for two weeks. How do you make sure that never happens again?Intermediate