title: Parse an AWS CloudFormation template with the PyYAML library
body: <p>I am writing a custom Python application using the PyYAML library that needs to read in AWS CloudFormation YAML templates.</p>
  
  <p>I know the templates are valid CloudFormation templates, because I tested them using validate-template:</p>
  
  <pre class="lang-none prettyprint-override"><code>▶ aws cloudformation validate-template --template-body file://cloudformation.yml
  </code></pre>
  
  <p>When I try to read them using the PyYAML library, however, I get errors like:</p>
  
  <blockquote>
    <p>yaml.scanner.ScannerError: mapping values are not allowed here</p>
  </blockquote>
  
  <p>and </p>
  
  <blockquote>
    <p>could not determine a constructor for the tag "!Sub"</p>
  </blockquote>
  
  <p>and others.</p>
  
  <p>By way of example, I try this AWS example template:</p>
  
  <pre class="lang-none prettyprint-override"><code>▶ curl -s \
      https://raw.githubusercontent.com/awslabs/aws-cloudformation-templates/master/aws/services/CloudFormation/FindInMap_Inside_Sub.yaml \
      -o FindInMap_Inside_Sub.yaml
  </code></pre>
  
  <p>And then:</p>
  
  <pre class="lang-none prettyprint-override"><code>▶ python
  Python 2.7.15 (default, Nov 27 2018, 21:40:55) 
  [GCC 4.2.1 Compatible Apple LLVM 10.0.0 (clang-1000.11.45.5)] on darwin
  Type "help", "copyright", "credits" or "license" for more information.
  &gt;&gt;&gt; import yaml
  &gt;&gt;&gt; yaml.load(open('FindInMap_Inside_Sub.yaml'))
  </code></pre>
  
  <p>Which leads to:</p>
  
  <pre class="lang-none prettyprint-override"><code>yaml.constructor.ConstructorError: could not determine a constructor for the tag '!FindInMap'
    in "FindInMap_Inside_Sub.yaml", line 89, column 45
  </code></pre>
  
  <p><strong>How can I parse a CloudFormation YAML file using a library like PyYAML or others?</strong></p>