> This page is for version 2.1.5-pb7.
> For other versions, use one of these documentation indexes:
> - 2.1.7 (Latest) (default): https://docs.nvidia.com/nim/large-language-models/2.1.7/llms.txt
> - 2.1.6: https://docs.nvidia.com/nim/large-language-models/2.1.6/llms.txt
> - 2.1.5-pb7: https://docs.nvidia.com/nim/large-language-models/2.1.5-pb7/llms.txt
> - 2.1.5: https://docs.nvidia.com/nim/large-language-models/2.1.5/llms.txt
> - 2.1.4: https://docs.nvidia.com/nim/large-language-models/2.1.4/llms.txt
> - 2.0.13: https://docs.nvidia.com/nim/large-language-models/2.0.13/llms.txt
> - 2.0.12: https://docs.nvidia.com/nim/large-language-models/2.0.12/llms.txt
> - 2.0.11: https://docs.nvidia.com/nim/large-language-models/2.0.11/llms.txt
> - 2.0.10: https://docs.nvidia.com/nim/large-language-models/2.0.10/llms.txt
> - 2.0.4-pb6: https://docs.nvidia.com/nim/large-language-models/2.0.4-pb6/llms.txt
> - Archive: https://docs.nvidia.com/nim/large-language-models/archive/llms.txt

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.nvidia.com/nim/large-language-models/llms.txt.

# AWS

> Deploy NIM LLM on Amazon Web Services using Amazon EKS with Helm or Amazon SageMaker managed endpoints.

NIM LLM and VLM supports deployment on Amazon Web Services (AWS) through two approaches:

* **EKS (Amazon Elastic Kubernetes Service)**: Self-managed Kubernetes deployment using Helm charts with GPU-accelerated nodes.
* **SageMaker**: Fully managed ML platform with managed real-time inference endpoints that use S3 for model storage.

## Deploy on Amazon EKS

This guide walks through deploying NIM LLM and VLM on
[Amazon Elastic Kubernetes Service (EKS)](https://docs.aws.amazon.com/eks/latest/userguide/what-is-eks.html)
with GPU-accelerated nodes.

To deploy NIM LLM and VLM on Amazon EKS, complete the following steps.

### Prerequisites

Before you start, complete the following prerequisites:

* Create or use an AWS account with permissions to create EKS clusters, EC2 GPU instances, and associated networking and IAM resources.
* Confirm sufficient GPU instance quota in your target region. Verify in the AWS Console under **Service Quotas > Amazon EC2 > "Running On-Demand \[instance-type] instances"**.
* Obtain an [NGC](https://ngc.nvidia.com/) account and API key.
* Install the following CLI tools:
  * [AWS CLI v2](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html)
  * [eksctl](https://eksctl.io/installation/)
  * [kubectl](https://kubernetes.io/docs/tasks/tools/)
  * [Helm 3](https://helm.sh/docs/intro/install/)

### Configure AWS Credentials

Set up a named AWS CLI profile and confirm that it works before you create infrastructure.

#### Create a Named Profile

Use a named profile so the AWS CLI and related tools use the expected account and region.

1. Create the AWS credentials directory, and open the credentials file:

   ```bash
   mkdir -p ~/.aws
   nano ~/.aws/credentials
   ```

2. Add your profile to `~/.aws/credentials`:

   ```ini
   [my-profile]
   aws_access_key_id=<your-access-key>
   aws_secret_access_key=<your-secret-key>
   aws_session_token=<your-session-token>
   ```

3. Set your profile and default region:

   ```bash
   export AWS_PROFILE=my-profile
   export AWS_DEFAULT_REGION=us-east-2
   ```

4. Verify that the profile works:

   ```bash
   aws sts get-caller-identity
   ```

#### Check GPU Instance Quota

Confirm that your target region has enough GPU quota before you create the cluster.

1. Set the AWS region:

   ```bash
   export AWS_REGION="us-east-2"
   ```

2. List the relevant GPU quotas:

   ```bash
   aws service-quotas list-service-quotas \
     --service-code ec2 \
     --region $AWS_REGION \
     --query "Quotas[?contains(QuotaName, 'On-Demand G') || contains(QuotaName, 'On-Demand P')].{Name:QuotaName, Value:Value}" \
     --output table
   ```

Use the quota output to confirm the instance families you plan to use:

* G-series (`g5.xlarge`, `g5.12xlarge`, and so on) requires quota code `L-DB2E81BA`.
* P-series (`p4d.24xlarge`, `p5.48xlarge`) requires quota code `L-417A185B`.

### Set Up the EKS Cluster

Create the control plane first, then add GPU-enabled worker nodes and the supporting storage and GPU components.

#### Set Environment Variables

Start by defining the values that the EKS setup commands use.

```bash
export AWS_REGION="us-east-2"
export EKS_CLUSTER="my-eks-cluster"
export GPU_NODEGROUP="gpu-nodegroup"
```

#### Create the Cluster

Follow these steps to create the EKS control plane and verify connectivity:

1. Create the EKS control plane (without any node group). Refer to the
   [AWS EKS documentation](https://docs.aws.amazon.com/eks/latest/userguide/create-cluster.html)
   for additional cluster creation options.

   ```bash
   eksctl create cluster \
     --name $EKS_CLUSTER \
     --region $AWS_REGION \
     --without-nodegroup
   ```

2. After the cluster is ready, verify connectivity:

   ```bash
   kubectl get svc
   ```

> **Tip**
>
> To update `kubeconfig` for an existing cluster, run:
>
> ```bash
> aws eks update-kubeconfig --region $AWS_REGION --name $EKS_CLUSTER
> ```

#### Add a GPU Node Group

Add a GPU-capable managed node group after the EKS control plane is ready.

1. Create the GPU node group:

   ```bash
   eksctl create nodegroup \
     --cluster $EKS_CLUSTER \
     --region $AWS_REGION \
     --name $GPU_NODEGROUP \
     --node-type g5.12xlarge \
     --nodes 1 \
     --node-ami-family AmazonLinux2023 \
     --install-nvidia-plugin=false \
     --node-volume-size 200
   ```

2. After the node group is ready, verify that the node joined the cluster:

   ```bash
   kubectl get nodes -o wide
   ```

The following command options determine the key characteristics of the GPU node group:

* `--node-type`: This example uses a `g5.12xlarge` instance for the Lightning INT4 TP2 profile, which needs two NVIDIA A10G GPUs. For other profiles, choose an instance with the GPU type and count specified in the [Support Matrix for PB NIMs](/nim/large-language-models/2.1.5-pb7/reference/support-matrix).
* `--nodes 1`: Number of GPU instances to launch.
* `--node-ami-family AmazonLinux2023` selects an EKS-optimized NVIDIA AMI with the GPU driver and container toolkit.
* `--install-nvidia-plugin=false` lets the GPU Operator install the NVIDIA device plugin.
* `--node-volume-size 200`: Provides 200 GB of disk space for model storage and container
  images.

#### Install the NVIDIA GPU Operator

Install the GPU Operator after the node group is available. It installs the NVIDIA device plugin and GPU scheduling components. The AL2023 NVIDIA AMI supplies the driver and container toolkit. [EKS AL2023 NVIDIA AMIs](https://docs.aws.amazon.com/eks/latest/userguide/ml-eks-optimized-ami.html#eks-amis-nvidia-al2023)

1. Add the NVIDIA Helm repository, and update your local chart index:

   ```bash
   helm repo add nvidia https://helm.ngc.nvidia.com/nvidia --pass-credentials
   helm repo update
   ```

2. Install the GPU Operator:

   ```bash
   helm install --create-namespace --namespace gpu-operator nvidia/gpu-operator \
     --set driver.enabled=false --set toolkit.enabled=false \
     --wait --generate-name
   ```

3. Verify that the GPU Operator pods are ready:

   ```bash
   kubectl -n gpu-operator get pods
   ```

4. Verify that the nodes advertise GPU capacity:

   ```bash
   kubectl get nodes \
     -o custom-columns=NAME:.metadata.name,GPU:.status.allocatable.nvidia\.com/gpu
   ```

#### Associate the IAM OIDC Provider

The Amazon EBS CSI driver uses IAM Roles for Service Accounts (IRSA), which requires an IAM OIDC provider associated with the cluster. Associate it before you create the driver's IAM service account.

```bash
eksctl utils associate-iam-oidc-provider \
  --region $AWS_REGION \
  --cluster $EKS_CLUSTER \
  --approve
```

This command is idempotent: if the provider is already associated, `eksctl` reports that and makes no change.

#### Install the Amazon EBS CSI Driver

The Amazon EBS CSI driver is required for dynamic `PersistentVolumeClaim` provisioning.

1. Create an IAM service account using the `--override-existing-serviceaccounts` flag to keep re-runs idempotent:

   ```bash
   eksctl create iamserviceaccount \
     --cluster $EKS_CLUSTER \
     --region $AWS_REGION \
     --namespace kube-system \
     --name ebs-csi-controller-sa \
     --role-name AmazonEKS_EBS_CSI_DriverRole \
     --attach-policy-arn arn:aws:iam::aws:policy/service-role/AmazonEBSCSIDriverPolicy \
     --approve \
     --override-existing-serviceaccounts
   ```

2. Get your AWS account ID:

   ```bash
   ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)
   ```

3. Install the addon:

   ```bash
   eksctl create addon \
     --cluster $EKS_CLUSTER \
     --region $AWS_REGION \
     --name aws-ebs-csi-driver \
     --service-account-role-arn arn:aws:iam::${ACCOUNT_ID}:role/AmazonEKS_EBS_CSI_DriverRole \
     --force
   ```

   > **Info**
   >
   > The previous step creates the `ebs-csi-controller-sa` ServiceAccount and labels it `app.kubernetes.io/managed-by: eksctl`. The Amazon EBS CSI managed addon installs its own copy of that ServiceAccount. Without `--force`, the addon refuses to reconcile the conflicting label, fails with a `ConfigurationConflict` error, and remains in the `CREATE_FAILED` state. The `--force` flag applies the addon with the `OVERWRITE` conflict-resolution mode so that the addon adopts the existing ServiceAccount, which allows the controller to start and the `ebs.csi.aws.com` driver to register. If the addon fails, the EBS CSI controller has no pods, and `PersistentVolumeClaim` resources stay in the `Pending` state.

4. Verify the installation:

   ```bash
   kubectl get pods -n kube-system -l app.kubernetes.io/name=aws-ebs-csi-driver
   ```

#### Verify the Cluster Is Ready

Run the following checks to confirm that the cluster is ready for deployment.

1. Confirm that the nodes are present:

   ```bash
   kubectl get nodes -o wide
   ```

2. Confirm that the nodes advertise GPU capacity:

   ```bash
   kubectl get nodes \
     -o custom-columns=NAME:.metadata.name,GPU:.status.allocatable.nvidia\.com/gpu
   ```

3. Confirm that the Amazon EBS CSI Driver pods are running:

   ```bash
   kubectl get pods -n kube-system -l app.kubernetes.io/name=aws-ebs-csi-driver
   ```

4. Confirm that the GPU Operator pods are running:

   ```bash
   kubectl -n gpu-operator get pods
   ```

### Deploy NIM

After the cluster is ready, create the namespace, configure secrets and storage, and install the Helm chart.

#### Create the Namespace and Secrets

Create the Kubernetes namespace and the secrets that the deployment uses.

1. Set the deployment variables:

   ```bash
   export NAMESPACE="nim-llm"
   export RELEASE_NAME="my-nim"
   export NGC_API_KEY="<your-ngc-api-key>"
   ```

2. Create the namespace:

   ```bash
   kubectl create namespace $NAMESPACE
   ```

3. Create the NGC registry secret:

   ```bash
   kubectl create secret docker-registry ngc-secret \
     --namespace $NAMESPACE \
     --docker-server=nvcr.io \
     --docker-username='$oauthtoken' \
     --docker-password="$NGC_API_KEY"
   ```

4. Create the NGC API key secret:

   ```bash
   kubectl create secret generic ngc-api \
     --namespace $NAMESPACE \
     --from-literal=NGC_API_KEY="$NGC_API_KEY"
   ```

> **Tip**
>
> If your model requires a gated Hugging Face repository, create an additional
> secret with your Hugging Face token:
>
> ```bash
> kubectl create secret generic hf-token \
>   --namespace $NAMESPACE \
>   --from-literal=HF_TOKEN="<your-HF-token>"
> ```

#### Create a Model Cache PVC

Create a persistent volume claim so model artifacts can be reused across pod restarts.

```bash
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: nvidia-nim-cache-pvc
  namespace: $NAMESPACE
spec:
  accessModes:
    - ReadWriteOnce
  storageClassName: gp2
  resources:
    requests:
      storage: 200Gi
EOF
```

> **Note**
>
> `gp3` is also a valid `storageClassName`.

#### Create a Helm Values File

Save the following as `custom-values-eks.yaml`:

```yaml
image:
  repository: nvcr.io/nim/nvidia/nemotron-3.5-lightning-30b-a3b-pb7
  tag: "2.1.5-pb7.0"
  pullPolicy: IfNotPresent

model:
  name: nvidia/nemotron-3.5-lightning
  ngcAPISecret: ngc-api
  nimCache: /model-store
  openaiPort: 8000
  logLevel: INFO

env:
  - name: NIM_MODEL_PROFILE
    value: "vllm-int4-tp2-pp1"

persistence:
  enabled: true
  existingClaim: "nvidia-nim-cache-pvc"

resources:
  limits:
    nvidia.com/gpu: 2

imagePullSecrets:
  - name: ngc-secret

nodeSelector:
  nvidia.com/gpu.present: "true"

livenessProbe:
  timeoutSeconds: 10

service:
  type: LoadBalancer
  openaiPort: 8000
```

> **Info**
>
> `livenessProbe.timeoutSeconds` defaults to `1` in the chart. The liveness endpoint itself (`/v1/health/live`) is served directly by nginx and returns 200 without touching the backend, so the endpoint response is effectively instant. The 10-second override guards against transient kubelet-to-pod network latency (bin-packed nodes, CNI hiccups) that could otherwise trip a 1-second budget and cause a spurious restart during model load. Skip the override if your cluster's baseline latency profile is stable. Readiness and startup probes use `/v1/health/ready` and already ship with 30-second timeouts.
>
> `startupProbe` (`60/30s/30s / failureThreshold=120`, \~60min budget) and `readinessProbe` (`60/30s/30s / failureThreshold=6`) already ship with generous timings suitable for deployments with large model downloads and multi-node deployments, so no override is required for those two.

> **Note**
>
> If you choose a different model or GPU, update `NIM_MODEL_PROFILE` and `resources.limits.nvidia.com/gpu` together. To list available profiles, refer to [Model Profiles and Selection](/nim/large-language-models/2.1.5-pb7/deployment/model-profiles-and-selection).

#### Install the Helm Chart

Follow [Fetch the Helm Chart](/nim/large-language-models/2.1.5-pb7/deployment/kubernetes-deployment/helm-k8s#fetch-the-helm-chart) to download and extract a PB7-compatible Helm chart. Install it from the parent directory of the extracted `nim-llm/` chart:

```bash
helm install "$RELEASE_NAME" ./nim-llm \
  --namespace "$NAMESPACE" \
  -f custom-values-eks.yaml
```

#### Monitor and Verify the Deployment

Use the following steps to monitor the rollout and verify that the service is reachable.

1. Watch the pod status:

   ```bash
   kubectl -n $NAMESPACE get pods -w
   ```

2. Stream the NIM logs:

   ```bash
   kubectl -n $NAMESPACE logs -l app.kubernetes.io/name=nim-llm -f --tail=100
   ```

3. Get the service endpoint:

   ```bash
   kubectl -n $NAMESPACE get svc -l app.kubernetes.io/name=nim-llm
   ```

4. After `EXTERNAL-IP` is populated, set `EXTERNAL_IP`:

   ```bash
   export EXTERNAL_IP=$(kubectl -n $NAMESPACE get svc $RELEASE_NAME-nim-llm \
     -o jsonpath='{.status.loadBalancer.ingress[0].hostname}')
   ```

> **Tip**
>
> If the LoadBalancer external IP is not available, use port-forwarding instead:
>
> ```bash
> kubectl -n $NAMESPACE port-forward svc/$RELEASE_NAME-nim-llm 8000:8000
> export EXTERNAL_IP=localhost
> ```

5. Check the readiness endpoint:

   ```bash
   curl -s "http://$EXTERNAL_IP:8000/v1/health/ready"
   ```

   > **Note**
   >
   > After the LoadBalancer hostname resolves, an AWS Elastic Load Balancer (ELB) takes about 30 seconds to 2 minutes to register the (already ready) pod as a healthy target. Running `curl` on the endpoint once during this window can return a transient `curl` exit code (`7` connection refused, `28` timeout, or `52` empty reply) or an ELB-generated `HTTP 502`, `503`, or `504`. These are expected during target registration. Poll the readiness endpoint with retries until it returns `HTTP 200` rather than treating a single failed `curl` execution as a deployment error.

6. List the available models:

   ```bash
   curl -s "http://$EXTERNAL_IP:8000/v1/models" | python3 -m json.tool
   ```

7. Send a test chat completion request:

   ```bash
   curl -X POST "http://$EXTERNAL_IP:8000/v1/chat/completions" \
     -H "Content-Type: application/json" \
     -d '{
       "model": "nvidia/nemotron-3.5-lightning",
       "messages": [{"role": "user", "content": "Hello!"}],
       "max_tokens": 128
     }'
   ```

   > **Note**
   >
   > If you deploy another model, use the served model name returned by `/v1/models` in the request's `model` field.

### Remove the EKS Deployment

To remove the EKS deployment resources when you no longer need them, complete the following steps:

1. Remove the Helm release:

   ```bash
   helm uninstall $RELEASE_NAME -n $NAMESPACE
   ```

2. Delete the persistent volume claim and namespace:

   ```bash
   kubectl delete pvc nvidia-nim-cache-pvc -n $NAMESPACE
   kubectl delete namespace $NAMESPACE
   ```

3. Delete the EKS cluster. For additional options, refer to the
   [AWS documentation](https://docs.aws.amazon.com/eks/latest/userguide/getting-started-eksctl.html).

   ```bash
   eksctl delete cluster --name $EKS_CLUSTER --region $AWS_REGION
   ```

## Deploy on Amazon SageMaker

This guide covers deploying NIM LLM and VLM on [Amazon SageMaker](https://docs.aws.amazon.com/sagemaker/) using managed real-time inference endpoints. Model artifacts are typically stored in S3, but if your SageMaker endpoint has outbound internet access (for example, through a NAT gateway or public subnet), NIM can also download models directly from NGC or Hugging Face at startup. Refer to [Model Storage Options](#model-storage-options) for details.

To deploy NIM LLM and VLM on Amazon SageMaker, complete the following steps.

### Native SageMaker Protocol Support

NIM implements the SageMaker BYOC (Bring Your Own Container) protocol natively. When SageMaker mode is active, NIM:

* Listens on **port 8080** (the port SageMaker expects).
* Responds to `GET /ping` — the health check SageMaker calls before marking an endpoint `InService`.
* Accepts `POST /invocations` — the inference path SageMaker routes all requests to.

**Activation** — Set `NIM_SAGEMAKER_MODE=1` in the SageMaker model `Environment` for every real-time endpoint. A standard single-model endpoint does not inject `SAGEMAKER_MULTI_MODEL`, `SAGEMAKER_REGION`, or `SAGEMAKER_BIND_TO_PORT`, so auto-detection does not run and NIM stays on port 8000. Use `NIM_SAGEMAKER_MODE=0` only to suppress SageMaker mode.

| `NIM_SAGEMAKER_MODE` | Effect                                                                                    |
| -------------------- | ----------------------------------------------------------------------------------------- |
| `1`                  | Required for SageMaker endpoints. Enables port 8080, `/ping`, and `/invocations`.         |
| `0`                  | Suppress SageMaker mode even when `SAGEMAKER_*` vars are present                          |
| *(unset)*            | Auto-detect from `SAGEMAKER_MULTI_MODEL`, `SAGEMAKER_REGION`, or `SAGEMAKER_BIND_TO_PORT` |

#### SageMaker-Injected Environment Variables

The following environment variables are **not** NIM configuration variables. They are injected automatically by the [SageMaker host agent](https://docs.aws.amazon.com/sagemaker/latest/dg/your-algorithms-inference-code.html) into every BYOC container running on a SageMaker endpoint. NIM reads them solely as signals for auto-detection; you do not need to set them yourself.

| Variable                 | Purpose                                                                                                                                    | Reference                                                                                                      |
| ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------- |
| `SAGEMAKER_BIND_TO_PORT` | The port the container must listen on (typically `8080`). When present, NIM uses this value as the server port.                            | [Container requirements](https://docs.aws.amazon.com/sagemaker/latest/dg/your-algorithms-inference-main.html)  |
| `SAGEMAKER_MULTI_MODEL`  | Injected when the endpoint is configured for multi-model hosting. NIM does not use the value; its presence triggers auto-detection.        | [Multi-model endpoints](https://docs.aws.amazon.com/sagemaker/latest/dg/multi-model-endpoints.html)            |
| `SAGEMAKER_REGION`       | The AWS region where the endpoint is running (for example, `us-east-1`). NIM does not use the value; its presence triggers auto-detection. | [SageMaker BYOC contract](https://docs.aws.amazon.com/sagemaker/latest/dg/your-algorithms-inference-code.html) |

If any of these variables is detected and `NIM_SAGEMAKER_MODE` is not explicitly set, NIM enables SageMaker mode automatically. Set `NIM_SAGEMAKER_MODE=0` to suppress this behavior.

The request body for `POST /invocations` is identical to `POST /v1/chat/completions` — NIM transparently rewrites the path internally.

### Prerequisites

Before you start, complete the following prerequisites:

* Create or use an [AWS account](https://aws.amazon.com/) with permissions to create SageMaker endpoints, ECR repositories, and S3 buckets.
* Obtain an [NGC API key](https://org.ngc.nvidia.com/setup/api-key) to pull a PB7 image from NGC and to start deployments that download model files, including from S3 or Hugging Face.
* Obtain a [Hugging Face access token](https://huggingface.co/settings/tokens) if you download models directly from Hugging Face.
* Install the following tools:
  * [AWS CLI v2](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html)
  * [Docker](https://docs.docker.com/get-docker/) (for copying the NIM image to ECR)

Your SageMaker execution role must have access to the S3 bucket where model artifacts are stored, and to ECR if you push the container image to your own registry. For more information about IAM roles, refer to [SageMaker execution roles](https://docs.aws.amazon.com/sagemaker/latest/dg/sagemaker-roles.html).

### Model Storage Options

NIM on SageMaker supports the same model sources as other platforms. S3 is the most common choice, but if the SageMaker endpoint has outbound internet access (for example, through a NAT gateway or public subnet), NIM can also download directly from NGC or Hugging Face at startup.

| Source                  | Method                                              | Source Configuration                       | Outbound Internet for Model Downloads                      |
| ----------------------- | --------------------------------------------------- | ------------------------------------------ | ---------------------------------------------------------- |
| NGC (built-in manifest) | Container downloads from NGC at startup             | `NGC_API_KEY`                              | Yes                                                        |
| NGC direct              | NIM generates manifest, downloads from NGC          | `NIM_MODEL_PATH=ngc://org/model:ver`       | Yes                                                        |
| NGC mirrored to S3      | Model files in S3 with percent-encoded keys         | `NIM_REPOSITORY_OVERRIDE=s3://bucket`      | No (refer to [Model Download](/nim/large-language-models/2.1.5-pb7/deployment/model-download)) |
| S3 direct               | Your own model stored in S3                         | `NIM_MODEL_PATH=s3://bucket/path/to/model` | No                                                         |
| Hugging Face direct     | NIM generates manifest, downloads from Hugging Face | `NIM_MODEL_PATH=hf://org/model`            | Yes                                                        |
| Local path              | Model files pre-loaded in the container             | `NIM_MODEL_PATH=/opt/nim/models/`          | No                                                         |

Pass `NGC_API_KEY` whenever PB7 needs to download model files, including from S3 and Hugging Face. A complete local model store can start without the key. Pass `HF_TOKEN` as well for gated Hugging Face downloads.

The SageMaker execution role supplies S3 access. For `NIM_REPOSITORY_OVERRIDE=s3://...` or `NIM_MODEL_PATH=s3://...`, pass `AWS_REGION` and `AWS_DEFAULT_REGION` as container environment variables so the in-container AWS SDK can resolve the bucket region.

### Push the NIM Image to ECR

SageMaker runs the NIM image from Amazon ECR. Copy the PB7 model-specific image for an NGC manifest or S3 mirror. For a custom S3 model or direct Hugging Face download, copy the PB7 Model-Free image.

1. Set the AWS region, repository name, and account ID:

   ```bash
   export AWS_REGION="${AWS_REGION:-us-east-1}"
   export NGC_API_KEY="${YOUR_NGC_API_KEY}"
   export ECR_REPO_NAME="nim-llm"
   export AWS_ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)
   ```

2. Log in to Amazon ECR:

   ```bash
   aws ecr get-login-password --region $AWS_REGION | docker login --username AWS --password-stdin ${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com
   ```

3. Create the ECR repository if it does not already exist:

   ```bash
   aws ecr create-repository --repository-name $ECR_REPO_NAME --region $AWS_REGION 2>/dev/null || true
   ```

4. Define the source image and target ECR URI:

   ```bash
   export NIM_IMAGE="nvcr.io/nim/nvidia/nemotron-3.5-lightning-30b-a3b-pb7:2.1.5-pb7.0"
   # For Model-Free, use:
   # export NIM_IMAGE="nvcr.io/nim/nvidia/model-free-nim-pb7:2.1.5-pb7.0"
   export NIM_IMAGE_NAME="${NIM_IMAGE##*/}"
   export ECR_URI="${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/${ECR_REPO_NAME}:${NIM_IMAGE_NAME/:/-}"
   ```

5. Pull, tag, and push the image:

   ```bash
   docker login nvcr.io --username '$oauthtoken' --password-stdin <<< "$NGC_API_KEY"
   docker pull "$NIM_IMAGE"
   docker tag "$NIM_IMAGE" "$ECR_URI"
   docker push "$ECR_URI"
   ```

### Create the SageMaker Model

Create a SageMaker model resource that references your ECR image and sets `NIM_SAGEMAKER_MODE=1` plus the environment variables NIM needs at runtime.

#### Mirror an NGC Model to S3

For an NGC NIM image deployed to a VPC-isolated endpoint (no outbound internet), mirror the model artifacts into your own S3 bucket first, then point NIM at the bucket using `NIM_REPOSITORY_OVERRIDE`. The image ships a `mirror s3` command that reads its manifest and copies the model files to S3.

1. Set the bucket and create it if it does not exist:

   ```bash
   export S3_BUCKET="${YOUR_S3_BUCKET}"
   aws s3api create-bucket --bucket $S3_BUCKET --region $AWS_REGION \
     --create-bucket-configuration LocationConstraint=$AWS_REGION
   ```

   > **Note**
   >
   > In `us-east-1`, omit `--create-bucket-configuration` because that region does not accept a `LocationConstraint`.

2. Run the mirror command from the NIM image. This step runs in your own environment rather than under the SageMaker execution role, so the container needs AWS credentials to write to S3: the `-e AWS_ACCESS_KEY_ID`, `-e AWS_SECRET_ACCESS_KEY`, and `-e AWS_SESSION_TOKEN` lines forward credentials from your host shell, which is required when you run this from a workstation or instance that has no attached IAM role. Also pass `AWS_REGION` and `AWS_DEFAULT_REGION` so the in-container AWS SDK can resolve the bucket region:

   ```bash
   docker run --rm \
     -e NGC_API_KEY="$NGC_API_KEY" \
     -e AWS_REGION="$AWS_REGION" \
     -e AWS_DEFAULT_REGION="$AWS_REGION" \
     -e AWS_ACCESS_KEY_ID -e AWS_SECRET_ACCESS_KEY -e AWS_SESSION_TOKEN \
     $NIM_IMAGE \
     mirror s3 -b $S3_BUCKET -m /opt/nim/etc/default/model_manifest.yaml
   ```

3. Confirm the bucket now has objects:

   ```bash
   aws s3 ls s3://$S3_BUCKET/ --recursive | head
   ```

After the mirror finishes, create the model with `NIM_REPOSITORY_OVERRIDE=s3://$S3_BUCKET` as shown next.

#### Use an NGC Model Mirrored to S3

If you have mirrored an NGC model to S3, use the `NIM_REPOSITORY_OVERRIDE` environment variable to specify the location.

Replace `${YOUR_S3_BUCKET}` with your S3 bucket name (for example, `my-nim-models`) and `${YOUR_NGC_API_KEY}` with your [NGC API key](https://org.ngc.nvidia.com/setup/api-key). Keep `NGC_API_KEY` secret and never commit it to version control.

1. Set the required environment variables:

   ```bash
   # Use the ECR image URI from the "Push the NIM Image to ECR" section.
   export ENDPOINT_NAME="nim-lightning"
   export SERVED_MODEL_NAME="nvidia/nemotron-3.5-lightning"
   export EXECUTION_ROLE_ARN="arn:aws:iam::${AWS_ACCOUNT_ID}:role/YourSageMakerExecutionRole"
   export S3_BUCKET="${YOUR_S3_BUCKET}"
   export NGC_API_KEY="${YOUR_NGC_API_KEY}"
   ```

2. Create the SageMaker model:

   ```bash
   aws sagemaker create-model \
     --model-name $ENDPOINT_NAME \
     --execution-role-arn $EXECUTION_ROLE_ARN \
     --primary-container '{
       "Image": "'"$ECR_URI"'",
       "Environment": {
         "NIM_SAGEMAKER_MODE": "1",
         "NGC_API_KEY": "'"$NGC_API_KEY"'",
         "NIM_REPOSITORY_OVERRIDE": "s3://'"$S3_BUCKET"'",
         "NIM_MODEL_PROFILE": "vllm-int4-tp1-pp1",
         "NIM_SERVED_MODEL_NAME": "'"$SERVED_MODEL_NAME"'",
         "AWS_REGION": "'"$AWS_REGION"'",
         "AWS_DEFAULT_REGION": "'"$AWS_REGION"'"
       }
     }'
   ```

> **Info**
>
> When `NIM_REPOSITORY_OVERRIDE` (or `NIM_MODEL_PATH`) points to S3, NIM uses the AWS SDK inside the container to download model artifacts. The SDK requires a region, and SageMaker does not inject one automatically. Pass both `AWS_REGION` and `AWS_DEFAULT_REGION` in the container `Environment` (set to the same region as your S3 bucket and endpoint), or the container fails at startup with `no region selected` and the endpoint never reaches `InService`.

> **Note**
>
> `NIM_SERVED_MODEL_NAME` must match the model name baked into the image at build time (the `com.nvidia.nim.model` docker label). A mismatch causes a model-profile lookup failure at startup. The same value must be used as the `"model"` field in the `/invocations` request body below.

#### Use a Custom Model in S3

Use the PB7 Model-Free image and specify the S3 path with `NIM_MODEL_PATH`.

Replace `${YOUR_S3_BUCKET}` with your S3 bucket name (for example, `my-nim-models`). The bucket must exist in the target region and your SageMaker execution role must have read access to it.

1. Set the required environment variables:

   ```bash
   # Use the ECR image URI from the "Push the NIM Image to ECR" section.
   export ENDPOINT_NAME="nim-custom-model"
   export SERVED_MODEL_NAME="my-model"
   export EXECUTION_ROLE_ARN="arn:aws:iam::${AWS_ACCOUNT_ID}:role/YourSageMakerExecutionRole"
   export S3_BUCKET="${YOUR_S3_BUCKET}"
   export S3_MODEL_URI="s3://${S3_BUCKET}/path/to/model"
   ```

2. Create the SageMaker model:

   ```bash
   aws sagemaker create-model \
     --model-name $ENDPOINT_NAME \
     --execution-role-arn $EXECUTION_ROLE_ARN \
     --primary-container '{
       "Image": "'"$ECR_URI"'",
       "Environment": {
         "NIM_SAGEMAKER_MODE": "1",
         "NGC_API_KEY": "'"$NGC_API_KEY"'",
         "NIM_MODEL_PATH": "'"$S3_MODEL_URI"'",
         "NIM_SERVED_MODEL_NAME": "'"$SERVED_MODEL_NAME"'",
         "AWS_REGION": "'"$AWS_REGION"'",
         "AWS_DEFAULT_REGION": "'"$AWS_REGION"'"
       }
     }'
   ```

#### Use a Hugging Face Model Directly

Use the PB7 Model-Free image to download a compatible gated or public Hugging Face model at endpoint startup. The SageMaker subnet must allow outbound internet access.

1. Find the model page on Hugging Face (for example, [Llama-3.1-8B-Instruct](https://huggingface.co/meta-llama/Llama-3.1-8B-Instruct)). Accept the model's license before deploying.

2. Set the required environment variables. Replace `${YOUR_HF_TOKEN}` with your [Hugging Face access token](https://huggingface.co/settings/tokens):

   ```bash
   # Use the ECR image URI from the "Push the NIM Image to ECR" section.
   export ENDPOINT_NAME="nim-hf-llama"
   export SERVED_MODEL_NAME="llama-3.1-8b-instruct"
   export EXECUTION_ROLE_ARN="arn:aws:iam::${AWS_ACCOUNT_ID}:role/YourSageMakerExecutionRole"
   export HF_TOKEN="${YOUR_HF_TOKEN}"
   ```

3. Create the SageMaker model:

   ```bash
   aws sagemaker create-model \
     --model-name $ENDPOINT_NAME \
     --execution-role-arn $EXECUTION_ROLE_ARN \
     --primary-container '{
       "Image": "'"$ECR_URI"'",
       "Environment": {
         "NIM_SAGEMAKER_MODE": "1",
         "NGC_API_KEY": "'"$NGC_API_KEY"'",
         "NIM_MODEL_PATH": "hf://meta-llama/Llama-3.1-8B-Instruct",
         "HF_TOKEN": "'"$HF_TOKEN"'",
         "NIM_SERVED_MODEL_NAME": "'"$SERVED_MODEL_NAME"'",
         "AWS_REGION": "'"$AWS_REGION"'",
         "AWS_DEFAULT_REGION": "'"$AWS_REGION"'"
       }
     }'
   ```

> **Note**
>
> Pass `HF_TOKEN` in the container `Environment` so NIM can authenticate to Hugging Face for gated models. Also pass `AWS_REGION` and `AWS_DEFAULT_REGION`: NIM's in-container AWS SDK resolves its region from these variables and ignores the `SAGEMAKER_REGION` value that the SageMaker host agent injects, so omitting them can break any S3 access the runtime performs.

> **Note**
>
> This option requires outbound internet access from the SageMaker endpoint subnet. If your VPC does not have a NAT gateway or internet gateway, the download will fail at startup. For VPC-isolated deployments, use one of the S3-based options instead.

Keep the same `ENDPOINT_NAME` for the model, endpoint configuration, and endpoint. Use the `SERVED_MODEL_NAME` from the selected model source when sending an inference request.

### Create Endpoint Config and Endpoint

Create an endpoint configuration, create the endpoint, and then wait for it to become ready.

1. Set the instance type. This example has one NVIDIA L40S GPU. For Lightning, it matches the INT4 TP1 profile in the [Support Matrix for PB NIMs](/nim/large-language-models/2.1.5-pb7/reference/support-matrix). Choose a compatible instance type and profile for the model you deploy.

   ```bash
   export INSTANCE_TYPE="ml.g6e.xlarge"
   ```

2. Create the endpoint configuration:

   ```bash
   aws sagemaker create-endpoint-config \
     --endpoint-config-name $ENDPOINT_NAME \
     --production-variants '[{
       "VariantName": "AllTraffic",
       "ModelName": "'"$ENDPOINT_NAME"'",
       "InstanceType": "'"$INSTANCE_TYPE"'",
       "InitialInstanceCount": 1,
       "ContainerStartupHealthCheckTimeoutInSeconds": 1800,
       "InferenceAmiVersion": "al2023-ami-sagemaker-inference-gpu-4-1"
     }]'
   ```

   > **Info**
   >
   > Choose an inference AMI that is available for your instance type and supplies a driver that supports the CUDA version required by PB7. The example selects an AMI with an NVIDIA R580 driver and CUDA 13.0. [SageMaker inference AMI options](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_ProductionVariant.html#sagemaker-Type-ProductionVariant-InferenceAmiVersion)

3. Create the endpoint:

   ```bash
   aws sagemaker create-endpoint \
     --endpoint-name $ENDPOINT_NAME \
     --endpoint-config-name $ENDPOINT_NAME
   ```

4. Check the endpoint status until it is `InService` (this can take several minutes):

   ```bash
   aws sagemaker describe-endpoint --endpoint-name $ENDPOINT_NAME --query 'EndpointStatus' --output text
   ```

### Verify the Deployment

SageMaker calls `GET /ping` on port 8080 to determine readiness and routes all inference traffic to `POST /invocations`. Both endpoints are implemented natively by NIM when `NIM_SAGEMAKER_MODE=1` is set.

#### Check Endpoint Status

Wait for the endpoint to reach `InService`. SageMaker polls `GET /ping` internally during startup and only marks the endpoint ready when it returns `200`:

```bash
aws sagemaker describe-endpoint \
  --endpoint-name $ENDPOINT_NAME \
  --query 'EndpointStatus' \
  --output text
```

Expected output when ready:

```
InService
```

#### Run an Inference Request

Send a chat completion request through `POST /invocations`. The request body is the same OpenAI-compatible JSON as other NIM deployments — NIM rewrites the path to `/v1/chat/completions` internally:

1. Invoke the endpoint:

   ```bash
   aws sagemaker-runtime invoke-endpoint \
     --endpoint-name $ENDPOINT_NAME \
     --content-type "application/json" \
     --cli-binary-format raw-in-base64-out \
     --body '{"model":"'"$SERVED_MODEL_NAME"'","messages":[{"role":"user","content":"Hello!"}],"max_tokens":128}' \
     /tmp/response.json && echo "HTTP 200 OK"
   ```

2. Format the response:

   ```bash
   python3 -m json.tool /tmp/response.json
   ```

   Expected response shape:

   ```json
   {
     "id": "chatcmpl-...",
     "object": "chat.completion",
     "model": "nvidia/nemotron-3.5-lightning",
     "choices": [
       {
         "index": 0,
         "message": {
           "role": "assistant",
           "content": "Hello! How can I help you today?"
         },
         "finish_reason": "stop"
       }
     ],
     "usage": { "prompt_tokens": 10, "completion_tokens": 9, "total_tokens": 19 }
   }
   ```

> **Note**
>
> For AWS CLI v2, `--body` is a blob parameter. Use
> `--cli-binary-format raw-in-base64-out` when sending raw JSON inline,
> otherwise the endpoint receives a malformed request body.

> **Note**
>
> `POST /invocations` is a direct pass-through to `/v1/chat/completions`. Any valid OpenAI chat completion body works, including streaming (`"stream": true`).

> **Note**
>
> Some AWS CLI installations do not expose
> `invoke-endpoint-with-response-stream` under `aws sagemaker-runtime`.
> If that subcommand is unavailable, verify non-streaming `invoke-endpoint`
> first and use a newer CLI build or an SDK-based client for streaming tests.

### Remove the SageMaker Resources

Delete the SageMaker resources when you no longer need them so you avoid ongoing charges.

To remove the SageMaker resources, complete the following steps:

1. Delete the endpoint:

   ```bash
   aws sagemaker delete-endpoint --endpoint-name $ENDPOINT_NAME
   ```

2. After the endpoint deletion finishes, delete the endpoint configuration:

   ```bash
   aws sagemaker delete-endpoint-config --endpoint-config-name $ENDPOINT_NAME
   ```

3. Delete the model:

   ```bash
   aws sagemaker delete-model --model-name $ENDPOINT_NAME
   ```

4. Optional: Remove the ECR image and S3 model data if you no longer need them.

## Next Steps

Refer to the following AWS documentation for more information:

* [AWS Elastic Kubernetes Service (EKS) Documentation](https://docs.aws.amazon.com/eks/)
* [AWS SageMaker Documentation](https://docs.aws.amazon.com/sagemaker/)
* [Model Download](/nim/large-language-models/2.1.5-pb7/deployment/model-download) — Mirror NGC models to S3 or serve from `NIM_MODEL_PATH`
* [Model Profiles and Selection](/nim/large-language-models/2.1.5-pb7/deployment/model-profiles-and-selection) — Choose a profile for your GPU instance