aws / aws/serverless-application-model

BinaryMediaTypes and CORS do not work together

Open
#1,344 12 comments 7 reactions 0 assignees View on GitHub
ares/cors maintainer/need-response type/bug type/bug-triaged
Dominant language
Python
Stars
9.6k
Forks
2.5k
Avg merge
1d 11h
Merged PRs (30d)
7

Description

We cannot get CORS to work with BinaryMediaTypes

Error message:

```

OPTIONS https://URL 500

Access to XMLHttpRequest at 'https://URL' from origin 'http://localhost:8000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-
Control-Allow-Origin' header is present on the requested resource.

```

This is our sam template:

```

Resources:
ApiName:
Type: AWS::Serverless::Api
Properties:
StageName: development
BinaryMediaTypes:
- '*~1*'
Cors:
AllowMethods: "'*'"
AllowHeaders: "'*'"
AllowOrigin: "'*'"
Auth:
DefaultAuthorizer: CognitoAuthorizer
AddDefaultAuthorizerToCorsPreflight: false
Authorizers:
CognitoAuthorizer:
UserPoolArn: 'USER_POOL'

```

As soon as we remove the "BinaryMediaTypes" option, the request works.

SAM CLI, version 0.37.0

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.