Skip to content

Commit d930998

Browse files
ekristencorybekk
authored andcommitted
feat(apigateway-restapi): support rate limit on remove
1 parent d03f1b7 commit d930998

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

resources/apigateway-restapis.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"context"
55
"time"
66

7+
"go.uber.org/ratelimit"
8+
79
"github.com/aws/aws-sdk-go/aws"
810
"github.com/aws/aws-sdk-go/service/apigateway"
911

@@ -16,6 +18,12 @@ import (
1618

1719
const APIGatewayRestAPIResource = "APIGatewayRestAPI"
1820

21+
// Rate limit to avoid throttling when deleting API Gateway Rest APIs
22+
// The API Gateway Delete Rest API has a limit of 1 request per 30 seconds for each account
23+
// https://docs.aws.amazon.com/apigateway/latest/developerguide/limits.html
24+
// Note: due to time drift, set to 31 seconds to be safe.
25+
var deleteRestAPILimit = ratelimit.New(1, ratelimit.Per(32*time.Second))
26+
1927
func init() {
2028
registry.Register(&registry.Registration{
2129
Name: APIGatewayRestAPIResource,
@@ -73,6 +81,8 @@ func (l *APIGatewayRestAPILister) List(_ context.Context, o interface{}) ([]reso
7381
}
7482

7583
func (f *APIGatewayRestAPI) Remove(_ context.Context) error {
84+
deleteRestAPILimit.Take()
85+
7686
_, err := f.svc.DeleteRestApi(&apigateway.DeleteRestApiInput{
7787
RestApiId: f.restAPIID,
7888
})

0 commit comments

Comments
 (0)