@@ -3,8 +3,10 @@ package resources
3
3
import (
4
4
"context"
5
5
"errors"
6
+ "time"
6
7
7
8
"github.com/gotidy/ptr"
9
+ "go.uber.org/ratelimit"
8
10
9
11
"github.com/aws/aws-sdk-go-v2/service/ecs"
10
12
ecstypes "github.com/aws/aws-sdk-go-v2/service/ecs/types"
@@ -17,6 +19,14 @@ import (
17
19
"github.com/ekristen/aws-nuke/v3/pkg/nuke"
18
20
)
19
21
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
+
20
30
const ECSTaskDefinitionResource = "ECSTaskDefinition"
21
31
22
32
func init () {
@@ -49,6 +59,8 @@ func (l *ECSTaskDefinitionLister) List(ctx context.Context, o interface{}) ([]re
49
59
}
50
60
51
61
for {
62
+ ecsTaskDefinitionReadActionsRateLimit .Take ()
63
+
52
64
output , err := svc .ListTaskDefinitions (ctx , params )
53
65
if err != nil {
54
66
var errSkipRequest = liberrors .ErrSkipRequest ("skip global" )
@@ -61,6 +73,8 @@ func (l *ECSTaskDefinitionLister) List(ctx context.Context, o interface{}) ([]re
61
73
}
62
74
63
75
for _ , taskDefinitionARN := range output .TaskDefinitionArns {
76
+ ecsTaskDefinitionReadActionsRateLimit .Take ()
77
+
64
78
details , err := svc .DescribeTaskDefinition (ctx , & ecs.DescribeTaskDefinitionInput {
65
79
TaskDefinition : ptr .String (taskDefinitionARN ),
66
80
})
@@ -105,6 +119,8 @@ func (r *ECSTaskDefinition) Filter() error {
105
119
106
120
func (r * ECSTaskDefinition ) Remove (ctx context.Context ) error {
107
121
if * r .Status != string (ecstypes .TaskDefinitionStatusInactive ) {
122
+ ecsTaskDefinitionModifyActionsRateLimit .Take ()
123
+
108
124
_ , err := r .svc .DeregisterTaskDefinition (ctx , & ecs.DeregisterTaskDefinitionInput {
109
125
TaskDefinition : r .arn ,
110
126
})
@@ -113,6 +129,8 @@ func (r *ECSTaskDefinition) Remove(ctx context.Context) error {
113
129
}
114
130
}
115
131
132
+ ecsTaskDefinitionDeleteActionsRateLimit .Take ()
133
+
116
134
_ , err := r .svc .DeleteTaskDefinitions (ctx , & ecs.DeleteTaskDefinitionsInput {
117
135
TaskDefinitions : []string {* r .arn },
118
136
})
0 commit comments