Skip to content

Commit cfa9c9e

Browse files
authored
Merge pull request #4 from oreillymedia/CL-550
Cl 550 | Adjust cloudcontrol behavior in aws-nuke to properly handle ThrottlingExceptions
2 parents 0b661ad + 1c22311 commit cfa9c9e

File tree

3 files changed

+37
-5
lines changed

3 files changed

+37
-5
lines changed

cmd/nuke.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,16 @@ func (n *Nuke) Run() error {
6363
return err
6464
}
6565

66+
if n.items.Count(ItemStateFailed) > 0 && n.items.Count(ItemStateNew) == 0 {
67+
for _, item := range n.items {
68+
if item.State != ItemStateFailed {
69+
continue
70+
}
71+
logrus.Error(fmt.Sprintf("%s. %s.", item.Type, item.Reason))
72+
}
73+
return fmt.Errorf("failed")
74+
}
75+
6676
if n.items.Count(ItemStateNew) == 0 {
6777
fmt.Println("No resource to delete.")
6878
return nil
@@ -249,9 +259,14 @@ func (n *Nuke) HandleQueue() {
249259
n.HandleRemove(item)
250260
item.Print()
251261
case ItemStateFailed:
252-
n.HandleRemove(item)
253-
n.HandleWait(item, listCache)
254-
item.Print()
262+
// item.Resource will be nil if an exception was thrown while retrieving cloudControl
263+
// resourceType's items (I.E resourceTypes lister()), however we still pass down the
264+
// reason and state so we aren't ignoring these exceptions.
265+
if item.Resource != nil {
266+
n.HandleRemove(item)
267+
n.HandleWait(item, listCache)
268+
item.Print()
269+
}
255270
case ItemStatePending:
256271
n.HandleWait(item, listCache)
257272
item.State = ItemStateWaiting

cmd/scan.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ import (
55
"fmt"
66
"runtime/debug"
77

8+
"github.com/aws/aws-sdk-go/aws/awserr"
89
"github.com/rebuy-de/aws-nuke/v2/pkg/awsutil"
910
"github.com/rebuy-de/aws-nuke/v2/pkg/util"
1011
"github.com/rebuy-de/aws-nuke/v2/resources"
1112
log "github.com/sirupsen/logrus"
1213
"golang.org/x/sync/semaphore"
1314
)
1415

15-
const ScannerParallelQueries = 2
16+
const ScannerParallelQueries = 16
1617

1718
func Scan(region *Region, resourceTypes []string) <-chan *Item {
1819
s := &scanner{
@@ -72,6 +73,20 @@ func (s *scanner) list(region *Region, resourceType string) {
7273
return
7374
}
7475

76+
awsErr, ok := err.(awserr.Error)
77+
if ok && awsErr.Code() == "ThrottlingException" {
78+
s.items <- &Item{
79+
Region: region,
80+
Resource: nil,
81+
State: ItemStateFailed,
82+
Reason: err.Error(),
83+
Type: resourceType,
84+
}
85+
dump := util.Indent(fmt.Sprintf("%v", err), " ")
86+
log.Errorf("Listing %s failed:\n%s", resourceType, dump)
87+
return
88+
}
89+
7590
dump := util.Indent(fmt.Sprintf("%v", err), " ")
7691
log.Errorf("Listing %s failed:\n%s", resourceType, dump)
7792
return

resources/cloudcontrol.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,11 @@ func init() {
3737
registerCloudControl("AWS::NetworkFirewall::RuleGroup")
3838
}
3939

40+
const CloudControlAPiMaxRetries = 5
41+
4042
func NewListCloudControlResource(typeName string) func(*session.Session) ([]Resource, error) {
4143
return func(sess *session.Session) ([]Resource, error) {
42-
svc := cloudcontrolapi.New(sess)
44+
svc := cloudcontrolapi.New(sess, &aws.Config{MaxRetries: aws.Int(CloudControlAPiMaxRetries)})
4345

4446
params := &cloudcontrolapi.ListResourcesInput{
4547
TypeName: aws.String(typeName),

0 commit comments

Comments
 (0)