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

add Sagemaker NotebookInstanceLifecycleConfigs #558

Merged
merged 4 commits into from
Mar 30, 2021
Merged
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
68 changes: 68 additions & 0 deletions resources/sagemaker-notebookinstancelifecycleconfigs.go
Original file line number Diff line number Diff line change
@@ -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
}