How to use NVIDIA GPU EC2 instances: families, quotas, DLAMI, and EKS
Choose between G4dn, G5, G6, G7, P5, and P6, unlock the vCPU quota that starts at zero, launch a Deep Learning AMI with the AWS CLI and Terraform, use GPUs on EKS, and stop idle GPUs from burning money.
Cloud$ aws service-quotas list-service-quotas --service-code ec2▍The first attempt to launch a GPU instance on AWS often ends in an error before the boot even starts: VcpuLimitExceeded. A new account has no GPU quota, the right family is not always available in your Region, and the instance you forgot running over the weekend becomes the biggest line on the bill. This guide covers the whole path: choosing the family, unlocking the quota, launching the Deep Learning AMI, checking CUDA, using Spot and Capacity Blocks, running on EKS, and keeping costs under control.
G or P? The NVIDIA GPU families
Rule of thumb: the G family is for inference, graphics, and small fine-tuning; the P family is for training and inference of very large models, with several GPUs linked at high speed.
| Family | NVIDIA GPU | Typical use |
|---|---|---|
| G4dn | T4 | Low-cost inference, graphics |
| G5 | A10G | Inference, graphics, small fine-tuning |
| G6 | L4 | Cost-efficient inference, video |
| G6e | L40S | Larger-model inference |
| G7 (GA Jun 2026) | RTX PRO 4500 Blackwell Server Edition, 32 GB | Inference and graphics |
| G7e (GA Jan 2026) | RTX PRO 6000 Blackwell Server Edition, 96 GB | LLM and multimodal inference |
| P4d | A100 | Training and HPC (previous generation) |
| P5 | H100 | Training and large inference |
| P5e / P5en | H200 | Training and large inference |
| P6-B200 | B200 (Blackwell) | Frontier training and inference |
| P6-B300 | B300 (Blackwell Ultra) | Same as above, with more GPU memory |
| P6e-GB200 | GB200 NVL72 (UltraServers) | The largest training runs and reasoning inference |
The G7, G7e, and P6-B300 families and the P6e UltraServers are recent: sizes, Regions, and purchase options change quickly (GB300 UltraServers, for example, are sold through the AWS sales team). Check the current docs and availability in your Region:
aws ec2 describe-instance-type-offerings --location-type availability-zone \
--filters Name=instance-type,Values=g6.xlarge --region us-east-1 \
--query 'InstanceTypeOfferings[].Location' --output text
aws ec2 describe-instance-types --instance-types g6.xlarge \
--query 'InstanceTypes[0].[VCpuInfo.DefaultVCpus,GpuInfo.Gpus[0].Name,GpuInfo.Gpus[0].Count,GpuInfo.Gpus[0].MemoryInfo.SizeInMiB]' \
--output text
The second command shows the vCPUs and the GPU model, count, and memory for a type. You will need the vCPU count in the next section.
The quota gotcha: vCPUs, not instances
GPU quotas are per Region and counted in vCPUs, not in number of instances. The two that matter are “Running On-Demand G and VT instances” and “Running On-Demand P instances”, and the table in the docs shows a default value of 0 for both. In other words: without asking for an increase, not even a g6.xlarge (4 vCPUs) will launch. A p5.48xlarge has 192 vCPUs, so the P quota must be at least 192 for a single instance. Stopped instances don’t count; Capacity Reservations do.
# 1. Find names, codes, and current values
aws service-quotas list-service-quotas --service-code ec2 --region us-east-1 \
--query "Quotas[?contains(QuotaName,'G and VT') || contains(QuotaName,'P instances')].[QuotaName,QuotaCode,Value]" \
--output table
# 2. Read a specific quota (use the code shown above)
aws service-quotas get-service-quota --service-code ec2 --quota-code <quota-code> --region us-east-1
# 3. Request an increase, in vCPUs
aws service-quotas request-service-quota-increase --service-code ec2 \
--quota-code <quota-code> --desired-value 16 --region us-east-1
# 4. Track the request
aws service-quotas list-requested-service-quota-change-history-by-quota \
--service-code ec2 --quota-code <quota-code> --region us-east-1
I left the codes (L-...) out of the commands because I could not confirm them in an official source during this review; step 1 shows the real codes for your account. Spot has its own quotas, separate from on-demand; look for them in the same listing (the G and VT filter usually brings them along) and, if you plan to use Spot, request an increase there too. Ask early and justify the use case, because GPU increases can take days. The flags were checked with aws service-quotas <cmd> help, and the JMESPath query was tested with the botocore Stubber against a sample response.
Finding the Deep Learning AMI
The AWS Deep Learning AMI (DLAMI) comes with the NVIDIA driver, CUDA, NCCL, and EFA preinstalled. The “Base OSS Nvidia Driver” variant has only the driver stack; there are also PyTorch variants and Amazon Linux 2023 variants (check the exact names in the docs). To get the latest one with Ubuntu 24.04:
aws ec2 describe-images --owners amazon --region us-east-1 \
--filters 'Name=name,Values=Deep Learning Base OSS Nvidia Driver GPU AMI (Ubuntu 24.04)*' 'Name=state,Values=available' \
--query 'sort_by(Images,&CreationDate)[-1].[ImageId,Name,RootDeviceName]' --output text
AWS also publishes DLAMI IDs as public SSM parameters, which is handier in pipelines. I did not confirm the exact parameter path during this review, so check the DLAMI docs before using one.
If you build your own AMI, respect each family’s minimum driver:
| Family | Minimum NVIDIA driver | CUDA |
|---|---|---|
| G7 | 595 | 13.2 |
| G7e | 575 | 12.9 |
| P6-B300 | 580 | 13.0 |
| P6-B200 / P6e-GB200 | 570 | 12.8 |
| P5e / P5en | 550 | 12.1 |
| P5 | 530 | 12.1 |
Launching the instance
The instance below sits in a private subnet with no SSH key: access goes through Session Manager, via an instance profile with the AmazonSSMManagedInstanceCore policy. IMDSv2 is required and the root volume is 200 GB, because model weights and pip caches fill disks fast. The root device name comes from the AMI’s RootDeviceName (/dev/sda1 on Ubuntu AMIs).
aws ec2 run-instances --region us-east-1 \
--image-id ami-0123456789abcdef0 --instance-type g6.xlarge --count 1 \
--subnet-id subnet-priv-a --security-group-ids sg-gpu \
--iam-instance-profile Name=gpu-ssm \
--block-device-mappings 'DeviceName=/dev/sda1,Ebs={VolumeSize=200,VolumeType=gp3,DeleteOnTermination=true}' \
--metadata-options HttpTokens=required \
--tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=gpu-lab},{Key=owner,Value=ml-team}]'
The command was run against a local mock (moto). With no AWS account in the lab, a real boot was not tested.
Checking the GPU: nvidia-smi and PyTorch
Once connected through Session Manager (aws ssm start-session --target <instance-id>), the first command is always:
nvidia-smi
It shows the GPU model, the driver version, the supported CUDA version, memory usage, and processes. If it fails, the problem is the driver or the AMI, not your code. Next, a quick PyTorch test (on the Base DLAMI, install PyTorch in a virtualenv; the PyTorch variants ship with it ready):
import torch
print("CUDA available:", torch.cuda.is_available())
if torch.cuda.is_available():
print("PyTorch CUDA version:", torch.version.cuda)
print("Visible GPUs:", torch.cuda.device_count())
print("GPU 0:", torch.cuda.get_device_name(0))
x = torch.randn(4096, 4096, device="cuda")
y = x @ x
torch.cuda.synchronize()
print("GPU matmul ok:", tuple(y.shape))
Honest warning: neither nvidia-smi nor this script was run for this article, because the lab has no NVIDIA GPU. The script only went through a syntax check.
Spot and Capacity Blocks for ML
Spot works on the G and P families (G7 and G7e included) and can be interrupted with a two-minute warning. It suits stateless inference behind a load balancer, batch jobs, and training with frequent checkpoints:
aws ec2 run-instances --image-id ami-0123456789abcdef0 --instance-type g6.xlarge \
--subnet-id subnet-priv-a --security-group-ids sg-gpu \
--instance-market-options 'MarketType=spot,SpotOptions={SpotInstanceType=one-time,InstanceInterruptionBehavior=terminate}'
Capacity Blocks for ML reserve GPU instances (or UltraServers) for a future window with fixed dates. Durations go in 1-day steps up to 14 days, then in 7-day steps up to 182 days. Each block holds up to 64 instances, with up to 256 across all blocks. It is the way out when you need guaranteed P5 or P6 capacity for a scheduled training run.
aws ec2 describe-capacity-block-offerings --instance-type p5.48xlarge \
--instance-count 1 --capacity-duration-hours 24 --region us-east-1
aws ec2 purchase-capacity-block --capacity-block-offering-id <offering-id> \
--instance-platform Linux/UNIX
# During the reserved window, launch targeting the reservation
aws ec2 run-instances --image-id ami-0123456789abcdef0 --instance-type p5.48xlarge \
--instance-market-options MarketType=capacity-block \
--capacity-reservation-specification 'CapacityReservationTarget={CapacityReservationId=cr-0123456789abcdef0}'
purchase-capacity-block is a purchase: review the dates, duration, and quantity before you run it. The parameters were validated with the Stubber; no purchase was made.
GPUs on EKS
On EKS, use the EKS-optimized accelerated AMIs. The AL2023 x86_64 NVIDIA variant covers g4dn through g7/g7e and p4d through p6-b300. The AL2023 ARM NVIDIA variant covers p6e-gb200/gb300 and g5g. Bottlerocket has the aws-k8s-nvidia variant (G7 requires EKS 1.37 or later). What exposes the GPU to the scheduler is the NVIDIA device plugin: eksctl installs it automatically, Bottlerocket already runs it, and otherwise you install the plugin yourself (for example, through NVIDIA’s official Helm chart; check the current version in the NVIDIA/k8s-device-plugin repository).
With the plugin running, the node advertises the nvidia.com/gpu resource and the pod requests a GPU under limits:
apiVersion: v1
kind: Pod
metadata:
name: cuda-check
namespace: ml
spec:
restartPolicy: Never
nodeSelector:
node.kubernetes.io/instance-type: g6.xlarge
tolerations:
- key: nvidia.com/gpu
operator: Exists
effect: NoSchedule
containers:
- name: cuda
image: nvcr.io/nvidia/cuda:12.8.0-base-ubuntu24.04
command: ["nvidia-smi"]
resources:
limits:
nvidia.com/gpu: 1
The toleration is only needed if your GPU nodes are tainted (a recommended practice so ordinary pods don’t land on expensive nodes). Pick a CUDA image tag that matches the node’s driver from NVIDIA’s catalog. kubectl --dry-run=client does not work without a cluster, so this YAML was only checked as valid YAML. For requests, limits, and taints, see Kubernetes scheduling and resources; for serving models, running LLMs on Kubernetes with vLLM.
Launch template in Terraform
For Auto Scaling groups, node groups, or Karpenter, the starting point is a launch template. Validated with terraform validate and terraform fmt -check (provider hashicorp/aws 6.74.0), with no plan or apply:
data "aws_ami" "dlami" {
most_recent = true
owners = ["amazon"]
filter {
name = "name"
values = ["Deep Learning Base OSS Nvidia Driver GPU AMI (Ubuntu 24.04)*"]
}
filter {
name = "state"
values = ["available"]
}
}
resource "aws_launch_template" "gpu" {
name_prefix = "gpu-inference-"
image_id = data.aws_ami.dlami.id
instance_type = "g6.xlarge"
iam_instance_profile {
name = var.instance_profile_name
}
network_interfaces {
subnet_id = var.subnet_id
security_groups = [var.gpu_sg_id]
associate_public_ip_address = false
}
block_device_mappings {
device_name = data.aws_ami.dlami.root_device_name
ebs {
volume_size = 200
volume_type = "gp3"
encrypted = true
delete_on_termination = true
}
}
metadata_options {
http_tokens = "required"
}
tag_specifications {
resource_type = "instance"
tags = {
Name = "gpu-inference"
owner = "ml-team"
}
}
}
Using the AMI’s own root_device_name avoids getting the root disk name wrong. For Spot, add an instance_market_options block with market_type = "spot".
Cost hygiene: a stopped GPU is a cheap GPU
No prices here, but the dimensions are clear: the instance per second or per hour while it is running (on-demand, Spot, or Capacity Block), EBS per GB-month even while the instance is stopped, snapshots, data transfer, and public IPv4. GPUs are the most expensive line in almost every ML bill, and the biggest waste is an instance left running with nothing to do.
List what is running in the G and P families, with its owner:
aws ec2 describe-instances --filters Name=instance-state-name,Values=running \
--query "Reservations[].Instances[?starts_with(InstanceType,'g') || starts_with(InstanceType,'p')][].[InstanceId,InstanceType,LaunchTime,Tags[?Key=='owner']|[0].Value]" \
--output table
And stop an idle lab instance automatically, with a CloudWatch alarm that uses the EC2 stop action (here, average CPU below 5% for one hour):
aws cloudwatch put-metric-alarm --alarm-name gpu-lab-idle \
--namespace AWS/EC2 --metric-name CPUUtilization \
--dimensions Name=InstanceId,Value=i-0123456789abcdef0 \
--statistic Average --period 300 --evaluation-periods 12 \
--threshold 5 --comparison-operator LessThanThreshold \
--alarm-actions arn:aws:automate:us-east-1:ec2:stop
Low CPU is a rough signal; to measure the GPU itself, publish its utilization with the CloudWatch agent. Both commands ran against moto. For the rest of the cleanup, read zombie cloud resources, FinOps: cut AWS costs, and FinOps for AI: cost per token.
Checklist
- Family chosen by workload (G for inference and graphics, P for training) and available in the Region
- On-demand and Spot G/P quotas requested in vCPUs, well in advance
- Latest DLAMI looked up by filter, not by an ID hardcoded in your code
- Instance in a private subnet, access through Session Manager, and IMDSv2 required
-
nvidia-smiandtorch.cuda.is_available()checked before running the real job - Spot or Capacity Blocks evaluated before leaving everything on-demand
- An
ownertag on every GPU instance and automatic stop for idle ones
A GPU in the cloud is like renting a Formula 1 car: worth every cent on the track and not one in the garage.