serverless-application-model: Unable to set authorizer on AWS::Serverless::HttpApi on $default path
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.”
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)
- OS: Ubuntu
sam --version
: 1.15.0
Add --debug flag to command you are running
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 1
- Comments: 18 (7 by maintainers)
Commits related to this issue
- default route bug https://github.com/aws/serverless-application-model/issues/2481 — committed to jneeee/taskbox by jneeee 2 years ago
- default route bug https://github.com/aws/serverless-application-model/issues/2481 — committed to jneeee/taskbox by jneeee 2 years ago
- default route bug https://github.com/aws/serverless-application-model/issues/2481 — committed to jneeee/taskbox by jneeee 2 years ago
As for auth support in
sam local
, it is not yet supported in AWS SAM CLI. Please refer to the issue https://github.com/aws/aws-sam-cli/issues/137Sorry for the delay @rockey5520. Support for
$default
route was added at a later date as part of a quick create for HttpApi. SAM do not have support for this yet. When you declarePath
as$default
SAM puts it in Path body which based on OpenAPI specification need to start with a/
, that is why you are seeing that error.I am marking this issue as a feature request and will update after discussing in team.
Please let me know if you have any questions.
Thanks Tarun