C24IO / SageMaker-CLI-Deploy

SageMaker-CLI-Deploy

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SageMaker-CLI-Deploy

Deploy an endpoint using boto3 CLI

Step 1: define create_model.json

{
    "ModelName": "my-sagemaker-model",
    "PrimaryContainer": {
        "Image": "<insert the ECR Image URI>",
        "ModelDataUrl": "s3://path/to/model/artifact/model.tar.gz",
        "Environment": {}
    },
    "ExecutionRoleArn": "<ARN for AmazonSageMaker-ExecutionRole>"
}

if required, include the following environment variables:

 "Environment": {
            "SAGEMAKER_PROGRAM": "<specify your entry-point.py script>",
            "SAGEMAKER_SUBMIT_DIRECTORY": "/opt/ml/model/code",
            "SAGEMAKER_REGION": "<insert your region>",
            "SAGEMAKER_ENABLE_CLOUDWATCH_METRICS": "FALSE",
            "SAGEMAKER_CONTAINER_LOG_LEVEL": "20"            
        }

if required, include the following VPC config:

VpcConfig: {
      "Subnets": [
          "subnet-0123456789abcdef0",
          "subnet-0123456789abcdef1",
          "subnet-0123456789abcdef2"
          ],
      "SecurityGroupIds": [
          "sg-0123456789abcdef0"
          ]
       }

Reference: - vpc-config

Step 2: create sagemaker model using create_model.json

aws sagemaker create-model —cli-input-json file://create_model.json

OR

aws sagemaker create-model --model-name <<model name>>  --primary-container  Image=<<Docker image location>>  --execution-role-arn <<Role ARN>> --region <<region>>

OR 

aws sagemaker create-model --model-name <value> --primary-container Image=<<Docker image location>> --execution-role-arn <<ROLE ARN>> --tags <<Billing tags>> --vpc-config <<VPC config>> [--enable-network-isolation | --no-enable-network-isolation]

Reference - create-model

Step 3: define create_config.json

{
    "EndpointConfigName": "<provide your endpoint config name>",
    "ProductionVariants": [
        {
            "VariantName": "<provide your variant name>",
            "ModelName": "my-sagemaker-model",
            "InitialInstanceCount": 1,
            "InstanceType": "<provide your instance type here>",
            "InitialVariantWeight": 1.0
        }
    ]
}        

Step 4: create sagemaker endpoint configuration using create_config.json

aws sagemaker create-endpoint-config --cli-input-json file://create_config.json

Step 5: deploy the endpoint

aws sagemaker create-endpoint --endpoint-name '<provide your endpoint name>' --endpoint-config-name '<insert your endpoint config name>'

Thanks to - Pratyush Bagaria for this code snippet.

About

SageMaker-CLI-Deploy

License:MIT License