@@ -3,8 +3,10 @@ package resources
33import (
44 "context"
55 "errors"
6+ "time"
67
78 "github.com/gotidy/ptr"
9+ "go.uber.org/ratelimit"
810
911 "github.com/aws/aws-sdk-go-v2/service/ecs"
1012 ecstypes "github.com/aws/aws-sdk-go-v2/service/ecs/types"
@@ -17,6 +19,14 @@ import (
1719 "github.com/ekristen/aws-nuke/v3/pkg/nuke"
1820)
1921
22+ // Note: these are global, they really should be per-region
23+ var ecsTaskDefinitionModifyActionsRateLimit = ratelimit .New (1 ,
24+ ratelimit .Per (1 * time .Second ), ratelimit .WithSlack (15 ))
25+ var ecsTaskDefinitionDeleteActionsRateLimit = ratelimit .New (1 ,
26+ ratelimit .Per (1 * time .Second ), ratelimit .WithSlack (5 ))
27+ var ecsTaskDefinitionReadActionsRateLimit = ratelimit .New (20 ,
28+ ratelimit .Per (1 * time .Second ), ratelimit .WithSlack (50 ))
29+
2030const ECSTaskDefinitionResource = "ECSTaskDefinition"
2131
2232func init () {
@@ -49,6 +59,8 @@ func (l *ECSTaskDefinitionLister) List(ctx context.Context, o interface{}) ([]re
4959 }
5060
5161 for {
62+ ecsTaskDefinitionReadActionsRateLimit .Take ()
63+
5264 output , err := svc .ListTaskDefinitions (ctx , params )
5365 if err != nil {
5466 var errSkipRequest = liberrors .ErrSkipRequest ("skip global" )
@@ -61,6 +73,8 @@ func (l *ECSTaskDefinitionLister) List(ctx context.Context, o interface{}) ([]re
6173 }
6274
6375 for _ , taskDefinitionARN := range output .TaskDefinitionArns {
76+ ecsTaskDefinitionReadActionsRateLimit .Take ()
77+
6478 details , err := svc .DescribeTaskDefinition (ctx , & ecs.DescribeTaskDefinitionInput {
6579 TaskDefinition : ptr .String (taskDefinitionARN ),
6680 })
@@ -105,6 +119,8 @@ func (r *ECSTaskDefinition) Filter() error {
105119
106120func (r * ECSTaskDefinition ) Remove (ctx context.Context ) error {
107121 if * r .Status != string (ecstypes .TaskDefinitionStatusInactive ) {
122+ ecsTaskDefinitionModifyActionsRateLimit .Take ()
123+
108124 _ , err := r .svc .DeregisterTaskDefinition (ctx , & ecs.DeregisterTaskDefinitionInput {
109125 TaskDefinition : r .arn ,
110126 })
@@ -113,6 +129,8 @@ func (r *ECSTaskDefinition) Remove(ctx context.Context) error {
113129 }
114130 }
115131
132+ ecsTaskDefinitionDeleteActionsRateLimit .Take ()
133+
116134 _ , err := r .svc .DeleteTaskDefinitions (ctx , & ecs.DeleteTaskDefinitionsInput {
117135 TaskDefinitions : []string {* r .arn },
118136 })
0 commit comments