# SageMaker Usage through SDK (Boto3) This file documents an approach on a possible use case of Amazon SageMaker via an SDK. Information used is obtained from related AWS glossaries and documentations. ## Requirements A Software Development Kit (SDK) in the context of this task can be used to create, configure and manage AWS Services like SageMaker. Boto3 is the AWS SDK solution for python, which occurs to be highly suitable for ML purposes. Team B created a sample python project uploaded within Team B's git repository in the folder "SDK_Project." > [Link to the project folder](https://github.com/hochschule-pforzheim/aws-services-example-team-b/tree/main/SDK_Project) In order to get access to SageMaker via Boto3, the AWS CLI firstly needs to be configured for getting access to the respective AWS environment. For this configuration, the required connection setup is similar to the CLI scenario with the following code provided by AWS: ```shell= aws configure aws_access_key_id = AKIAV2MMYY7VG6G2H6UF aws_secret_access_key = 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 region=us-west-2 ``` > [Amazon Boto3 Documentation](https://boto3.amazonaws.com/v1/documentation/api/latest/guide/quickstart.html) For the execution of this sample project within local Visual Studio Code editor, the pyvenv.cfg file needs to be adjusted appropriately. For "home" it is required to enter the installation path of Python within the executing system. ```python= home = C:\Users\"USERNAME"\AppData\Local\Programs\Python\Python39 ``` Under circumstances, it might be necessary to change the Execution Policies within the python Terminal of Visual Studio Code: ```python= Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process ``` Furthermore, within the python Terminal of Visual Studio Code, it is required to execute the following code in order to being able to use Boto3: ```python= py -3 -m venv .venv .venv\scripts\activate python -m pip install boto3 ``` ## Typical Scenario Analogous to the CLI scenario, SageMaker Notebooks can be created and and executed via scripts. The following python code demonstrates this scenario using the Boto3 SDK in Visual Studio Code editor: ```python= import boto3 client = boto3.client('sagemaker') response = client.create_notebook_instance( NotebookInstanceName='SDKNotebookInstance', InstanceType='ml.t2.medium', RoleArn='arn:aws:iam::400264054762:role/SageMaker-Role', DirectInternetAccess='Enabled', Tags=[ { 'Key': 'Name', 'Value': 'Created through Boto3 SDK' }, ], VolumeSizeInGB=5, RootAccess='Enabled') ``` In order to display the existing Notebooks with their properties within the Visual Studio Code Terminal, the following python code can be executed: ```python= import boto3 client = boto3.client('sagemaker') response = client.list_notebook_instances() print(response) ``` As a result, the Visual Studio Code Terminal lists the Notebooks' properties as follows: ```json= (venv) PS C:\Users\IchHeißeMarvin\Desktop\Python> & c:/Users/IchHeißeMarvin/Desktop/Python/venv/Scripts/python.exe c:/Users/IchHeißeMarvin/Desktop/Python/venv/SDK_usage.py { "NotebookInstances": [ { "NotebookInstanceName": "SDKNotebookInstance", "NotebookInstanceArn": "arn:aws:sagemaker:us-west-2:400264054762:notebook-instance/sdknotebookinstance", "NotebookInstanceStatus": "InService", "Url": "sdknotebookinstance.notebook.us-west-2.sagemaker.aws", "InstanceType": "ml.t2.medium", "CreationTime": datetime.datetime(2021, 2, 8, 12, 33, 19, 940000, tzinfo=tzlocal()), "LastModifiedTime": datetime.datetime(2021, 2, 8, 12, 33, 26, 394000, tzinfo=tzlocal()), }, { "NotebookInstanceName": "CLINotebookInstance", "NotebookInstanceArn": "arn:aws:sagemaker:us-west-2:400264054762:notebook-instance/clinotebookinstance", "NotebookInstanceStatus": "InService", "Url": "clinotebookinstance-0acx.notebook.us-west-2.sagemaker.aws", "InstanceType": "ml.t2.medium", "CreationTime": "2021-02-08T12:14:28.565000+01:00", "LastModifiedTime": "2021-02-08T12:17:05.333000+01:00", "CreationTime": datetime.datetime(2021, 2, 8, 12, 14, 28, 565000, tzinfo=tzlocal()), "LastModifiedTime": datetime.datetime(2021, 2, 8, 12, 17, 5, 333000, tzinfo=tzlocal())}], "ResponseMetadata": {"RequestId": "30fe87cc-bb39-41f0-9437-1c05a9b86eff", "HTTPStatusCode": 200, "HTTPHeaders": {"x-amzn-requestid": "30fe87cc-bb39-41f0-9437-1c05a9b86eff", "content-type": "application/x-amz-json-1.1", "content-length": "717", "date": "Mon, 08 Feb 2021 11:34:08 GMT"}, "RetryAttempts": 0}} } ] } ``` Within the project folder "SDK_Project" in the Git repository of Group B, this sample python project is accessible and ready to execute in a local Visual Studio Code environment.