title: How to enable CORS with AWS SAM
body: <p>I'm trying to enable CORS in my AWS SAM app. Here is the snippet from my <code>template.yaml</code>:</p>
  <pre><code>Globals:
    Api:
      Cors:
        AllowMethods: &quot;'*'&quot;
        AllowHeaders: &quot;'*'&quot;
        AllowOrigin: &quot;'*'&quot;
  
  Resources:
    MyApi:
      Type: AWS::Serverless::Api
      Properties:
        StageName: prod
        Auth:
          Authorizers:
            MyCognitoAuthorizer: ...
  
    getByIdFunc:
      Type: AWS::Serverless::Function
      Properties:
        Handler: src/handler.handle
        Events:
          ApiEvent:
            Type: Api
            Properties:
              Path: /{id}
              Method: GET
              RestApiId: !Ref MyApi
  </code></pre>
  <p>According to this <a href="https://stackoverflow.com/questions/50229563/using-cors-with-aws-sam">Using CORS with AWS SAM</a> and that <a href="https://github.com/aws/serverless-application-model/issues/373" rel="noreferrer">https://github.com/aws/serverless-application-model/issues/373</a>, the cors config should work but unfortunately no header is set on the API response, as seen below.</p>
  <pre><code>&lt; HTTP/2 200 
  &lt; content-type: application/json
  &lt; content-length: 770
  &lt; date: Tue, 13 Apr 2021 19:55:31 GMT
  &lt; x-amzn-requestid: ...
  &lt; x-amz-apigw-id: ...
  &lt; x-amzn-trace-id: Root=1-...-...;Sampled=0
  &lt; x-cache: Miss from cloudfront
  &lt; via: 1.1 ...cloudfront.net (CloudFront)
  &lt; x-amz-cf-pop: FRA2-C2
  &lt; x-amz-cf-id: ...==
  &lt; 
  * Connection #0 to host ....execute-api.eu-central-1.amazonaws.com left intact
  [{&quot;model&quot;: ..}]
  </code></pre>
  <p>I also tried adding the cors config to the API definition (MyApi) itself like its stated in the <a href="https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-property-api-corsconfiguration.html" rel="noreferrer">offical docs here</a>, but without success.</p>
  <p>I could add the header in the response by myself but i rather have it in the template file.</p>