Skip to content

Commit 5439fa2

Browse files
ekristencorybekk
authored andcommitted
feat(apigateway-api-key): support rate limit on remove
1 parent d930998 commit 5439fa2

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

resources/apigateway-api-key.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package resources
22

33
import (
44
"context"
5+
"go.uber.org/ratelimit"
56
"time"
67

78
"github.com/aws/aws-sdk-go/aws"
@@ -16,6 +17,12 @@ import (
1617

1718
const APIGatewayAPIKeyResource = "APIGatewayAPIKey"
1819

20+
// Rate limit to avoid throttling when deleting API Gateway Rest APIs
21+
// The API Gateway Delete Rest API has a limit of 1 request per 30 seconds for each account
22+
// https://docs.aws.amazon.com/apigateway/latest/developerguide/limits.html
23+
// Note: due to time drift, set to 31 seconds to be safe.
24+
var deleteAPIKeyLimit = ratelimit.New(1, ratelimit.Per(32*time.Second))
25+
1926
func init() {
2027
registry.Register(&registry.Registration{
2128
Name: APIGatewayAPIKeyResource,
@@ -72,6 +79,8 @@ type APIGatewayAPIKey struct {
7279
}
7380

7481
func (r *APIGatewayAPIKey) Remove(_ context.Context) error {
82+
deleteAPIKeyLimit.Take()
83+
7584
_, err := r.svc.DeleteApiKey(&apigateway.DeleteApiKeyInput{
7685
ApiKey: r.apiKey,
7786
})

0 commit comments

Comments
 (0)