Turn off (Disable) individual API in API Gateway temporarily without Deleting?

Viewed 5217

Is it possible in AWS API Gateway to "turn off"/"disable" an API in API Gateway, without deleting the API itself? I'm hoping to keep the configuration of an API, without losing it through the otherwise deletion I'm hoping to avoid; that would also have the beneficial parallel motivation of preventing AWS billed API usage.

Is it possible, or is delete the only option?

3 Answers

you can set the Burst limit / Rate limit for your stage to zero. In the console: API Gateway -> select API -> Protect/Throttling -> select your stage -> EDIT Default route throttling -> Burst limit=0, Rate limit=0

Works at least for me. When calling the API you get:

{"message":"Too Many Requests"}

There is no disable button, but there are two possibilities that can be considered as a workaround:

  1. Delete the API stage(s). Without stage, API wont be accessible.
  2. Since one can be problematic if there are multiple stages with lots of custom setttings, you can add Deny resource base policy to the API.
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Deny",
            "Principal": "*",
            "Action": "execute-api:Invoke",
            "Resource": "execute-api:/{{stageNameOrWildcard}}/{{httpVerbOrWildcard}}/{{resourcePathOrWildcard}}"
        }
    ]
}

The policy will Deny all invocations of the API, making it effectively disabled. But the invocations will still count towards API usage.

I would suggest the following as a workaround:

  1. You can simply limit the Usage Plans of that specific API by activating Enable Quota and setting it to (1 request per month) for instance. enter image description here

  2. Then optionally under Gateway Responses, you can remap the Quota Exceeded response to 500. enter image description here

  3. The last step for the changes to take place, Go to Resources then click actions, Deploy API then pick the stage and click Deploy. enter image description here

Related