为了启用 AWS_IAM auth 和 CORS,我制作了我的 sam 模板,如下所示。
但是,我收到一条错误消息
未能创建变更集:Waiter ChangeSetCreateComplete 失败:Waiter 遇到终端故障状态状态:FAILED。原因:转换 AWS::Serverless-2016-10-31 失败,原因是:无服务器应用程序规范文档无效。发现的错误数: 1. id 为 [ListFunction] 的资源无效。ID 为 [ListFunctionCors] 的事件无效。无法在路径 [/list] 的 API 方法 [options] 上设置 Authorizer [NONE],因为相关 API 未定义任何 Authorizer。
这里有什么问题?
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
ListApi:
Type: AWS::Serverless::Api
Properties:
StageName: Prod
Auth:
DefaultAuthorizer: AWS_IAM
Cors:
AllowMethods: "'*'"
AllowHeaders: "'*'"
AllowOrigin: "'*'"
ListFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: app_src/
Handler: app.lambda_handler
Runtime: python3.7
Events:
ListFunction:
Type: Api
Properties:
RestApiId: !Ref ListApi
Path: /list
Method: GET
ListFunctionCors:
Type: Api
Properties:
RestApiId: !Ref ListApi
Path: /list
Method: OPTIONS
Auth:
Authorizer: 'NONE'