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

Defuse unnecessary errors for unavailable services #1083

Merged
merged 1 commit into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading