Skip to content

Instantly share code, notes, and snippets.

@nov05
Last active December 6, 2024 01:30
Show Gist options
  • Save nov05/d9c3be6c2ab9f6c050e3d988830db08b to your computer and use it in GitHub Desktop.
Save nov05/d9c3be6c2ab9f6c050e3d988830db08b to your computer and use it in GitHub Desktop.
  • Local Install Requirements
Python 3.7
MXNet 1.8
Pandas >= 1.2.4
AutoGluon 0.2.0
  • 👉 create sagemaker base environment
conda create -n sagemaker_py310 python=3.10
conda activate sagemaker_py310
pip install boto3 awscli sagemaker
conda install -c conda-forge jupyterlab
python -m ipykernel install --user --name sagemaker_py310
aws configure
jupyter lab
  • 👉 create an environment cloned from the base environment
conda create --name awsmle_py310 --clone sagemaker_py310
python -m ipykernel install --user --name awsmle_py310
conda install -c conda-forge mamba  (having unicode file names issue) 
mamba install -c conda-forge autogluon (failed)  
conda install -c conda-forge mamba==1.4.7  
conda update conda
mamba install -c conda-forge autogluon  
mamba install -c conda-forge "ray-tune >=2.6.3,<2.7" "ray-default >=2.6.3,<2.7" 
pip install bokeh==2.0.1  
pip install kaggle
pip install ipywidgets
pip install ydata-profiling  
pip install smdebug
pip install jinja2==2.11.3
pip install markupsafe==2.0.1
pip install 'sagemaker[local]'
pip install sagemaker_inference
  • To run SageMaker in the local environment, add the following 3 keys to ~/.aws/credentials.
notepad C:\Users\*\.aws\credentials
(awsmle_py310) PS D:\github\udacity-nd009t-C2-Developing-ML-Workflow> cat ~/.aws/credentials
[default]
aws_access_key_id = <?>
aws_secret_access_key = <?>
aws_session_token = *vQ== <?>
## reset the session after updating credentials
import boto3
boto3.DEFAULT_SESSION = None

  • 👉 create an env with cuda enabled, torch and transformers installed.
conda create --name conda_py310 python=3.10  
conda activate conda_py310  
nvidia-smi
conda install cuda  --channel "nvidia/label/cuda-12.1.0"    
nvcc --version  
conda install pytorch torchvision torchaudio pytorch-cuda=12.1 -c pytorch -c nvidia  
pip install transformers
pip install pandas
pip install scikit-learn
conda install -c conda-forge ipywidgets
pip install wandb

  • docker commands
docker images
docker ps
  • Windows Powershell commands
conda deactivate
conda env remove --name awsmle_py37
  • install wsl-ubuntu
wsl --list --online 
wsl --install -d Ubuntu-22.04

install ubuntu, restart Windows OS
install Docker Desktop, restart Windows


  • Tips:
    • Choose the torch version according to the cuda version at https://pytorch.org/
    • Choose the MXNet version according to the cuda version at mxnet.apache.org.
      MXNet 1.8 does not officially support CUDA 12.x, as the latest version (MXNet 1.8) was designed for compatibility with CUDA versions up to 11.x. However, you can try using a previous version of CUDA (such as CUDA 11.0 or 10.2) to install MXNet 1.8 with GPU support.

  • Some output in the terminal
(awsmle_py37) PS D:\github\udacity-cd0385-exercise-files> nvidia-smi                                                                                      
Tue Nov 19 14:19:10 2024                                                                                                                                  
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 555.99                 Driver Version: 555.99         CUDA Version: 12.5     |                                                               
|-----------------------------------------+------------------------+----------------------+                                                               
| GPU  Name                  Driver-Model | Bus-Id          Disp.A | Volatile Uncorr. ECC |                                                               
| Fan  Temp   Perf          Pwr:Usage/Cap |           Memory-Usage | GPU-Util  Compute M. |                                                               
|                                         |                        |               MIG M. |                                                               
|=========================================+========================+======================|                                                               
|   0  NVIDIA GeForce GTX 1650 Ti   WDDM  |   00000000:01:00.0 Off |                  N/A |                                                               
| N/A   46C    P0             14W /   50W |       0MiB /   4096MiB |      0%      Default |                                                               
|                                         |                        |                  N/A |                                                               
+-----------------------------------------+------------------------+----------------------+                                                               
                                                                                                                                                          
+-----------------------------------------------------------------------------------------+                                                               
| Processes:                                                                              |
|  GPU   GI   CI        PID   Type   Process name                              GPU Memory |
|        ID   ID                                                               Usage      |
|=========================================================================================|
|  No running processes found                                                             |
+-----------------------------------------------------------------------------------------+
(awsmle_py37) PS D:\github\udacity-cd0385-exercise-files> nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2023 NVIDIA Corporation
Built on Wed_Feb__8_05:53:42_Coordinated_Universal_Time_2023
Cuda compilation tools, release 12.1, V12.1.66
Build cuda_12.1.r12.1/compiler.32415258_0
(awsmle_py37) PS D:\github\udacity-cd0385-exercise-files> python -m ipykernel install --user --name=awsmle_py37                         
Installed kernelspec awsmle_py37 in C:\Users\*\AppData\Roaming\jupyter\kernels\awsmle_py37  
(awsmle_py310) PS D:\github\udacity-cd0385-exercise-files> aws configure
AWS Access Key ID [****************HX33]: 
AWS Secret Access Key [****************HD5x]: 
Default region name [us-east-1]: us-east-1
Default output format [None]: json
@nov05
Copy link
Author

nov05 commented Nov 19, 2024

Support building source against CUDA 12.1 #21190
Open
kevnzhao opened this issue on Mar 27, 2023 · 5 comments
apache/mxnet#21190

@nov05
Copy link
Author

nov05 commented Nov 19, 2024

  • Failled to run pip install AutoGluon
conda create --name awsmle_py37 python=3.7  
conda activate awsmle_py37  
nvidia-smi
conda install cuda  --channel "nvidia/label/cuda-12.1.0"
nvcc --version  
conda install pytorch torchvision torchaudio pytorch-cuda=12.1 -c pytorch -c nvidia
conda install ipykernel
python -m ipykernel install --user --name=awsmle_py37  
pip install mxnet  
pip install pandas
D:\Users\*\miniconda3\envs\awsmle_py37\python.exe -m pip install --upgrade pip setuptools wheel 

@nov05
Copy link
Author

nov05 commented Nov 19, 2024

conda create --name awsmle_py310 python=3.10  
conda activate awsmle_py310  
D:\Users\*\miniconda3\envs\awsmle_py310\python.exe -m pip install --upgrade pip setuptools wheel   
  • failed to run any of the following
pip install mxnet==1.8.0.post0  
pip install mxnet==1.8.0  
conda install -c conda-forge mxnet=1.8.0  
pip install mxnet  

@nov05
Copy link
Author

nov05 commented Nov 19, 2024

conda create --name awsmle_py38 python=3.8    
conda activate awsmle_py38
  • failed to run any of the following
pip install mxnet==1.7.0.post2  
pip install mxnet  
conda install -c conda-forge mxnet 

@nov05
Copy link
Author

nov05 commented Nov 19, 2024

conda create --name awsmle_py37 python=3.7  
conda activate awsmle_py37   
pip install mxnet  
pip install pandas
  • failed to run pip install AutoGluon

(awsmle_py37) PS D:\github\udacity-cd0385-exercise-files> pip install mxnet
Collecting mxnet
  Using cached mxnet-1.7.0.post2-py2.py3-none-win_amd64.whl (33.1 MB)
Collecting requests<2.19.0,>=2.18.4
  Using cached requests-2.18.4-py2.py3-none-any.whl (88 kB)
Collecting graphviz<0.9.0,>=0.8.1
  Using cached graphviz-0.8.4-py2.py3-none-any.whl (16 kB)
Collecting numpy<1.17.0,>=1.8.2
  Using cached numpy-1.16.6-cp37-cp37m-win_amd64.whl (11.9 MB)
Collecting idna<2.7,>=2.5
  Using cached idna-2.6-py2.py3-none-any.whl (56 kB)
Requirement already satisfied: certifi>=2017.4.17 in d:\users\*\miniconda3\envs\awsmle_py37\lib\site-packages (from requests<2.19.0,>=2.18.4->mxnet) (2022.12.7)
Collecting urllib3<1.23,>=1.21.1
  Using cached urllib3-1.22-py2.py3-none-any.whl (132 kB)
Collecting chardet<3.1.0,>=3.0.2
  Using cached chardet-3.0.4-py2.py3-none-any.whl (133 kB)
Installing collected packages: urllib3, idna, chardet, requests, numpy, graphviz, mxnet
Successfully installed chardet-3.0.4 graphviz-0.8.4 idna-2.6 mxnet-1.7.0.post2 numpy-1.16.6 requests-2.18.4 urllib3-1.22
(awsmle_py37) PS D:\github\udacity-cd0385-exercise-files> pip install pandas
Collecting pandas
  Using cached pandas-1.3.5-cp37-cp37m-win_amd64.whl (10.0 MB)
Collecting python-dateutil>=2.7.3
  Downloading python_dateutil-2.9.0.post0-py2.py3-none-any.whl (229 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 229.9/229.9 kB 1.0 MB/s eta 0:00:00
Collecting pytz>=2017.3
  Using cached pytz-2024.2-py2.py3-none-any.whl (508 kB)
Collecting numpy>=1.17.3
  Using cached numpy-1.21.6-cp37-cp37m-win_amd64.whl (14.0 MB)
Collecting six>=1.5
  Using cached six-1.16.0-py2.py3-none-any.whl (11 kB)
Installing collected packages: pytz, six, numpy, python-dateutil, pandas
  Attempting uninstall: numpy
    Found existing installation: numpy 1.16.6
    Uninstalling numpy-1.16.6:
      Successfully uninstalled numpy-1.16.6
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
mxnet 1.7.0.post2 requires numpy<1.17.0,>=1.8.2, but you have numpy 1.21.6 which is incompatible.
Successfully installed numpy-1.21.6 pandas-1.3.5 python-dateutil-2.9.0.post0 pytz-2024.2 six-1.16.0

@nov05
Copy link
Author

nov05 commented Nov 19, 2024

  • failed to run
conda create --name awsmle_py37 python=3.7  
conda activate awsmle_py37    
D:\Users\*\miniconda3\envs\awsmle_py37\python.exe -m pip install --upgrade pip setuptools wheel  
pip install --use-pep517 mxnet pandas AutoGluon  

@nov05
Copy link
Author

nov05 commented Nov 19, 2024

  • failed to install autogluon
conda create -n awsmle_py39 python=3.9
conda activate awsmle_py39
conda install -c conda-forge cmake
cmake --version             (cmake version 3.29.4)
conda install -c conda-forge protobuf               (failed)
conda install -c conda-forge protobuf=3.13.0
protoc --version                (libprotoc 3.13.0)
pip install autogluon    (failed)   
pip install --use-pep517 autogluon (failed)

@nov05
Copy link
Author

nov05 commented Nov 19, 2024

conda create -n awsmle_py310 python=3.10  
conda activate awsmle_py310
conda install -c conda-forge mamba  (having unicode file names issue) 
mamba install -c conda-forge autogluon (failed)  
conda install -c conda-forge mamba==1.4.7  
conda update conda
mamba install -c conda-forge autogluon  
mamba install -c conda-forge "ray-tune >=2.6.3,<2.7" "ray-default >=2.6.3,<2.7"  
pip install mxnet pandas  (failed)  
conda install -c conda-forge mxnet pandas  (failed)

conda create -n ag python=3.10
conda activate ag
conda install -c conda-forge mamba
mamba install -c conda-forge autogluon
mamba install -c conda-forge "ray-tune >=2.6.3,<2.7" "ray-default >=2.6.3,<2.7"  # install ray for faster training
(awsmle_py310) PS D:\github\udacity-cd0385-exercise-files> mamba install -c conda-forge autogluon                                                          
conda-forge/noarch                                          Using cache                                                                                    
conda-forge/win-64                                          Using cache
critical libmamba [json.exception.parse_error.101] parse error at line 163, column 37: syntax error while parsing value - invalid string: ill-formed UTF-8'
  • mamba issue

JohanMabille on Jul 6, 2023
Mamba 1.4.7 has been released with a fix to this issue. It should be available on conda-forge soon.

@nov05
Copy link
Author

nov05 commented Nov 20, 2024

wsl --list --online 
wsl --install -d Ubuntu-22.04
  • restart Windows OS
  • install Docker Desktop, restart Windows
(drlnd_py310) PS D:\github\udacity-deep-reinforcement-learning\python> wsl --list
Windows Subsystem for Linux Distributions:
Ubuntu-22.04 (Default)
docker-desktop

https://github.com/aws/sagemaker-distribution

@nov05
Copy link
Author

nov05 commented Nov 20, 2024

Create custom images for geospatial analysis with Amazon SageMaker Distribution in Amazon SageMaker Studio
by Janosch Woschitz, Anirudh Viswanathan, and Karsten Schroer on 11 JUL 2024 in Advanced (300), Amazon SageMaker, Amazon SageMaker Studio, Architecture, Geospatial ML with Amazon SageMaker, Technical How-to Permalink

@nov05
Copy link
Author

nov05 commented Nov 21, 2024

Youtube, Setup a Local Development Environment for SageMaker
YouTube, Train and Deploy SageMaker model in your Local Machine

conda create -n sagemaker_py310 python=3.10
conda activate sagemaker_py310
pip install boto3 awscli sagemaker
conda install -c conda-forge jupyterlab
python -m ipykernel install --user --name sagemaker_py310
aws configure
jupyter lab
conda create --name awsmle_py310 --clone sagemaker_py310
docker images
docker ps

@nov05
Copy link
Author

nov05 commented Nov 21, 2024

aws s3api create-bucket --bucket s3://udacity-awsmle-20241121 --region us-east-1
aws s3 cp algorithms-and-tools\concept1_linear_models_exercise\starter\01_exercise_starter.ipynb s3://udacity-awsmle-20241121
An error occurred (InvalidAccessKeyId) when calling the CreateBucket operation: The AWS Access Key Id you provided does not exist in our records. 

@nov05
Copy link
Author

nov05 commented Nov 24, 2024

  • add profile in a wrong way
(awsmle_py310) PS D:\github\udacity-nd009t-C2-Developing-ML-Workflow> aws configure list
      Name                    Value             Type    Location
      ----                    -----             ----    --------
   profile                <not set>             None    None
access_key     ****************KDV4 shared-credentials-file
secret_key     ****************U4jB shared-credentials-file
    region                us-east-1      config-file    ~/.aws/config
(awsmle_py310) PS D:\github\udacity-nd009t-C2-Developing-ML-Workflow> $env:AWS_PROFILE="awsmle_py310"
(awsmle_py310) PS D:\github\udacity-nd009t-C2-Developing-ML-Workflow> aws configure list
      Name                    Value             Type    Location
      ----                    -----             ----    --------
   profile             awsmle_py310              env    ['AWS_DEFAULT_PROFILE', 'AWS_PROFILE']

The config profile (awsmle_py310) could not be found
  • remove the "profile"
(awsmle_py310) PS D:\github\udacity-nd009t-C2-Developing-ML-Workflow> $env:AWS_PROFILE=""
  • display credentials. ~ here means user root path, in windows it is usually C:\Users\<username>\.aws. add aws_session_token in the ~/.aws/credentials file.
(awsmle_py310) PS D:\github\udacity-nd009t-C2-Developing-ML-Workflow> cat ~/.aws/credentials
[default]
aws_access_key_id = *KDV4
aws_secret_access_key = *U4jB
aws_session_token = *vQ==

@nov05
Copy link
Author

nov05 commented Nov 24, 2024

  • in the local environment (off AWS), manually specify the role ARN. or you will get the voclabs role.
import sagemaker # type: ignore
from sagemaker import get_execution_role # type: ignore
from sagemaker.session import Session # type: ignore

# role = get_execution_role()  ## get role ARN
# print("Role ARN:", role) ## Role ARN: arn:aws:iam::807711953667:role/voclabs
role = "arn:aws:iam::807711953667:role/service-role/AmazonSageMaker-ExecutionRole-20241121T213663"
session = sagemaker.Session()
region = session.boto_region_name
# bucket = session.default_bucket()
bucket = "sagemaker-studio-807711953667-mmx0am1bt28"
  • role voclabs
(awsmle_py310) PS D:\github\udacity-nd009t-C2-Developing-ML-Workflow> aws iam list-roles 
{  
    "Roles": [
        {
            "Path": "/service-role/",
            "RoleName": "AmazonSageMaker-ExecutionRole-20241121T213663",
            "RoleId": "AROA3YD3CKMBT62QJY7IR",
            "Arn": "arn:aws:iam::807711953667:role/service-role/AmazonSageMaker-ExecutionRole-20241121T213663",
            "CreateDate": "2024-11-22T03:36:32Z",
            "AssumeRolePolicyDocument": {
                "Version": "2012-10-17",
                "Statement": [
                    {
                        "Effect": "Allow",
                        "Principal": {
                            "Service": "sagemaker.amazonaws.com"
                        },
                        "Action": "sts:AssumeRole"
                    }
                ]
            },
            "Description": "SageMaker execution role created from the SageMaker AWS Management Console.",
            "MaxSessionDuration": 3600
        },
        {
            "Path": "/service-role/",
            "RoleName": "AmazonSageMaker-ExecutionRole-20241122T021889",
            "RoleId": "AROA3YD3CKMB7TVHCGUZB",
            "Arn": "arn:aws:iam::807711953667:role/service-role/AmazonSageMaker-ExecutionRole-20241122T021889",
            "CreateDate": "2024-11-22T08:18:47Z",
            "AssumeRolePolicyDocument": {
                "Version": "2012-10-17",
                "Statement": [
                    {
                        "Effect": "Allow",
                        "Principal": {
                            "Service": "sagemaker.amazonaws.com"
                        },
                        "Action": "sts:AssumeRole"
                    }
                ]
            },
            "Description": "SageMaker execution role created from the SageMaker AWS Management Console.",
            "MaxSessionDuration": 3600
        },
        {
            "Path": "/service-role/",
            "RoleName": "AmazonSagemakerCanvasBedrockRole-20241121T213661",
            "RoleId": "AROA3YD3CKMBSNVLDAGZY",
            "Arn": "arn:aws:iam::807711953667:role/service-role/AmazonSagemakerCanvasBedrockRole-20241121T213661",
            "CreateDate": "2024-11-22T03:36:35Z",
            "AssumeRolePolicyDocument": {
                "Version": "2012-10-17",
                "Statement": [
                    {
                        "Sid": "BedrockAssumeRole",
                        "Effect": "Allow",
                        "Principal": {
                            "Service": "bedrock.amazonaws.com"
                        },
                        "Action": "sts:AssumeRole",
                        "Condition": {
                            "StringEquals": {
                                "aws:SourceAccount": "807711953667"
                            }
                        }
                    }
                ]
            },
            "MaxSessionDuration": 3600
        },
        {
            "Path": "/service-role/",
            "RoleName": "AmazonSagemakerCanvasBedrockRole-20241122T021889",
            "RoleId": "AROA3YD3CKMBSKPE6ZNKB",
            "Arn": "arn:aws:iam::807711953667:role/service-role/AmazonSagemakerCanvasBedrockRole-20241122T021889",
            "CreateDate": "2024-11-22T08:18:49Z",
            "AssumeRolePolicyDocument": {
                "Version": "2012-10-17",
                "Statement": [
                    {
                        "Sid": "BedrockAssumeRole",
                        "Effect": "Allow",
                        "Principal": {
                            "Service": "bedrock.amazonaws.com"
                        },
                        "Action": "sts:AssumeRole",
                        "Condition": {
                            "StringEquals": {
                                "aws:SourceAccount": "807711953667"
                            }
                        }
                    }
                ]
            },
            "MaxSessionDuration": 3600
        },
        {
            "Path": "/service-role/",
            "RoleName": "AmazonSageMakerCanvasEMRSExecutionAccess-20241121T213661",
            "RoleId": "AROA3YD3CKMBXIDTFHPVM",
            "Arn": "arn:aws:iam::807711953667:role/service-role/AmazonSageMakerCanvasEMRSExecutionAccess-20241121T213661",
            "CreateDate": "2024-11-22T03:36:37Z",
            "AssumeRolePolicyDocument": {
                "Version": "2012-10-17",
                "Statement": [
                    {
                        "Sid": "EMRServerlessTrustPolicy",
                        "Effect": "Allow",
                        "Principal": {
                            "Service": "emr-serverless.amazonaws.com"
                        },
                        "Action": "sts:AssumeRole",
                        "Condition": {
                            "StringEquals": {
                                "aws:SourceAccount": "807711953667"
                            }
                        }
                    }
                ]
            },
            "MaxSessionDuration": 3600
        },
        {
            "Path": "/service-role/",
            "RoleName": "AmazonSageMakerCanvasEMRSExecutionAccess-20241122T021889",
            "RoleId": "AROA3YD3CKMB75BK6CX3P",
            "Arn": "arn:aws:iam::807711953667:role/service-role/AmazonSageMakerCanvasEMRSExecutionAccess-20241122T021889",
            "CreateDate": "2024-11-22T08:18:51Z",
            "AssumeRolePolicyDocument": {
                "Version": "2012-10-17",
                "Statement": [
                    {
                        "Sid": "EMRServerlessTrustPolicy",
                        "Effect": "Allow",
                        "Principal": {
                            "Service": "emr-serverless.amazonaws.com"
                        },
                        "Action": "sts:AssumeRole",
                        "Condition": {
                            "StringEquals": {
                                "aws:SourceAccount": "807711953667"
                            }
                        }
                    }
                ]
            },
            "MaxSessionDuration": 3600
        },
        {
            "Path": "/service-role/",
            "RoleName": "AmazonSagemakerCanvasForecastRole-20241121T213661",
            "RoleId": "AROA3YD3CKMB5G7LAOPYJ",
            "Arn": "arn:aws:iam::807711953667:role/service-role/AmazonSagemakerCanvasForecastRole-20241121T213661",
            "CreateDate": "2024-11-22T03:36:33Z",
            "AssumeRolePolicyDocument": {
                "Version": "2012-10-17",
                "Statement": [
                    {
                        "Effect": "Allow",
                        "Principal": {
                            "Service": "forecast.amazonaws.com"
                        },
                        "Action": "sts:AssumeRole"
                    }
                ]
            },
            "MaxSessionDuration": 3600
        },
        {
            "Path": "/service-role/",
            "RoleName": "AmazonSagemakerCanvasForecastRole-20241122T021889",
            "RoleId": "AROA3YD3CKMBQZYPU4LUS",
            "Arn": "arn:aws:iam::807711953667:role/service-role/AmazonSagemakerCanvasForecastRole-20241122T021889",
            "CreateDate": "2024-11-22T08:18:48Z",
            "AssumeRolePolicyDocument": {
                "Version": "2012-10-17",
                "Statement": [
                    {
                        "Effect": "Allow",
                        "Principal": {
                            "Service": "forecast.amazonaws.com"
                        },
                        "Action": "sts:AssumeRole"
                    }
                ]
            },
            "MaxSessionDuration": 3600
        },
        {
            "Path": "/aws-service-role/ops.emr-serverless.amazonaws.com/",
            "RoleName": "AWSServiceRoleForAmazonEMRServerless",
            "RoleId": "AROA3YD3CKMBTK7VOQVDN",
            "Arn": "arn:aws:iam::807711953667:role/aws-service-role/ops.emr-serverless.amazonaws.com/AWSServiceRoleForAmazonEMRServerless",
            "CreateDate": "2024-11-22T03:36:37Z",
            "AssumeRolePolicyDocument": {
                "Version": "2012-10-17",
                "Statement": [
                    {
                        "Effect": "Allow",
                        "Principal": {
                            "Service": "ops.emr-serverless.amazonaws.com"
                        },
                        "Action": "sts:AssumeRole"
                    }
                ]
            },
            "MaxSessionDuration": 3600
        },
        {
            "Path": "/aws-service-role/sagemaker.amazonaws.com/",
            "RoleName": "AWSServiceRoleForAmazonSageMakerNotebooks",
            "RoleId": "AROA3YD3CKMB5UERRULHW",
            "Arn": "arn:aws:iam::807711953667:role/aws-service-role/sagemaker.amazonaws.com/AWSServiceRoleForAmazonSageMakerNotebooks",
            "CreateDate": "2024-11-22T03:38:33Z",
            "AssumeRolePolicyDocument": {
                "Version": "2012-10-17",
                "Statement": [
                    {
                        "Effect": "Allow",
                        "Principal": {
                            "Service": "sagemaker.amazonaws.com"
                        },
                        "Action": "sts:AssumeRole"
                    }
                ]
            },
            "Description": "AWS SageMaker Notebooks Service Linked Role",
            "MaxSessionDuration": 3600
        },
        {
            "Path": "/aws-service-role/sagemaker.application-autoscaling.amazonaws.com/",
            "RoleName": "AWSServiceRoleForApplicationAutoScaling_SageMakerEndpoint",
            "RoleId": "AROA3YD3CKMB3SIGPHOC7",
            "Arn": "arn:aws:iam::807711953667:role/aws-service-role/sagemaker.application-autoscaling.amazonaws.com/AWSServiceRoleForApplicationAutoScaling_SageMakerEndpoint",
            "CreateDate": "2023-03-15T19:16:33Z",
            "AssumeRolePolicyDocument": {
                "Version": "2012-10-17",
                "Statement": [
                    {
                        "Effect": "Allow",
                        "Principal": {
                            "Service": "sagemaker.application-autoscaling.amazonaws.com"
                        },
                        "Action": "sts:AssumeRole"
                    }
                ]
            },
            "MaxSessionDuration": 3600
        },
        {
            "Path": "/aws-service-role/cloud9.amazonaws.com/",
            "RoleName": "AWSServiceRoleForAWSCloud9",
            "RoleId": "AROA3YD3CKMBQQNO3NRPA",
            "Arn": "arn:aws:iam::807711953667:role/aws-service-role/cloud9.amazonaws.com/AWSServiceRoleForAWSCloud9",
            "CreateDate": "2021-02-13T00:18:46Z",
            "AssumeRolePolicyDocument": {
                "Version": "2012-10-17",
                "Statement": [
                    {
                        "Effect": "Allow",
                        "Principal": {
                            "Service": "cloud9.amazonaws.com"
                        },
                        "Action": "sts:AssumeRole"
                    }
                ]
            },
            "MaxSessionDuration": 3600
        },
        {
            "Path": "/aws-service-role/events.amazonaws.com/",
            "RoleName": "AWSServiceRoleForCloudWatchEvents",
            "RoleId": "AROA3YD3CKMBSKIBMU2PB",
            "Arn": "arn:aws:iam::807711953667:role/aws-service-role/events.amazonaws.com/AWSServiceRoleForCloudWatchEvents",
            "CreateDate": "2021-02-13T00:18:45Z",
            "AssumeRolePolicyDocument": {
                "Version": "2012-10-17",
                "Statement": [
                    {
                        "Effect": "Allow",
                        "Principal": {
                            "Service": "events.amazonaws.com"
                        },
                        "Action": "sts:AssumeRole"
                    }
                ]
            },
            "MaxSessionDuration": 3600
        },
        {
            "Path": "/aws-service-role/elasticache.amazonaws.com/",
            "RoleName": "AWSServiceRoleForElastiCache",
            "RoleId": "AROA3YD3CKMB7MLEFUC6Q",
            "Arn": "arn:aws:iam::807711953667:role/aws-service-role/elasticache.amazonaws.com/AWSServiceRoleForElastiCache",
            "CreateDate": "2021-02-13T00:18:44Z",
            "AssumeRolePolicyDocument": {
                "Version": "2012-10-17",
                "Statement": [
                    {
                        "Effect": "Allow",
                        "Principal": {
                            "Service": "elasticache.amazonaws.com"
                        },
                        "Action": "sts:AssumeRole"
                    }
                ]
            },
            "MaxSessionDuration": 3600
        },
        {
            "Path": "/aws-service-role/globalaccelerator.amazonaws.com/",
            "RoleName": "AWSServiceRoleForGlobalAccelerator",
            "RoleId": "AROA3YD3CKMB5HNFDPBEC",
            "Arn": "arn:aws:iam::807711953667:role/aws-service-role/globalaccelerator.amazonaws.com/AWSServiceRoleForGlobalAccelerator",
            "CreateDate": "2021-12-29T18:14:51Z",
            "AssumeRolePolicyDocument": {
                "Version": "2012-10-17",
                "Statement": [
                    {
                        "Effect": "Allow",
                        "Principal": {
                            "Service": "globalaccelerator.amazonaws.com"
                        },
                        "Action": "sts:AssumeRole"
                    }
                ]
            },
            "Description": "Allows Global Accelerator to call AWS services on customer's behalf",
            "MaxSessionDuration": 3600
        },
        {
            "Path": "/aws-service-role/organizations.amazonaws.com/",
            "RoleName": "AWSServiceRoleForOrganizations",
            "RoleId": "AROA3YD3CKMBWS6G7772C",
            "Arn": "arn:aws:iam::807711953667:role/aws-service-role/organizations.amazonaws.com/AWSServiceRoleForOrganizations",
            "CreateDate": "2021-02-13T00:17:33Z",
            "AssumeRolePolicyDocument": {
                "Version": "2012-10-17",
                "Statement": [
                    {
                        "Effect": "Allow",
                        "Principal": {
                            "Service": "organizations.amazonaws.com"
                        },
                        "Action": "sts:AssumeRole"
                    }
                ]
            },
            "Description": "Service-linked role used by AWS Organizations to enable integration of other AWS services with Organizations.",
            "MaxSessionDuration": 3600
        },
        {
            "Path": "/aws-service-role/servicequotas.amazonaws.com/",
            "RoleName": "AWSServiceRoleForServiceQuotas",
            "RoleId": "AROA3YD3CKMB3LLQVG3G5",
            "Arn": "arn:aws:iam::807711953667:role/aws-service-role/servicequotas.amazonaws.com/AWSServiceRoleForServiceQuotas",
            "CreateDate": "2022-07-08T01:46:50Z",
            "AssumeRolePolicyDocument": {
                "Version": "2012-10-17",
                "Statement": [
                    {
                        "Effect": "Allow",
                        "Principal": {
                            "Service": "servicequotas.amazonaws.com"
                        },
                        "Action": "sts:AssumeRole"
                    }
                ]
            },
            "Description": "A service-linked role is required for Service Quotas to access your service limits.",
            "MaxSessionDuration": 3600
        },
        {
            "Path": "/aws-service-role/support.amazonaws.com/",
            "RoleName": "AWSServiceRoleForSupport",
            "RoleId": "AROA3YD3CKMB7FSSHYAWY",
            "Arn": "arn:aws:iam::807711953667:role/aws-service-role/support.amazonaws.com/AWSServiceRoleForSupport",
            "CreateDate": "2021-02-13T00:17:32Z",
            "AssumeRolePolicyDocument": {
                "Version": "2012-10-17",
                "Statement": [
                    {
                        "Effect": "Allow",
                        "Principal": {
                            "Service": "support.amazonaws.com"
                        },
                        "Action": "sts:AssumeRole"
                    }
                ]
            },
            "Description": "Enables resource access for AWS to provide billing, administrative and support services",
            "MaxSessionDuration": 3600
        },
        {
            "Path": "/aws-service-role/trustedadvisor.amazonaws.com/",
            "RoleName": "AWSServiceRoleForTrustedAdvisor",
            "RoleId": "AROA3YD3CKMBSCH4YQQGF",
            "Arn": "arn:aws:iam::807711953667:role/aws-service-role/trustedadvisor.amazonaws.com/AWSServiceRoleForTrustedAdvisor",
            "CreateDate": "2021-02-13T00:17:32Z",
            "AssumeRolePolicyDocument": {
                "Version": "2012-10-17",
                "Statement": [
                    {
                        "Effect": "Allow",
                        "Principal": {
                            "Service": "trustedadvisor.amazonaws.com"
                        },
                        "Action": "sts:AssumeRole"
                    }
                ]
            },
            "Description": "Access for the AWS Trusted Advisor Service to help reduce cost, increase performance, and improve security of your AWS environment.",
            "MaxSessionDuration": 3600
        },
        {
            "Path": "/",
            "RoleName": "EMR_AutoScaling_DefaultRole",
            "RoleId": "AROA3YD3CKMBWXZWXQKOE",
            "Arn": "arn:aws:iam::807711953667:role/EMR_AutoScaling_DefaultRole",
            "CreateDate": "2024-08-06T22:29:28Z",
            "AssumeRolePolicyDocument": {
                "Version": "2008-10-17",
                "Statement": [
                    {
                        "Sid": "",
                        "Effect": "Allow",
                        "Principal": {
                            "Service": [
                                "application-autoscaling.amazonaws.com",
                                "elasticmapreduce.amazonaws.com"
                            ]
                        },
                        "Action": "sts:AssumeRole"
                    }
                ]
            },
            "MaxSessionDuration": 3600
        },
        {
            "Path": "/",
            "RoleName": "EMR_DefaultRole",
            "RoleId": "AROA3YD3CKMB2UVNX6ZWC",
            "Arn": "arn:aws:iam::807711953667:role/EMR_DefaultRole",
            "CreateDate": "2024-08-06T22:29:20Z",
            "AssumeRolePolicyDocument": {
                "Version": "2008-10-17",
                "Statement": [
                    {
                        "Sid": "",
                        "Effect": "Allow",
                        "Principal": {
                            "Service": "elasticmapreduce.amazonaws.com"
                        },
                        "Action": "sts:AssumeRole"
                    }
                ]
            },
            "MaxSessionDuration": 3600
        },
        {
            "Path": "/",
            "RoleName": "EMR_EC2_DefaultRole",
            "RoleId": "AROA3YD3CKMB7AEHGQGVZ",
            "Arn": "arn:aws:iam::807711953667:role/EMR_EC2_DefaultRole",
            "CreateDate": "2024-08-06T22:29:12Z",
            "AssumeRolePolicyDocument": {
                "Version": "2008-10-17",
                "Statement": [
                    {
                        "Sid": "",
                        "Effect": "Allow",
                        "Principal": {
                            "Service": "ec2.amazonaws.com"
                        },
                        "Action": "sts:AssumeRole"
                    }
                ]
            },
            "MaxSessionDuration": 3600
        },
        {
            "Path": "/",
            "RoleName": "udacity_lambda_20241122",
            "RoleId": "AROA3YD3CKMBV34DVLJBB",
            "Arn": "arn:aws:iam::807711953667:role/udacity_lambda_20241122",
            "CreateDate": "2024-11-22T19:44:14Z",
            "AssumeRolePolicyDocument": {
                "Version": "2012-10-17",
                "Statement": [
                    {
                        "Effect": "Allow",
                        "Principal": {
                            "Service": "lambda.amazonaws.com"
                        },
                        "Action": "sts:AssumeRole"
                    }
                ]
            },
            "Description": "Udacity AWS MLE, S3 read/write access",
            "MaxSessionDuration": 3600
        },
        {
            "Path": "/",
            "RoleName": "udacity_lambda_step_20241124",
            "RoleId": "AROA3YD3CKMBRPZPLSU3J",
            "Arn": "arn:aws:iam::807711953667:role/udacity_lambda_step_20241124",
            "CreateDate": "2024-11-24T08:34:43Z",
            "AssumeRolePolicyDocument": {
                "Version": "2012-10-17",
                "Statement": [
                    {
                        "Effect": "Allow",
                        "Principal": {
                            "Service": "lambda.amazonaws.com"
                        },
                        "Action": "sts:AssumeRole"
                    }
                ]
            },
            "Description": "Allows Lambda functions to call AWS Step Functions on your behalf.",
            "MaxSessionDuration": 3600
        },
        {
            "Path": "/",
            "RoleName": "udacity_step_20241123",
            "RoleId": "AROA3YD3CKMBSERU5MWOU",
            "Arn": "arn:aws:iam::807711953667:role/udacity_step_20241123",
            "CreateDate": "2024-11-23T18:26:36Z",
            "AssumeRolePolicyDocument": {
                "Version": "2012-10-17",
                "Statement": [
                    {
                        "Sid": "",
                        "Effect": "Allow",
                        "Principal": {
                            "Service": "states.amazonaws.com"
                        },
                        "Action": "sts:AssumeRole"
                    }
                ]
            },
            "Description": "Allows Step Functions to access AWS resources on your behalf.",
            "MaxSessionDuration": 3600
        },
        {
            "Path": "/",
            "RoleName": "vocareum",
            "RoleId": "AROA3YD3CKMB5SWDT4C6Z",
            "Arn": "arn:aws:iam::807711953667:role/vocareum",
            "CreateDate": "2021-02-13T00:17:32Z",
            "AssumeRolePolicyDocument": {
                "Version": "2012-10-17",
                "Statement": [
                    {
                        "Effect": "Allow",
                        "Principal": {
                            "AWS": "arn:aws:iam::137949000194:root"
                        },
                        "Action": "sts:AssumeRole"
                    }
                ]
            },
            "MaxSessionDuration": 43200
        },
        {
            "Path": "/",
            "RoleName": "vocareum-eventbridge",
            "RoleId": "AROA3YD3CKMB2TYBCC53L",
            "Arn": "arn:aws:iam::807711953667:role/vocareum-eventbridge",
            "CreateDate": "2024-08-06T22:28:21Z",
            "AssumeRolePolicyDocument": {
                "Version": "2012-10-17",
                "Statement": [
                    {
                        "Effect": "Allow",
                        "Principal": {
                            "Service": "events.amazonaws.com"
                        },
                        "Action": "sts:AssumeRole"
                    }
                ]
            },
            "MaxSessionDuration": 3600
        },
        {
            "Path": "/",
            "RoleName": "voclabs",
            "RoleId": "AROA3YD3CKMB35VO2XJRP",
            "Arn": "arn:aws:iam::807711953667:role/voclabs",
            "CreateDate": "2024-08-06T22:29:05Z",
            "AssumeRolePolicyDocument": {
                "Version": "2012-10-17",
                "Statement": [
                    {
                        "Effect": "Allow",
                        "Principal": {
                            "AWS": [
                                "arn:aws:iam::137949000194:root",
                                "arn:aws:iam::117530877863:root"
                            ]
                        },
                        "Action": "sts:AssumeRole"
                    }
                ]
            },
            "MaxSessionDuration": 43200
        }
    ]
}

@nov05
Copy link
Author

nov05 commented Nov 26, 2024

  • create SageMaker layer for Lambda functions

$ aws lambda publish-layer-version --layer-name sagemaker-layer --zip-file fileb://sagemaker-layer.zip

(awsmle_py310) PS D:\github\udacity-nd009t-C2-Developing-ML-Workflow> aws lambda publish-layer-version --layer-name sagemaker-layer --zip-file fileb://sagemaker-layer.zip
{
    "Content": {
        "Location": "https://prod-04-2014-layers.s3.us-east-1.amazonaws.com/snapshots/807711953667/sagemaker-layer-916c77e6-f7a3-4dc7-bd1e-6dd9ab5a7321?versionId=UK7HYuxaBN5A8VPVcGeaeQxV2Oq7L_l2&X-Amz-Security-Token=IQoJb3JpZ2luX2VjEIH%2F%2F%2F%2F%2F%2F%2F%2F%2F%2FwEaCXVzLWVhc3QtMSJGMEQCICbHuLXtZzox%2FDcD4W4FHt%2Bw5qg9VGSqfVC%2F3GTAL3d1AiAXZvwluvZCcP8iBvHoBGcQ1cbNpBJUZok%2Fw5967G38USqyBQgqEAAaDDc0OTY3ODkwMjgzOSIMdkhZWaLZtPPbTpC%2BKo8F0sefAeW7pzE%2B5asbi38Bi2Pt4oJtbFUDAxNVpRyuUqlvjj1w6VTHseFnkkERCAZZ%2BHyCN1vQtJ9fVYvmlM%2FMKibMA6MGMKYn7XTSaNRzQu21MdLaGyNFW84Jx0yO2wUe2cumqDP3aJJpCMsdyt2M5is8YQPjaYZqzYw9Fyd42zll3bpps0F%2BtG592AjRX%2FFg9vuGfCqYe6gr1JtH1A3Jqa%2BLsPuKeA0xnVzw5HVU8O%2F3dfhMkKDf2wLqwR0a2bt9SMUlwXs3X%2BzeIcelXHZUNPvvullyA2Bvr2MTxLZGoFXd84An5GrX93IdL0RIboIyz7Ds0wrEJtvuCsJ2ZDp83qGbSGTjD6ToK1HLlh570kjPpAcLerth1PEovUcT4201vRPOoxj%2FGmkKLJAmFyiE3iuBNts6ylqZVWmWQdo%2BOXGL1aLLO64j7Bpwkrwf32zijjWbEUZnqGoPsWQWNIJ4wMaRYvu19Lpr5Zbtg78XNIu0Y4PnysnrrrhuKSg1oZp6uYlr1l5WjV3ydKqlHW0SKR1LXZgWqPDKNjUKnTxYARQMEtXdnruw1aES%2Bg7HmYy6mZiPQWrnzyVrMp%2BrfF6KC%2FO8PcmeXXAvuXZ3Wo38ZomwwxAwFxnnAWW%2FH4n6dHC8M5uqlNaoY%2ByV5ChyPVXFTdFwlq1dT0Re4Qk%2BshdmP7DlZYJFUKrl4mwreEH%2BKvdig3b0VqFS3CKUs3Mr%2Fts1q17SuxusvpuTt%2BQBimdnAaYh6CUq5TGRBZTKcaey6hU7S8X9oYRKtJEaLsuCXZg9YaynNZitRa8veKyKGrjIqvXKxLrruXWzDO%2BZCgWg5lhpTqr69BTfi6Aw%2BlUL3lpZlEYLAWeQ2FEPnLEWwf%2Bc3TDrj5a6BjqyARy7W%2BSkE9n4njhF3A%2FBNSVofyRQl42nAxlpgYpymJU%2FjPrm8C00AWHYKmnVPhh9M21C9txV7GQ910cuCzjYr1B8uSZ4aZjnT8JO7RHBOBI%2BQUjV3ypw6QlR%2BDGC1u%2Bq5HU5AEeCxuFB111K3C6LslwAjI7xuJARUj7uZg4HdsRpM72c3njPNsN15QwIs1DzVUSmLv7E7PJqDyqwQF51sU5xoHlz2%2B5KNSo6RQQ7nwcgy0w%3D&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20241126T093338Z&X-Amz-SignedHeaders=host&X-Amz-Expires=600&X-Amz-Credential=ASIA25DCYHY36QN2DDF6%2F20241126%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Signature=c023271972d4fb4ca92c53c8b2b4e81a865183c3f1cc75487ae073993cb2357e",
        "CodeSha256": "ofdERd8h+eJmzGuSAI3OalGpKE8OI5wqUF8HEBCy8Pc=",
        "CodeSize": 4406191
    },
    "LayerArn": "arn:aws:lambda:us-east-1:807711953667:layer:sagemaker-layer",
    "LayerVersionArn": "arn:aws:lambda:us-east-1:807711953667:layer:sagemaker-layer:1",
    "Description": "",
    "CreatedDate": "2024-11-26T09:33:42.626+0000",
    "Version": 1
}

@nov05
Copy link
Author

nov05 commented Nov 26, 2024

  • create a layer for lambda
  • lambda is using python 3.13
  • create a new local env. install sagemaker.
  • remove win32 files. rolled back to jsonschema==4.17.3.
  • go to the site-packages folder, to package all the files there into a ZIP file.
  • upload the ZIP file with aws cli command to create a layer (the ZIP file has a size of 99MB)
  • include the layer in the lambda function
conda create --name sagemaker_py313 python=3.13
conda activate sagemaker_py313
pip install sagemaker  
pip uninstall jsonschema
pip install jsonschema==4.17.3
aws lambda publish-layer-version --layer-name sagemaker-layer --zip-file fileb://python.zip    <- for small zip files
  • for large zip files, upload them to s3 first, then add or update layers from s3 files.
aws lambda publish-layer-version \
  --layer-name sagemaker-layer \
  --content S3Bucket=sagemaker-studio-807711953667-mmx0am1bt28,S3Key=python/sagemaker-layer.zip \
  --compatible-runtimes python3.13 \
  --description "SageMaker Layer"
  • exclude if possible
The following NEW packages will be INSTALLED:

  bzip2              pkgs/main/win-64::bzip2-1.0.8-h2bbff1b_6 
  ca-certificates    pkgs/main/win-64::ca-certificates-2024.9.24-haa95532_0 
  expat              pkgs/main/win-64::expat-2.6.3-h5da7b33_0 
  libffi             pkgs/main/win-64::libffi-3.4.4-hd77b12b_1 
  libmpdec           pkgs/main/win-64::libmpdec-4.0.0-h827c3e9_0 
  openssl            pkgs/main/win-64::openssl-3.0.15-h827c3e9_0 
  pip                pkgs/main/win-64::pip-24.2-py313haa95532_0 
  python             pkgs/main/win-64::python-3.13.0-hadb2040_100_cp313 
  python_abi         pkgs/main/win-64::python_abi-3.13-0_cp313 
  setuptools         pkgs/main/win-64::setuptools-75.1.0-py313haa95532_0 
  sqlite             pkgs/main/win-64::sqlite-3.45.3-h2bbff1b_0
  tk                 pkgs/main/win-64::tk-8.6.14-h0416ee5_0
  tzdata             pkgs/main/noarch::tzdata-2024b-h04d1e81_0
  vc                 pkgs/main/win-64::vc-14.40-h2eaa2aa_1
  vs2015_runtime     pkgs/main/win-64::vs2015_runtime-14.40.33807-h98bb1dd_1
  wheel              pkgs/main/win-64::wheel-0.44.0-py313haa95532_0
  xz                 pkgs/main/win-64::xz-5.4.6-h8cc25b3_1
  zlib               pkgs/main/win-64::zlib-1.2.13-h8cc25b3_1
(sagemaker_py313) PS D:\github\udacity-nd009t-C2-Developing-ML-Workflow> pip uninstall jsonschema
Found existing installation: jsonschema 4.23.0
Uninstalling jsonschema-4.23.0:
  Would remove:
    d:\users\guido\miniconda3\envs\sagemaker_py313\lib\site-packages\jsonschema-4.23.0.dist-info\*
    d:\users\guido\miniconda3\envs\sagemaker_py313\lib\site-packages\jsonschema\*
    d:\users\guido\miniconda3\envs\sagemaker_py313\scripts\jsonschema.exe
Proceed (Y/n)? y
  Successfully uninstalled jsonschema-4.23.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment