Search code examples
amazon-web-servicesaws-api-gatewayaws-cli

Error when creating Usage Plan using AWS CLI for a specific Stage in API Gateway


I want to create a usage plan for an associated API stage. I am using the following command right now:

aws apigateway create-usage-plan --name "New Usage Plan1"  --api-stages  '[{ "apiId": "abcde12345", "stage":"test-stage", "throttle": {"Test from CLI": { "burstLimit": 200, "rateLimit": 100}}}]' --throttle burstLimit=200,rateLimit=100 --quota limit=500,offset=0,period=MONTH

where abcde12345 is my Rest API ID, test-stage is the stage I want it to be associated with, Test from CLI is the API Key I successfully created.

I get the following error:

An error occurred (BadRequestException) when calling the CreateUsagePlan operation: Invalid method {resourcePath: Test from CLI,method: } specified

I tried replacing the Key Test from CLI with the ID of the API Key abc123 but that throws the same error as well:

An error occurred (BadRequestException) when calling the CreateUsagePlan operation: Invalid method {resourcePath: abc123,method: } specified

I looked at this to create this usage plan. Where am I going wrong in this command?


Solution

  • Test from CLI is the name of my API Key

    This is not what KeyName1 referers to. This is a key name representing your method in your API, e.g. /pets/GET in the following default example :

        "apiStages": [
            {
                "apiId": "ym7ggv1kh6",
                "stage": "test",
                "throttle": {
                    "/pets/GET": {
                        "burstLimit": 33,
                        "rateLimit": 33.0
                    }
                }
            }
        ],