title: AWS APIGateway with Cognito Authorizer defined in OpenAPI Spec
body: <p><strong>Tools</strong></p>
  
  <ul>
  <li>Terraform v0.11.14</li>
  </ul>
  
  <p><strong>Setup</strong></p>
  
  <ul>
  <li>API Gateway managed by Terraform, defined using OpenAPI Spec</li>
  <li>Cognito Authorizer</li>
  </ul>
  
  <p>I'm trying to specify the Authorizer for a method in my API.  I can do this using the console (it's pretty well documented):</p>
  
  <p><a href="https://i.stack.imgur.com/sohAZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sohAZ.png" alt="Manual Cognito Authorizer"></a></p>
  
  <p><strong>Problem</strong></p>
  
  <p>I want to be able to set this programatically using the OpenAPI spec.  The relevant documentation from AWS is <a href="https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-enable-cognito-user-pool.html" rel="nofollow noreferrer">here</a></p>
  
  <p>It says that you can create the Authorizer object in the OpenAPI spec by specifying:</p>
  
  <pre><code>securitySchemes:
    NameOfCognitoAuthorizer:
      type: apiKey
      name: Authorization
      in: header
      x-amazon-apigateway-authtype: cognito_user_pools
      x-amazon-apigateway-authorizer:
        type: cognito_user_pools
        providerARNs:
        - 'arn:aws:cognito-idp:{region}:{account_id}:userpool/{user_pool_id}'
  </code></pre>
  
  <p>This works as expected.</p>
  
  <p>And then once this is done, you should be able to apply the Authorizer to a resource method as follows:</p>
  
  <pre><code>post:
    summary: Create a new Item
    responses:
      '200':
        description: Ok
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Item'
    security:
      - NameOfCognitoAuthorizer:
  </code></pre>
  
  <p>However, once I apply the changes and inspect the post method in the AWS console, I can see that the Authorizer has not been applied to the API method.  Can anyone see what I have done wrong?</p>
  
  <p>For completeness, my API is created using terraform:</p>
  
  <pre class="lang-sh prettyprint-override"><code>resource "aws_api_gateway_rest_api" "this" {
    name        = "MyAPI"
    body        = "${file("./api-spec.yaml")}"
  
    endpoint_configuration {
      types = ["REGIONAL"]
    }
  }
  </code></pre>