amazon-web-services - 配置 API Gateway 方法以从阶段继承限制设置
问题描述
我正在使用 AWS CLIupdate-stage
命令为 API Gateway 方法配置特定的限制设置,效果很好:
aws apigateway update-stage --rest-api-id <the-id> --stage-name <the-stage-name>
--patch-operations op=replace,path='/~1cats~1{pawId}/GET/throttling/rateLimit',value=10
但是,当我尝试删除我刚刚配置的设置并从阶段继承限制设置时,默认情况下,我收到一个错误:
aws apigateway update-stage --rest-api-id <the-id> --stage-name <the-stage-name>
--patch-operations op=remove,path='/~1cats~1{pawId}/GET/throttling/rateLimit'
An error occurred (BadRequestException) when calling the UpdateStage operation:
Cannot remove method setting ~1cats~1{pawId}/GET/throttling/rateLimit because there
is no method setting for this method
我如何使用 CLI(或 AWS 开发工具包)来获取再次从阶段继承设置的方法?
解决方案
这里的问题是删除调用的路径。您正在使用“/~1cats~1{pawId}/GET/throttling/rateLimit”。
API Gateway 支持删除所有方法设置,而不仅仅是特定的方法设置。我从删除调用中删除了“/throttling/rateLimit”,它起作用了。
我运行了以下命令并且它有效
aws apigateway update-stage --rest-api-id <> --stage-name <> --patch-operations op=replace,path='/hw/GET/throttling/rateLimit',value=20
{
"deploymentId": "<>",
"stageName": "<>",
"cacheClusterEnabled": false,
"cacheClusterStatus": "NOT_AVAILABLE",
"methodSettings": {
"hw/GET": {
"metricsEnabled": false,
"dataTraceEnabled": false,
"throttlingBurstLimit": 5000,
"throttlingRateLimit": 20.0,
"cachingEnabled": false,
"cacheTtlInSeconds": 300,
"cacheDataEncrypted": false,
"requireAuthorizationForCacheControl": true,
"unauthorizedCacheControlHeaderStrategy": "SUCCEED_WITH_RESPONSE_HEADER"
}
},
"tracingEnabled": false,
"createdDate": "2020-04-24T13:50:18-07:00",
"lastUpdatedDate": "2020-04-27T01:21:45-07:00"
}
aws apigateway update-stage --rest-api-id <> --stage-name <> --patch-operations op=remove,path=/hw/GET,value=""
{
"deploymentId": "<>",
"stageName": "<>",
"cacheClusterEnabled": false,
"cacheClusterStatus": "NOT_AVAILABLE",
"methodSettings": {},
"tracingEnabled": false,
"createdDate": "2020-04-24T13:50:18-07:00",
"lastUpdatedDate": "2020-04-27T01:36:12-07:00"
}
我通过检查 API Gateway 控制台进行的网络调用找到了这个解决方案。
推荐阅读
- javascript - 使用 CJS 和 ESM 模块是否存在兼容性问题?
- authentication - 如何在一个应用程序中进行多用户登录?
- regex - 如何用“sed”或“awk”替换每行中第二次出现的空格?
- c++ - 如何将一个函数中的值用于主函数?
- linux - 如何在 ubuntu 18.04 上临时和永久打开/关闭 kaslr?
- image - 在数据集类上使用自定义函数调用 DataLoader 时的执行块
- javascript - 如何将上传的文件显示为附件,而不是以角度显示整个 url
- javascript - 如何在 express().use 中调用一个类?
- prolog - 序言中缺席事实的否定
- android - 在 Flutter 中制作自定义小部件时 onPress 不起作用