Interview Prep/Python for DevOps/Automation scripting & CLI design

You inherit a script with hardcoded AWS keys, a hardcoded account ID and a hardcoded region. What is your clean-up plan?

BeginnerScenarioAutomation scripting & CLI design
Answer

Situation read → A credential leak (the keys are in Git history) and an inflexible design.

What I'd do →

  1. Treat the keys as compromised: deactivate and delete them in IAM now, check CloudTrail for misuse.
  2. Remove them from code; rely on the default credential chain (profile, SSO, instance role, OIDC in CI).
  3. Make region and account inputs: --region, --profile, or derive the account with sts.get_caller_identity().
  4. Purge history if the repo is shared (git filter-repo), and add gitleaks/push protection to prevent recurrence.

Why → Removing keys from the latest commit does not remove them from history or from anyone's clone.

Interview tip → Lead with "rotate first, then clean the code"; order matters.

All Python for DevOps questions Roadmap: Python for automation

More on Automation scripting & CLI design