首页 > 解决方案 > 配置 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 开发工具包)来获取再次从阶段继承设置的方法?

标签: amazon-web-servicesaws-sdkaws-api-gatewayaws-clithrottling

解决方案


这里的问题是删除调用的路径。您正在使用“/~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 控制台进行的网络调用找到了这个解决方案。


推荐阅读