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

`KeyError: 'Tags'` while processing `describe_instances` output.

BeginnerTroubleshootingRuntime, file, subprocess & encoding errors
Answer

Likely causes → AWS omits the Tags key entirely for untagged resources rather than returning an empty list.

Diagnose →

print(json.dumps(inst, default=str, indent=2))   # look for missing keys

Fix → tags = {t["Key"]: t["Value"] for t in inst.get("Tags", [])}. Same for PublicIpAddress, IamInstanceProfile, Platform.

Prevent → Use .get() for optional fields; type responses with boto3-stubs, which marks them as NotRequired.

All Python for DevOps questions Roadmap: Python for automation

More on Runtime, file, subprocess & encoding errors