Skip to content

Instantly share code, notes, and snippets.

@amalgjose
Created September 29, 2020 10:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save amalgjose/b317d763136fabab0b4be5d78e6b3fa6 to your computer and use it in GitHub Desktop.
Save amalgjose/b317d763136fabab0b4be5d78e6b3fa6 to your computer and use it in GitHub Desktop.
Python program to list all the details of AWS SageMaker Notebook instances running in an AWS account and exporting the data as a csv file.
import csv
import boto3
client = boto3.client('sagemaker', region_name='us-east-1')
response = client.list_notebook_instances(MaxResults=100)
notebooks = response['NotebookInstances']
print("Total Number of Notebook Instances ----->", len(notebooks))
notebook_list = []
for notebook in notebooks:
notebook_dict = dict()
notebook_dict['NotebookInstanceName'] = notebook['NotebookInstanceName']
notebook_dict['NotebookInstanceArn'] = notebook['NotebookInstanceArn']
notebook_dict['NotebookInstanceStatus'] = notebook['NotebookInstanceStatus']
notebook_dict['InstanceType'] = notebook['InstanceType']
notebook_list.append(notebook_dict)
print(notebook_list)
with open('notebook_instances.csv', 'w', encoding='utf8', newline='') as output_file:
fc = csv.DictWriter(output_file,
fieldnames=notebook_list[0].keys())
fc.writeheader()
fc.writerows(notebook_list)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment