这是我的SAM模板:
webApi:
Type: AWS::Serverless::Api
Properties:
Auth:
DefaultAuthorizer: CognitoAuthorizer
Authorizers:
CognitoAuthorizer:
UserPoolArn: !GetAtt myUserPool.Arn
AddDefaultAuthorizerToCorsPreflight: false
Cors:
AllowMethods: "'*'"
AllowHeaders: "'*'"
AllowOrigin: "'*'"
StageName: !Ref Environment
DefinitionBody:
swagger: "2.0"
info:
title:
Ref: AWS::StackName
paths:
/path/one:
post:
responses: {}
x-amazon-apigateway-integration:
uri: myFunction.Arn
httpMethod: "POST"
type: "aws_proxy"
/path/two:
post:
responses: {}
x-amazon-apigateway-integration:
uri: myFunction.Arn
httpMethod: "POST"
type: "aws_proxy"
如何使path/two
成为未经身份验证的路由?
我试图用Google搜索,但是什么也没有。
如果可能,我不想创建另一个API网关。我想在同一资源内完成此操作。
答案 0 :(得分:2)
作为OpenAPI,您可以使用security: []
在某些路径中禁用身份验证。
引用:
https://github.com/zalando/connexion/issues/944 https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-restapi.html#cfn-apigateway-restapi-body
答案 1 :(得分:0)
在AWS SAM模板中,要为DefinitionBody
中的特定端点禁用安全性,对我有用的是:
swagger: "2.0"
info:
title:
Ref: AWS::StackName
paths:
/path/one:
post:
security:
- NONE: []