在cloudformation中,AWS::ApiGateway::Method具有一个布尔属性ApiKeyRequired。我如何在SAM中实现同样的目标?
我知道我们可以使用显式的swagger配置来启用。就像这样
{
"swagger": "2.0",
"info": {
"version": "1.0",
"title": {
"Ref": "AWS::StackName"
}
},
"x-amazon-apigateway-api-key-source": "HEADER",
"paths": {
"/": {
"get": {
"x-amazon-apigateway-integration": {
"httpMethod": "POST",
"type": "aws_proxy",
"uri": {
"Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${GetHelloWorld.Arn}/invocations"
}
},
"responses": {},
"security": [
{
"api_key": []
}
]
}
}
},
"securityDefinitions": {
"api_key": {
"type": "apiKey",
"name": "x-api-key",
"in": "header"
}
}
}不能在SAM中使用隐式API调用而不是显式传递AWS::Serverless::Api吗?因为swagger代码可以使用较少的端点,并且随着端点的增加而变得复杂。有像APIkeyRequired一样的Cloudformation旗子吗?
任何帮助都是非常感谢的
发布于 2020-05-27 17:51:58
现在,SAM中的ApiKeyRequired在AWS::Serverless::Api和AWS::Serverless::Function级别都得到了支持。
以下是AWS文档中的一个示例:
Resources:
MyApi:
Type: AWS::Serverless::Api
Properties:
StageName: Prod
Auth:
ApiKeyRequired: true # sets for all methods
MyFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: .
Handler: index.handler
Runtime: nodejs8.10
Events:
ApiKey:
Type: Api
Properties:
RestApiId: !Ref MyApi
Path: /
Method: get
Auth:
ApiKeyRequired: true您还可以从以下资源了解此信息:
https://stackoverflow.com/questions/52936126
复制相似问题