Interview Prep/Python for DevOps/Runtime, file, subprocess & encoding errors

A cron job fails with `KeyError: 'HOME'` or cannot find `~/.aws/config`.

IntermediateTroubleshootingRuntime, file, subprocess & encoding errors
Answer

Likely causes → Cron and systemd run with a minimal environment: no HOME in some setups, no profile scripts, different user, no AWS_PROFILE.

Diagnose →

* * * * * env > /tmp/cron-env.txt     # temporary crontab entry to inspect

Fix → Set needed variables explicitly in the crontab or systemd unit (Environment=HOME=/home/ops AWS_PROFILE=audit), or better use an instance role so no config file is needed.

Prevent → Use systemd units with explicit environment; avoid depending on login-shell state.

All Python for DevOps questions Roadmap: Python for automation

More on Runtime, file, subprocess & encoding errors