`yaml.constructor.ConstructorError: could not determine a constructor for the tag '!Ref'` loading a CloudFormation template.
IntermediateTroubleshootingRuntime, file, subprocess & encoding errors
Answer
Likely causes → CloudFormation short-form intrinsic functions (!Ref, !Sub, !GetAtt) are custom YAML tags that safe_load does not know.
Diagnose →
grep -n "!\(Ref\|Sub\|GetAtt\|If\)" template.yaml | head
Fix → Register constructors on a SafeLoader subclass that turn tags into {"Ref": value} dicts, or use the cfn-flip library to convert, or cfn-lint for validation.
Prevent → Use a CloudFormation-aware loader for templates; keep plain safe_load for ordinary YAML.
More on Runtime, file, subprocess & encoding errors
`KeyError: 'Tags'` while processing `describe_instances` output.Beginner`TypeError: can't compare offset-naive and offset-aware datetimes` in a snapshot-age check.Beginner`UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte` reading a log file.Intermediate`UnicodeEncodeError: 'ascii' codec can't encode character '✓'` when printing in a container.Intermediate`PermissionError: [Errno 13] Permission denied: '/var/log/app/report.json'`Intermediate`OSError: [Errno 24] Too many open files` in a long-running Python service.Intermediate