From 86c01c225953707257c2eb4a7f523d6d1cc11c03 Mon Sep 17 00:00:00 2001 From: Troy Ready Date: Tue, 30 Mar 2021 01:06:52 -0700 Subject: [PATCH] add Sagemaker NotebookInstanceLifecycleConfigs (#558) * add Sagemaker NotebookInstanceLifecycleConfigs https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_ListNotebookInstanceLifecycleConfigs.html * add properties * shorten property name * Update resources/sagemaker-notebookinstancelifecycleconfigs.go Co-authored-by: Sven Walter --- ...emaker-notebookinstancelifecycleconfigs.go | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 resources/sagemaker-notebookinstancelifecycleconfigs.go diff --git a/resources/sagemaker-notebookinstancelifecycleconfigs.go b/resources/sagemaker-notebookinstancelifecycleconfigs.go new file mode 100644 index 000000000..044ca2044 --- /dev/null +++ b/resources/sagemaker-notebookinstancelifecycleconfigs.go @@ -0,0 +1,68 @@ +package resources + +import ( + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/aws/session" + "github.com/aws/aws-sdk-go/service/sagemaker" + "github.com/rebuy-de/aws-nuke/pkg/types" +) + +type SageMakerNotebookInstanceLifecycleConfig struct { + svc *sagemaker.SageMaker + Name *string +} + +func init() { + register("SageMakerNotebookInstanceLifecycleConfig", ListSageMakerNotebookInstanceLifecycleConfigs) +} + +func ListSageMakerNotebookInstanceLifecycleConfigs(sess *session.Session) ([]Resource, error) { + svc := sagemaker.New(sess) + resources := []Resource{} + + params := &sagemaker.ListNotebookInstanceLifecycleConfigsInput{ + MaxResults: aws.Int64(30), + } + + for { + resp, err := svc.ListNotebookInstanceLifecycleConfigs(params) + if err != nil { + return nil, err + } + + for _, lifecycleConfig := range resp.NotebookInstanceLifecycleConfigs { + resources = append(resources, &SageMakerNotebookInstanceLifecycleConfig{ + svc: svc, + Name: lifecycleConfig.NotebookInstanceLifecycleConfigName, + }) + } + + if resp.NextToken == nil { + break + } + + params.NextToken = resp.NextToken + } + + return resources, nil +} + +func (f *SageMakerNotebookInstanceLifecycleConfig) Remove() error { + + _, err := f.svc.DeleteNotebookInstanceLifecycleConfig(&sagemaker.DeleteNotebookInstanceLifecycleConfigInput{ + NotebookInstanceLifecycleConfigName: f.Name, + }) + + return err +} + +func (f *SageMakerNotebookInstanceLifecycleConfig) String() string { + return *f.Name +} + +func (f *SageMakerNotebookInstanceLifecycleConfig) Properties() types.Properties { + properties := types.NewProperties() + properties. + Set("Name", f.Name) + return properties +}