title: How to configure CORS for AWS API Gateway using OpenAPI?
body: <p>I have an OpenAPI spec for an api which I am deploying via CDK.  The spec looks like:</p>
  <pre><code>openapi: 3.0.1
  info:
    title: My API
    description: My REST API with CORS enabled
    version: 0.1.0
  
  x-amazon-apigateway-cors:
    allowOrigins:
      - &quot;*&quot;
    allowCredentials: true
    exposeHeaders:
      - &quot;x-apigateway-header&quot;
      - &quot;x-amz-date&quot;
      - &quot;content-type&quot;
    maxAge: 3600
    allowMethods:
      - &quot;*&quot;
    allowHeaders&quot;:
      - &quot;x-apigateway-header&quot;
      - &quot;x-amz-date&quot;
      - &quot;content-type&quot;
      - &quot;Authorization&quot;
  
  components:
    securitySchemes:
      lambda:
        type: &quot;apiKey&quot;
        name: &quot;Authorization&quot;
        in: &quot;header&quot;
        x-amazon-apigateway-authtype: &quot;custom&quot;
        x-amazon-apigateway-authorizer:
          authorizerUri: &quot;{{my-lambda-authorizer}}&quot;
          authorizerResultTtlInSeconds: 300
          type: &quot;token&quot; 
  
  paths:
    /user/{id}:
      get:
        summary: Get info of specified user.
        parameters:
          - in: path
            name: id
            required: true
            schema:
              type: string
        responses:
          '200':
            description: OK
            content:
              application/json:
                schema:
                  $ref: '#/components/schemas/User'
        security:
          - lambda: []
        x-amazon-apigateway-integration:
          uri: &quot;{{my-lambda}}&quot;
          passthroughBehavior: &quot;when_no_match&quot;
          httpMethod: &quot;POST&quot;
          type: &quot;aws_proxy&quot;
  </code></pre>
  <p>When I try to access this via <code>fetch()</code>, I get an error <code>Failed to load resource: Origin http://localhost:8000 is not allowed by Access-Control-Allow-Origin</code>.</p>
  <pre><code>fetch('https://api.example.com/user/1')
          .then(response =&gt; response.json())
          .then((user: User) =&gt; {
              // do something
          })
          .catch((err) =&gt; {
              console.log(&quot;Error: &quot; + err);
          });
  </code></pre>
  <p>The API is accessible at <code>api.example.com</code> and I am running the website locally using Gatsby at <code>localhost:8000</code>.</p>
  <p>The <a href="https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-swagger-extensions-cors-configuration.html" rel="nofollow noreferrer">AWS docs</a> seem to state that CORS is enabled when I put <code>x-amazon-apigateway-cors</code> at the root of the spec, but CORS doesn't seem to be enabled (or working) when I try to access the API.  How do I enable CORS for my API without needing to configure it in the console?</p>