Skip to content
This repository was archived by the owner on Oct 15, 2024. It is now read-only.

Commit 3d46846

Browse files
committed
Defuse unnecessary errors for unavailable services
1 parent 468e5e3 commit 3d46846

8 files changed

+66
-2
lines changed

resources/fms_notification_channels.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
package resources
22

33
import (
4+
"strings"
5+
46
"github.com/aws/aws-sdk-go/aws/awserr"
57
"github.com/aws/aws-sdk-go/aws/session"
68
"github.com/aws/aws-sdk-go/service/fms"
79
"github.com/rebuy-de/aws-nuke/v2/pkg/types"
10+
"github.com/sirupsen/logrus"
811
)
912

1013
type FMSNotificationChannel struct {
@@ -21,8 +24,9 @@ func ListFMSNotificationChannel(sess *session.Session) ([]Resource, error) {
2124

2225
if _, err := svc.GetNotificationChannel(&fms.GetNotificationChannelInput{}); err != nil {
2326
if aerr, ok := err.(awserr.Error); ok {
24-
if aerr.Code() != fms.ErrCodeResourceNotFoundException {
25-
return nil, err
27+
if strings.Contains(aerr.Message(), "No default admin could be found") {
28+
logrus.Infof("FMSNotificationChannel: %s. Ignore if you haven't set it up.", aerr.Message())
29+
return nil, nil
2630
}
2731
} else {
2832
return nil, err

resources/fms_policies.go

+10
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
package resources
22

33
import (
4+
"strings"
5+
46
"github.com/aws/aws-sdk-go/aws"
7+
"github.com/aws/aws-sdk-go/aws/awserr"
58
"github.com/aws/aws-sdk-go/aws/session"
69
"github.com/aws/aws-sdk-go/service/fms"
710
"github.com/rebuy-de/aws-nuke/v2/pkg/types"
11+
"github.com/sirupsen/logrus"
812
)
913

1014
type FMSPolicy struct {
@@ -27,6 +31,12 @@ func ListFMSPolicies(sess *session.Session) ([]Resource, error) {
2731
for {
2832
resp, err := svc.ListPolicies(params)
2933
if err != nil {
34+
if aerr, ok := err.(awserr.Error); ok {
35+
if strings.Contains(aerr.Message(), "No default admin could be found") {
36+
logrus.Infof("FMSPolicy: %s. Ignore if you haven't set it up.", aerr.Message())
37+
return nil, nil
38+
}
39+
}
3040
return nil, err
3141
}
3242

resources/machinelearning-batchpredictions.go

+10
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
package resources
22

33
import (
4+
"strings"
5+
46
"github.com/aws/aws-sdk-go/aws"
7+
"github.com/aws/aws-sdk-go/aws/awserr"
58
"github.com/aws/aws-sdk-go/aws/session"
69
"github.com/aws/aws-sdk-go/service/machinelearning"
10+
"github.com/sirupsen/logrus"
711
)
812

913
type MachineLearningBranchPrediction struct {
@@ -26,6 +30,12 @@ func ListMachineLearningBranchPredictions(sess *session.Session) ([]Resource, er
2630
for {
2731
output, err := svc.DescribeBatchPredictions(params)
2832
if err != nil {
33+
if aerr, ok := err.(awserr.Error); ok {
34+
if strings.Contains(aerr.Message(), "AmazonML is no longer available to new customers") {
35+
logrus.Info("MachineLearningBranchPrediction: AmazonML is no longer available to new customers. Ignore if you haven't set it up.")
36+
return nil, nil
37+
}
38+
}
2939
return nil, err
3040
}
3141

resources/machinelearning-datasources.go

+10
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
package resources
22

33
import (
4+
"strings"
5+
46
"github.com/aws/aws-sdk-go/aws"
7+
"github.com/aws/aws-sdk-go/aws/awserr"
58
"github.com/aws/aws-sdk-go/aws/session"
69
"github.com/aws/aws-sdk-go/service/machinelearning"
10+
"github.com/sirupsen/logrus"
711
)
812

913
type MachineLearningDataSource struct {
@@ -26,6 +30,12 @@ func ListMachineLearningDataSources(sess *session.Session) ([]Resource, error) {
2630
for {
2731
output, err := svc.DescribeDataSources(params)
2832
if err != nil {
33+
if aerr, ok := err.(awserr.Error); ok {
34+
if strings.Contains(aerr.Message(), "AmazonML is no longer available to new customers") {
35+
logrus.Info("MachineLearningBranchPrediction: AmazonML is no longer available to new customers. Ignore if you haven't set it up.")
36+
return nil, nil
37+
}
38+
}
2939
return nil, err
3040
}
3141

resources/machinelearning-evaluations.go

+10
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
package resources
22

33
import (
4+
"strings"
5+
46
"github.com/aws/aws-sdk-go/aws"
7+
"github.com/aws/aws-sdk-go/aws/awserr"
58
"github.com/aws/aws-sdk-go/aws/session"
69
"github.com/aws/aws-sdk-go/service/machinelearning"
10+
"github.com/sirupsen/logrus"
711
)
812

913
type MachineLearningEvaluation struct {
@@ -26,6 +30,12 @@ func ListMachineLearningEvaluations(sess *session.Session) ([]Resource, error) {
2630
for {
2731
output, err := svc.DescribeEvaluations(params)
2832
if err != nil {
33+
if aerr, ok := err.(awserr.Error); ok {
34+
if strings.Contains(aerr.Message(), "AmazonML is no longer available to new customers") {
35+
logrus.Info("MachineLearningBranchPrediction: AmazonML is no longer available to new customers. Ignore if you haven't set it up.")
36+
return nil, nil
37+
}
38+
}
2939
return nil, err
3040
}
3141

resources/machinelearning-mlmodels.go

+10
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
package resources
22

33
import (
4+
"strings"
5+
46
"github.com/aws/aws-sdk-go/aws"
7+
"github.com/aws/aws-sdk-go/aws/awserr"
58
"github.com/aws/aws-sdk-go/aws/session"
69
"github.com/aws/aws-sdk-go/service/machinelearning"
10+
"github.com/sirupsen/logrus"
711
)
812

913
type MachineLearningMLModel struct {
@@ -26,6 +30,12 @@ func ListMachineLearningMLModels(sess *session.Session) ([]Resource, error) {
2630
for {
2731
output, err := svc.DescribeMLModels(params)
2832
if err != nil {
33+
if aerr, ok := err.(awserr.Error); ok {
34+
if strings.Contains(aerr.Message(), "AmazonML is no longer available to new customers") {
35+
logrus.Info("MachineLearningBranchPrediction: AmazonML is no longer available to new customers. Ignore if you haven't set it up.")
36+
return nil, nil
37+
}
38+
}
2939
return nil, err
3040
}
3141

resources/mgn-jobs.go

+5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"github.com/aws/aws-sdk-go/aws/session"
66
"github.com/aws/aws-sdk-go/service/mgn"
77
"github.com/rebuy-de/aws-nuke/v2/pkg/types"
8+
"github.com/sirupsen/logrus"
89
)
910

1011
type MGNJob struct {
@@ -29,6 +30,10 @@ func ListMGNJobs(sess *session.Session) ([]Resource, error) {
2930
for {
3031
output, err := svc.DescribeJobs(params)
3132
if err != nil {
33+
if IsAWSError(err, mgn.ErrCodeUninitializedAccountException) {
34+
logrus.Info("MGNJob: Account not initialized for Application Migration Service. Ignore if you haven't set it up.")
35+
return nil, nil
36+
}
3237
return nil, err
3338
}
3439

resources/mgn-source_servers.go

+5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"github.com/aws/aws-sdk-go/aws/session"
66
"github.com/aws/aws-sdk-go/service/mgn"
77
"github.com/rebuy-de/aws-nuke/v2/pkg/types"
8+
"github.com/sirupsen/logrus"
89
)
910

1011
type MGNSourceServer struct {
@@ -29,6 +30,10 @@ func ListMGNSourceServers(sess *session.Session) ([]Resource, error) {
2930
for {
3031
output, err := svc.DescribeSourceServers(params)
3132
if err != nil {
33+
if IsAWSError(err, mgn.ErrCodeUninitializedAccountException) {
34+
logrus.Info("MGNSourceServer: Account not initialized for Application Migration Service. Ignore if you haven't set it up.")
35+
return nil, nil
36+
}
3237
return nil, err
3338
}
3439

0 commit comments

Comments
 (0)