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

Commit

Permalink
Defuse unnecessary errors for unavailable services (#1083)
Browse files Browse the repository at this point in the history
  • Loading branch information
der-eismann authored Aug 23, 2023
1 parent 468e5e3 commit 158ca36
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 2 deletions.
8 changes: 6 additions & 2 deletions resources/fms_notification_channels.go
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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
Expand Down
10 changes: 10 additions & 0 deletions resources/fms_policies.go
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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
}

Expand Down
10 changes: 10 additions & 0 deletions resources/machinelearning-batchpredictions.go
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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
}

Expand Down
10 changes: 10 additions & 0 deletions resources/machinelearning-datasources.go
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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
}

Expand Down
10 changes: 10 additions & 0 deletions resources/machinelearning-evaluations.go
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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
}

Expand Down
10 changes: 10 additions & 0 deletions resources/machinelearning-mlmodels.go
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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
}

Expand Down
5 changes: 5 additions & 0 deletions resources/mgn-jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}

Expand Down
5 changes: 5 additions & 0 deletions resources/mgn-source_servers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}

Expand Down

0 comments on commit 158ca36

Please sign in to comment.