From 3d46846a5bb779796173d8518fdaa13e8653d69b Mon Sep 17 00:00:00 2001
From: Philipp Trulson
Date: Wed, 23 Aug 2023 17:25:48 +0200
Subject: [PATCH] Defuse unnecessary errors for unavailable services
---
resources/fms_notification_channels.go | 8 ++++++--
resources/fms_policies.go | 10 ++++++++++
resources/machinelearning-batchpredictions.go | 10 ++++++++++
resources/machinelearning-datasources.go | 10 ++++++++++
resources/machinelearning-evaluations.go | 10 ++++++++++
resources/machinelearning-mlmodels.go | 10 ++++++++++
resources/mgn-jobs.go | 5 +++++
resources/mgn-source_servers.go | 5 +++++
8 files changed, 66 insertions(+), 2 deletions(-)
diff --git a/resources/fms_notification_channels.go b/resources/fms_notification_channels.go
index f7a832d0d..9f70e7147 100644
--- a/resources/fms_notification_channels.go
+++ b/resources/fms_notification_channels.go
@@ -1,10 +1,13 @@
package resources
import (
+ "strings"
+
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/fms"
"github.com/rebuy-de/aws-nuke/v2/pkg/types"
+ "github.com/sirupsen/logrus"
)
type FMSNotificationChannel struct {
@@ -21,8 +24,9 @@ func ListFMSNotificationChannel(sess *session.Session) ([]Resource, error) {
if _, err := svc.GetNotificationChannel(&fms.GetNotificationChannelInput{}); err != nil {
if aerr, ok := err.(awserr.Error); ok {
- if aerr.Code() != fms.ErrCodeResourceNotFoundException {
- return nil, err
+ if strings.Contains(aerr.Message(), "No default admin could be found") {
+ logrus.Infof("FMSNotificationChannel: %s. Ignore if you haven't set it up.", aerr.Message())
+ return nil, nil
}
} else {
return nil, err
diff --git a/resources/fms_policies.go b/resources/fms_policies.go
index f369518a3..9e6176731 100644
--- a/resources/fms_policies.go
+++ b/resources/fms_policies.go
@@ -1,10 +1,14 @@
package resources
import (
+ "strings"
+
"github.com/aws/aws-sdk-go/aws"
+ "github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/fms"
"github.com/rebuy-de/aws-nuke/v2/pkg/types"
+ "github.com/sirupsen/logrus"
)
type FMSPolicy struct {
@@ -27,6 +31,12 @@ func ListFMSPolicies(sess *session.Session) ([]Resource, error) {
for {
resp, err := svc.ListPolicies(params)
if err != nil {
+ if aerr, ok := err.(awserr.Error); ok {
+ if strings.Contains(aerr.Message(), "No default admin could be found") {
+ logrus.Infof("FMSPolicy: %s. Ignore if you haven't set it up.", aerr.Message())
+ return nil, nil
+ }
+ }
return nil, err
}
diff --git a/resources/machinelearning-batchpredictions.go b/resources/machinelearning-batchpredictions.go
index 46c9977b8..f93627226 100644
--- a/resources/machinelearning-batchpredictions.go
+++ b/resources/machinelearning-batchpredictions.go
@@ -1,9 +1,13 @@
package resources
import (
+ "strings"
+
"github.com/aws/aws-sdk-go/aws"
+ "github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/machinelearning"
+ "github.com/sirupsen/logrus"
)
type MachineLearningBranchPrediction struct {
@@ -26,6 +30,12 @@ func ListMachineLearningBranchPredictions(sess *session.Session) ([]Resource, er
for {
output, err := svc.DescribeBatchPredictions(params)
if err != nil {
+ if aerr, ok := err.(awserr.Error); ok {
+ if strings.Contains(aerr.Message(), "AmazonML is no longer available to new customers") {
+ logrus.Info("MachineLearningBranchPrediction: AmazonML is no longer available to new customers. Ignore if you haven't set it up.")
+ return nil, nil
+ }
+ }
return nil, err
}
diff --git a/resources/machinelearning-datasources.go b/resources/machinelearning-datasources.go
index 3dfb84a46..0b7301567 100644
--- a/resources/machinelearning-datasources.go
+++ b/resources/machinelearning-datasources.go
@@ -1,9 +1,13 @@
package resources
import (
+ "strings"
+
"github.com/aws/aws-sdk-go/aws"
+ "github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/machinelearning"
+ "github.com/sirupsen/logrus"
)
type MachineLearningDataSource struct {
@@ -26,6 +30,12 @@ func ListMachineLearningDataSources(sess *session.Session) ([]Resource, error) {
for {
output, err := svc.DescribeDataSources(params)
if err != nil {
+ if aerr, ok := err.(awserr.Error); ok {
+ if strings.Contains(aerr.Message(), "AmazonML is no longer available to new customers") {
+ logrus.Info("MachineLearningBranchPrediction: AmazonML is no longer available to new customers. Ignore if you haven't set it up.")
+ return nil, nil
+ }
+ }
return nil, err
}
diff --git a/resources/machinelearning-evaluations.go b/resources/machinelearning-evaluations.go
index 6ef834089..7d307ac97 100644
--- a/resources/machinelearning-evaluations.go
+++ b/resources/machinelearning-evaluations.go
@@ -1,9 +1,13 @@
package resources
import (
+ "strings"
+
"github.com/aws/aws-sdk-go/aws"
+ "github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/machinelearning"
+ "github.com/sirupsen/logrus"
)
type MachineLearningEvaluation struct {
@@ -26,6 +30,12 @@ func ListMachineLearningEvaluations(sess *session.Session) ([]Resource, error) {
for {
output, err := svc.DescribeEvaluations(params)
if err != nil {
+ if aerr, ok := err.(awserr.Error); ok {
+ if strings.Contains(aerr.Message(), "AmazonML is no longer available to new customers") {
+ logrus.Info("MachineLearningBranchPrediction: AmazonML is no longer available to new customers. Ignore if you haven't set it up.")
+ return nil, nil
+ }
+ }
return nil, err
}
diff --git a/resources/machinelearning-mlmodels.go b/resources/machinelearning-mlmodels.go
index b223efd00..0bde5f748 100644
--- a/resources/machinelearning-mlmodels.go
+++ b/resources/machinelearning-mlmodels.go
@@ -1,9 +1,13 @@
package resources
import (
+ "strings"
+
"github.com/aws/aws-sdk-go/aws"
+ "github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/machinelearning"
+ "github.com/sirupsen/logrus"
)
type MachineLearningMLModel struct {
@@ -26,6 +30,12 @@ func ListMachineLearningMLModels(sess *session.Session) ([]Resource, error) {
for {
output, err := svc.DescribeMLModels(params)
if err != nil {
+ if aerr, ok := err.(awserr.Error); ok {
+ if strings.Contains(aerr.Message(), "AmazonML is no longer available to new customers") {
+ logrus.Info("MachineLearningBranchPrediction: AmazonML is no longer available to new customers. Ignore if you haven't set it up.")
+ return nil, nil
+ }
+ }
return nil, err
}
diff --git a/resources/mgn-jobs.go b/resources/mgn-jobs.go
index 2159b3c55..670d4c4c7 100644
--- a/resources/mgn-jobs.go
+++ b/resources/mgn-jobs.go
@@ -5,6 +5,7 @@ import (
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/mgn"
"github.com/rebuy-de/aws-nuke/v2/pkg/types"
+ "github.com/sirupsen/logrus"
)
type MGNJob struct {
@@ -29,6 +30,10 @@ func ListMGNJobs(sess *session.Session) ([]Resource, error) {
for {
output, err := svc.DescribeJobs(params)
if err != nil {
+ if IsAWSError(err, mgn.ErrCodeUninitializedAccountException) {
+ logrus.Info("MGNJob: Account not initialized for Application Migration Service. Ignore if you haven't set it up.")
+ return nil, nil
+ }
return nil, err
}
diff --git a/resources/mgn-source_servers.go b/resources/mgn-source_servers.go
index 706138a77..fe8404390 100644
--- a/resources/mgn-source_servers.go
+++ b/resources/mgn-source_servers.go
@@ -5,6 +5,7 @@ import (
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/mgn"
"github.com/rebuy-de/aws-nuke/v2/pkg/types"
+ "github.com/sirupsen/logrus"
)
type MGNSourceServer struct {
@@ -29,6 +30,10 @@ func ListMGNSourceServers(sess *session.Session) ([]Resource, error) {
for {
output, err := svc.DescribeSourceServers(params)
if err != nil {
+ if IsAWSError(err, mgn.ErrCodeUninitializedAccountException) {
+ logrus.Info("MGNSourceServer: Account not initialized for Application Migration Service. Ignore if you haven't set it up.")
+ return nil, nil
+ }
return nil, err
}