I have a Custom Authorizer
with API Gateway
. When deployed through SAM Module
it also creates Options Method
when you enable CORS
. The thing I really don't understand is why the custom authorizer gets attached to Options
endpoint?
This is throwing 403
when I try to call the endpoint from browser and works perfectly fine when I remove Authorization
from the Options
method.
Below is the template.yaml
AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Globals:
Function:
Runtime: nodejs8.10
Api:
Cors:
AllowMethods: "'*'"
AllowHeaders: "'*'"
AllowOrigin: "'*'"
Resources:
TestApi:
Type: AWS::Serverless::Api
Properties:
StageName: dev
Auth:
DefaultAuthorizer: testAuthoriser
Authorizers:
testAuthoriser:
FunctionArn:
Fn::ImportValue: !Sub test-custom-autoriser
Identity:
Header: Authorization
ValidationExpression: ^Bearer [-0-9a-zA-Z\._]*$
ReauthorizeEvery: 30
Version:
Type: 'AWS::Serverless::Function'
Properties:
FunctionName: test
CodeUri: src/test
Handler: index.test
Events:
EndPoint:
Type: Api
Properties:
RestApiId: !Ref TestApi
Path: /test
Method: get
Auth:
Authorizer: testAuthoriser
I have enabled the 'Access-Control-Allow-Origin': '*'
in header as well. Not sure what's going on here. Any help would be appreciated
Options
method? – Moffat