Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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