Deploying and Invoking Models Programmatically
This lesson explains the resources that the SageMaker Python SDK, the AWS CLI and Boto3 create when models are deployed, since production deployments are automated, not clicked.
Learning outcomes
After completing this lesson, you will be able to:
- Create the model, endpoint configuration and endpoint resources.
- Deploy with the SageMaker Python SDK.
- Invoke endpoints synchronously and asynchronously.
- Update an endpoint without downtime.
The three hosting resources
SageMaker AI hosting uses three resources. A model combines an inference container image, the S3 location of model artefacts and an execution role. An endpoint configuration defines one or more production variants (model, instance type, initial instance count, traffic weight) and options such as data capture, asynchronous or serverless settings and KMS keys. An endpoint is created from an endpoint configuration. To change instance type, model or variants, create a new endpoint configuration and call UpdateEndpoint; SageMaker AI performs a blue/green update without downtime.
aws sagemaker create-model --model-name churn-v7 \
--primary-container Image=$IMAGE,ModelDataUrl=s3://ml/churn/v7/model.tar.gz \
--execution-role-arn $ROLE
aws sagemaker create-endpoint-config --endpoint-config-name churn-v7-cfg \
--production-variants VariantName=AllTraffic,ModelName=churn-v7,InstanceType=ml.m5.large,InitialInstanceCount=2
aws sagemaker update-endpoint --endpoint-name churn --endpoint-config-name churn-v7-cfgThe following diagram shows the resources created to upgrade a live SageMaker AI endpoint and the blue/green update that avoids an outage.

Create an endpoint
SageMaker Python SDK
The SageMaker Python SDK wraps the underlying API calls in a few high-level methods. estimator.deploy() deploys a model directly after training; Model(image_uri, model_data, role).deploy() deploys existing model artefacts with a chosen container; ModelBuilder packages models from many frameworks and selects suitable containers automatically; and a Predictor invokes the endpoint, with serializers and deserializers that convert data to and from the request format.
Serverless and asynchronous options are selected by passing a ServerlessInferenceConfig or AsyncInferenceConfig when deploying, so the same code deploys to any of the inference options.
A deployment script
Invoking endpoints
Clients use the sagemaker-runtime API: InvokeEndpoint for synchronous requests, InvokeEndpointAsync with an S3 input location for asynchronous endpoints and InvokeEndpointWithResponseStream to stream tokens from LLMs. Infrastructure as code with CloudFormation or CDK can define the same resources declaratively. The following table summarises the operations.
| Task | API / SDK |
|---|---|
| Register a model | CreateModel / Model() |
| Define variants and options | CreateEndpointConfig |
| Create or update an endpoint | CreateEndpoint / UpdateEndpoint |
| Change traffic weights without redeploying | UpdateEndpointWeightsAndCapacities |
| Synchronous request | InvokeEndpoint |
| Queued request | InvokeEndpointAsync |
| Streamed response | InvokeEndpointWithResponseStream |
Invocation options
A zero-downtime upgrade
A team must move a live endpoint from ml.m5.xlarge to ml.c6i.xlarge and to a new model version without interrupting callers. A colleague suggests deleting and recreating the endpoint with the same name.
Deleting the endpoint would cause an outage. Instead, create the new model and a new endpoint configuration, then call UpdateEndpoint. SageMaker AI provisions the new fleet, shifts traffic (optionally with deployment guardrails and alarms) and removes the old fleet. The endpoint name, and therefore client configuration, stays the same.
How are only the traffic weights between variants changed?
Show answer
With UpdateEndpointWeightsAndCapacities, without a new endpoint configuration.
Exam Tips
Remember for the exam
- Hosting resources: model, endpoint configuration, endpoint.
- Change instance type or model: new endpoint configuration, then UpdateEndpoint.
- Change traffic weights only: UpdateEndpointWeightsAndCapacities.
- Stream LLM tokens: InvokeEndpointWithResponseStream.
- Never delete and recreate a live endpoint to upgrade it.