【发布时间】:2019-10-13 17:05:16
【问题描述】:
工具
- Terraform v0.11.14
设置
- 由 Terraform 管理的 API 网关,使用 OpenAPI 规范定义
- Cognito 授权者
我正在尝试为我的 API 中的方法指定授权方。我可以使用控制台来做到这一点(它有很好的记录):
问题
我希望能够使用 OpenAPI 规范以编程方式进行设置。 AWS 的相关文档是here
它说你可以在 OpenAPI 规范中通过指定来创建 Authorizer 对象:
securitySchemes:
NameOfCognitoAuthorizer:
type: apiKey
name: Authorization
in: header
x-amazon-apigateway-authtype: cognito_user_pools
x-amazon-apigateway-authorizer:
type: cognito_user_pools
providerARNs:
- 'arn:aws:cognito-idp:{region}:{account_id}:userpool/{user_pool_id}'
这按预期工作。
然后一旦完成,您应该能够将 Authorizer 应用于资源方法,如下所示:
post:
summary: Create a new Item
responses:
'200':
description: Ok
content:
application/json:
schema:
$ref: '#/components/schemas/Item'
security:
- NameOfCognitoAuthorizer:
但是,一旦我应用更改并在 AWS 控制台中检查 post 方法,我可以看到 Authorizer 尚未应用于 API 方法。谁能看到我做错了什么?
为了完整起见,我的 API 是使用 terraform 创建的:
resource "aws_api_gateway_rest_api" "this" {
name = "MyAPI"
body = "${file("./api-spec.yaml")}"
endpoint_configuration {
types = ["REGIONAL"]
}
}
【问题讨论】:
标签: amazon-web-services aws-api-gateway amazon-cognito