SDK, CLI, and Boto3 deployments

Lesson 4 of 4 in Provisioning ML Infrastructure as Code.

Three programmatic surfaces drive the same control plane, and the exam distinguishes them by altitude. The SageMaker Python SDK is the high-level, ML-aware layer: one model.deploy() call creates the model, the endpoint config, and the endpoint. Boto3 is the general AWS SDK: you make the three calls yourself, which is exactly what automation (Lambda, pipeline steps) wants. The AWS CLI is the shell-script face of the same APIs. None of them replaces IaC — scripts do things; templates declare end states.

SageMaker Python SDK

The notebook-native layer — ML concepts in, API mechanics hidden:

from sagemaker.model import Model

model = Model(image_uri=image, model_data=s3_artifact, role=role)
predictor = model.deploy(
    initial_instance_count=1,
    instance_type="ml.m5.xlarge",
)
predictor.predict(payload)

One deploy() = three objects created and a Predictor for calling the result. Perfect for experimentation; in pipelines its implicitness can hide what will exist afterward.

Boto3

The explicit layer — every object spelled out, which is why Lambda and pipeline code uses it:

import boto3
sm = boto3.client("sagemaker")

sm.create_model(ModelName=..., PrimaryContainer=..., ExecutionRoleArn=...)
sm.create_endpoint_config(EndpointConfigName=..., ProductionVariants=[...])
sm.create_endpoint(EndpointName=..., EndpointConfigName=...)

runtime = boto3.client("sagemaker-runtime")
runtime.invoke_endpoint(EndpointName=..., Body=payload)

Note the two clients: sagemaker builds, sagemaker-runtime invokes.

AWS CLI

The same APIs from a shell — deploy scripts, cron, quick checks:

aws sagemaker create-endpoint \
  --endpoint-name churn-prod \
  --endpoint-config-name churn-config-v7

aws sagemaker-runtime invoke-endpoint \
  --endpoint-name churn-prod \
  --body fileb://payload.json out.json

Same control/data-plane split: aws sagemaker vs aws sagemaker-runtime.

Three ladders to the same endpoint

  1. Trained model artifact in S3

    A model.tar.gz plus an inference image URI — the raw material every ladder starts from.

  2. Who is deploying?

    The surfaces differ by altitude, not capability: a person exploring in a notebook, automation inside Lambda or a pipeline step, or a shell script — all drive the same SageMaker control plane.

  3. SDK: model.deploy()

    The SageMaker Python SDK wraps the whole chain: one call creates the model, the endpoint config, and the endpoint — and hands back a Predictor for calling it.

  4. Boto3: create_model

    Rung one of the explicit ladder: name the container image and artifact, attach the execution role.

  5. create_endpoint_config

    Rung two: production variants — instance type, count, weights. The config is the versioned object a later UpdateEndpoint swaps in.

  6. create_endpoint

    Rung three: stand the endpoint up from the config. It fails if the name already exists — the idempotency trap the callout below covers.

  7. CLI: aws sagemaker …

    The same three calls as shell commands — create-model, create-endpoint-config, create-endpoint. Invocation moves to the sibling aws sagemaker-runtime command.

  8. The same running endpoint

    Whichever ladder you climb, describe_endpoint shows identical resources: a model, a config, an InService endpoint — invoked through the sagemaker-runtime client, never the sagemaker one.

Key terms: AWS CloudFormation, AWS CDK, VPC endpoint (PrivateLink), Real-time inference, Production variant

Interactive checkpoint quiz (2 questions) — open this page in a browser to take it.