【问题标题】:Configure an API Gateway method to inherit throttling settings from the stage配置 API Gateway 方法以从阶段继承限制设置
【发布时间】:2020-08-09 09:06:52
【问题描述】:

我正在使用 AWS CLI update-stage 命令为 API 网关方法配置特定的限制设置,效果很好:

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-services aws-sdk aws-api-gateway aws-cli throttling


    【解决方案1】:

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

    【讨论】:

    • 谢谢,这很有用,但是我只需要更改限制设置,而不是其他任何设置,因为该方法可能具有覆盖默认值的其他设置。有没有办法告诉它从舞台上获得它的节流设置?
    • 我认为目前不可能。当提到方法级别覆盖时,所有设置都是从​​覆盖中读取的,而不是默认为阶段。
    猜你喜欢
    • 2020-05-24
    • 2011-03-09
    • 1970-01-01
    • 2019-06-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-01
    相关资源
    最近更新 更多