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

Commit

Permalink
add Sagemaker NotebookInstanceLifecycleConfigs (#558)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
troyready and svenwltr authored Mar 30, 2021
1 parent 0b0f8d0 commit 86c01c2
Showing 1 changed file with 68 additions and 0 deletions.
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
}

0 comments on commit 86c01c2

Please sign in to comment.