Interview Prep/Python for DevOps/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?

BeginnerScenarioAutomation scripting & CLI design
Answer

Situation read → The script has outgrown Bash: data structures, API calls, retries and error handling are all things Bash does badly.

What I'd do →

  1. Write down what it actually does today (inputs, outputs, side effects, exit codes) and capture a sample run's output as a reference.
  2. Rewrite in Python with boto3, a click CLI, logging and built-in retries (Config(retries={"mode": "adaptive"})), keeping the same flags and output so callers do not change.
  3. Add pytest tests with moto for the core logic and compare output against the reference run.
  4. Ship it side by side for one cycle, then switch callers over.

Why → A behaviour-preserving rewrite with tests removes the monthly breakage without surprising the people who depend on it.

Interview tip → Say you keep the external contract identical; rewrites fail when they change behaviour and tooling at the same time.

All Python for DevOps questions Roadmap: Python for automation

More on Automation scripting & CLI design