aws / aws/serverless-application-model

Unable to set authorizer on AWS::Serverless::HttpApi on $default path

Open
#2,481 19 comments 1 reaction 0 assignees View on GitHub
type/feature
Dominant language
Python
Stars
9.6k
Forks
2.5k
Avg merge
1d 11h
Merged PRs (30d)
7

Description

### Description:
Unable to set OAuth2 authorizer on API method [x-amazon-apigateway-any-method] for path [$default]

### Steps to reproduce:
Below is template.Yaml file used and when run sam deploy gives errror as

Waiting for changeset to be created..
"Error: Failed to create changeset for the stack: finapi, ex: Waiter ChangeSetCreateComplete failed: Waiter encountered a terminal failure state Status: FAILED. Reason: Transform AWS::Serverless-2016-10-31 failed with: Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [XXX] is invalid. Event with id [HttpApiEvent] is invalid. Unable to set Authorizer [MyOauth2Authorizer] on API method [x-amazon-apigateway-any-method] for path [$default] because the related API does not define any Authorizers."

```yaml
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Parameters:
StageName:
Type: String
Default: Prod
Description: XXX

Globals:
Api:
EndpointConfiguration: REGIONAL
Function:
Timeout: 180

Resources:
Api:
Type: AWS::Serverless::HttpApi
Properties:
StageName: !Ref StageName
Auth:
Authorizers:
MyOauth2Authorizer:
IdentitySource: $request.header.Authorization
JwtConfiguration:
audience:
- https://aws-api-gateway
issuer: "https://xxxx.eu.auth0.com/"
DefaultAuthorizer: MyOauth2Authorizer

FinApiFunction:
Type: AWS::Serverless::Function
Properties:
Handler: com.StreamLambdaHandler::handleRequest
Runtime: java11
CodeUri: api
MemorySize: 2048
Environment: # More info about Env Vars: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#environment-object
Variables:
PARAM1: VALUE
Events:
HttpApiEvent:
Type: HttpApi
Properties:
TimeoutInMillis: 20000
PayloadFormatVersion: '2.0'
Auth:
Authorizer: MyOauth2Authorizer

Outputs:
FApiFunctionApi:
Description: URL for application
Value: !Sub 'https://${ServerlessHttpApi}.execute-api.${AWS::Region}.amazonaws.com/pets'
Export:
Name: FApiFunctionApi
```

### Observed result:
Waiting for changeset to be created..
Error: Failed to create changeset for the stack: finapi, ex: Waiter ChangeSetCreateComplete failed: Waiter encountered a terminal failure state Status: FAILED. Reason: Transform AWS::Serverless-2016-10-31 failed with: Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [FinApiFunction] is invalid. Event with id [HttpApiEvent] is invalid. Unable to set Authorizer [MyOauth2Authorizer] on API method [x-amazon-apigateway-any-method] for path [$default] because the related API does not define any Authorizers.

### Expected result:
function with API method [x-amazon-apigateway-any-method] for path [$default] is created on API gateway with OAuth 2.0/JWT authorizer configured

### Additional environment details (Ex: Windows, Mac, Amazon Linux etc)

1. OS: Ubuntu
2. `sam --version`: 1.15.0

`Add --debug flag to command you are running`

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.