Created
September 29, 2020 10:50
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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