AWS::Serverless::HttpApi CorsConfiguration not working
- Dominant language
- Python
- Stars
- 6.7k
- Forks
- 1.2k
- Avg merge
- 1d 10h
- Merged PRs (30d)
- 52
Description
### Description:
I have an `AWS::Serverless::HttpApi` resource with the `CorsConfiguration` property. The template deploys ok and I can get a successful response from the endpoint sending a `GET` request using Postman but, an `OPTION` request returns error 404.
### Steps to reproduce:
Here is my template
```YAML
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Parameters:
EnvironmentName:
Description: An environment name
Type: String
Default: production
AllowedValues:
- sandbox
- production
- staging
StageName:
Type: String
Description: Api Stage Name
Default: 'v0'
UiUserPoolId:
Type: String
Description: Ui User Pool Id.
UiUserPoolClientId:
Type: String
Description: Ui User Pool Client Id.
Globals:
Function:
Runtime: nodejs12.x
MemorySize: 128
Timeout: 60
Handler: index.handler
Environment:
Variables:
AWS_NODEJS_CONNECTION_REUSE_ENABLED: 1
Resources:
MyApi:
Type: 'AWS::Serverless::HttpApi'
Properties:
StageName: !Ref 'StageName'
CorsConfiguration:
AllowCredentials: true
AllowMethods: "'GET,POST,OPTIONS'"
AllowHeaders: "'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'"
AllowOrigins: "'http://localhost:9000'"
Auth:
Authorizers:
OAuth2Authorizer:
JwtConfiguration:
issuer: !Sub 'https://cognito-idp.${AWS::Region}.amazonaws.com/${UiUserPoolId}'
audience:
- !Ref UiUserPoolClientId
IdentitySource: '$request.header.Authorization'
Tags:
Environment: !Sub '${EnvironmentName}'
FantazGlobalNotificationFunction:
Type: AWS::Serverless::Function
Properties:
Description: global notification for FantaZ UI
FunctionName: !Sub '${EnvironmentName}-client-global-notification-lambda'
CodeUri: ./global-notification/
MemorySize: 128
Environment:
Variables:
GLOBAL_NOTIFICATION_TABLE: !Sub '${EnvironmentName}-cf-GlobalNotification'
ORIGIN: 'http://localhost:9000'
Policies:
- DynamoDBReadPolicy:
TableName: !Sub '${EnvironmentName}-cf-GlobalNotification'
Events:
Get:
Type: HttpApi
Properties:
Path: /globalNotification
ApiId: !Ref MyApi
Method: GET
Tags:
Environment: !Sub '${EnvironmentName}'
Outputs:
MyApiUrl:
Value: !Sub 'https://${MyApi}.execute-api.${AWS::Region}.amazonaws.com/${StageName}'
Description: Client API URL
```
### Observed result:
After deploying the template, if I go to the API Gateway console and open the CORS page this is what I see

As you can see, there is no value set. If I send a `GET` to `/v0/globalNotification` it works ok, but sending an `OPTIONS` to the same endpoint fails with a 404 error.

Am I missing something? Is my template wrong?
### Expected result:
Send an `OPTIONS` request works as expected.
### Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
1. OS: Linux
2. `sam --version`: 1.18.1
3. AWS region: us-east-1
Contributor guide
Assessment
This issue has not been assessed yet.