Skip to content

Defining CORS when ApiKeyRequired is true results in an OPTIONS method that requires an API key #1786

@egalev

Description

@egalev

Description:

When setting up an API Gateway with {proxy+} integration through SAM, having a required API key prevents the CORS definition from properly responding to OPTIONS requests, since they require an API key as well.

Steps to reproduce the issue:

  1. Define an Api that requires an API key:
Resources:
  BasicAWSApiGateway:
    Type: AWS::Serverless::Api
    Properties:
      StageName: !Ref Environment
      Auth:
        ApiKeyRequired: true
      Cors: "'*'"
      DefinitionBody:
        swagger: "2.0.0"
        info:
          version: 1.0.0
        paths:
          /{proxy+}:
            x-amazon-apigateway-any-method:
              produces:
                - application/json
              parameters:
                - in: path
                  name: proxy
                  required: true
                  type: string
              x-amazon-apigateway-integration:
                uri: !Sub "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:${LambdaName}-${Environment}/invocations"
                httpMethod: POST
                type: aws_proxy
                passthroughBehavior: when_no_match
                credentials: !GetAtt ApiGatewayExecutionRole.Arn

Observed result:
The OPTIONS method in API Gateway requires an API Key, blocking CORS since browsers don't add a x-api-key header.

Expected result:
The OPTIONS method should not require an API Key.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions