我有一个Custom Authorizer
. API Gateway
当通过它部署时,SAM Module
它也会Options Method
在您启用时创建CORS
。我真的不明白为什么自定义授权者会附加到Options
端点?
当我尝试从浏览器调用端点时,这是抛出的,当我从方法403
中删除时,它工作得很好。Authorization
Options
下面是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
我也启用了'Access-Control-Allow-Origin': '*'
in 标头。不知道这里发生了什么。任何帮助,将不胜感激