Lesson 4 of 5 ML Infrastructure and Containers

Running SageMaker AI Endpoints Privately in a VPC

This lesson explains how SageMaker AI endpoints run inside a VPC and how clients reach them privately, for organisations that require model hosting and data access to stay on private networks.

Learning outcomes

After completing this lesson, you will be able to:

  • Connect the model container to a VPC.
  • Give clients private access through an interface endpoint.
  • Apply network isolation.

Connecting the model container to a VPC

Specifying a VpcConfig (subnets and security groups) on the SageMaker AI model places the endpoint's containers in your VPC by creating elastic network interfaces in the chosen subnets. Use private subnets in at least two Availability Zones for availability. The container can then reach resources in the VPC, such as a feature store cache or a database, and AWS services through VPC endpoints: an S3 gateway endpoint for model artefacts and data, and interface endpoints for ECR (image pulls), CloudWatch Logs and any other service the container calls.

Private client access

Applications inside a VPC call SageMaker AI endpoints through an interface VPC endpoint for the SageMaker Runtime (com.amazonaws.<region>.sagemaker.runtime), so invocation traffic never crosses the internet. A separate interface endpoint for the SageMaker API serves management calls, such as creating and updating endpoints.

Access can be restricted from both directions. A VPC endpoint policy limits which SageMaker endpoints can be invoked through the VPC endpoint, and IAM policies with the aws:SourceVpce or aws:SourceVpc condition can deny invocations that come from anywhere else.

The following diagram shows the network design of a private SageMaker AI endpoint for a hospital's clinical application.

The hospital's private endpoint. The model's containers run with network interfaces in private subnets in two Availability Zones; the clinical application calls them through a SageMaker Runtime interface endpoint; images, logs and artefacts arrive through ECR and CloudWatch Logs interface endpoints and an S3 gateway endpoint; and an IAM policy denies invocations that do not come through the runtime endpoint.
SG is a security group; ENI is an elastic network interface.
Scenario questions

Keep traffic private

Exam skills 3.2.4 · 4.3.6

Choose the network configuration that keeps endpoint traffic private.

Log in to try this activity Interactive activities are free with an account.

Network isolation

Network isolation, set with EnableNetworkIsolation, removes all network access from the inference container: it cannot call AWS services or the internet, and SageMaker AI itself supplies the model artefacts to the container. Even if the model's code tried to send data out, it would have no route to do so.

Network isolation suits untrusted third-party models, such as some models from AWS Marketplace, and workloads with strict data exfiltration requirements. The following table summarises the components.

ComponentPurpose
VpcConfig on the modelContainers run with ENIs in your private subnets
S3 gateway endpointPrivate access to artefacts and data
ECR and CloudWatch Logs interface endpointsImage pulls and logging without internet
sagemaker.runtime interface endpointPrivate invocation by clients
aws:SourceVpce conditionDeny invocations from outside the VPC endpoint
Network isolationNo outbound network access from the container
True or false

Network isolation

Exam skills 3.2.4 · 4.3.6

Check what network isolation does and does not block.

Log in to try this activity Interactive activities are free with an account.
Worked example

A hospital's private endpoint

A hospital requires that patient data used for inference never traverses the internet and that only its clinical application in a specific VPC can call the model.

  • Deploy the model with VpcConfig in private subnets across two Availability Zones and a security group allowing traffic only from the application tier.
  • Create interface endpoints for SageMaker Runtime, ECR and CloudWatch Logs, and an S3 gateway endpoint.
  • Attach an IAM policy that denies sagemaker:InvokeEndpoint unless aws:SourceVpce equals the runtime endpoint ID.

A NAT gateway would also let the container reach AWS services, but traffic to public service endpoints would leave the VPC, which the requirement rules out.

Check yourself

How are endpoint invocations restricted to a particular VPC endpoint?

Show answer

With the aws:SourceVpce condition in the policy.

Exam Tips

Remember for the exam

  • Private invocation: sagemaker.runtime interface VPC endpoint.
  • Model artefacts from S3 in private subnets: S3 gateway endpoint.
  • Restrict invocations to the VPC endpoint: aws:SourceVpce condition.
  • No outbound access from the container: network isolation.
  • Use private subnets in at least two Availability Zones.