Virtual Machines
A VM is a VM: pick an image, a size, a network, a disk and an identity. The differences are in the naming of sizes, the default network exposure, how you log in, and the discount and Spot options.
On AWS this is… EC2 instances, AMIs, instance types like
m7g.large, key pairs, user data and pricing models, from Amazon EC2, EC2 Instance Types and EC2 Pricing Models.
Side by side
| AWS EC2 | Azure Virtual Machines | Google Compute Engine | |
|---|---|---|---|
| Image | AMI (regional) | image from the Marketplace or an Azure Compute Gallery | image (global) in an image project, image families (debian-12) |
| Size | instance type m7i.large |
VM size Standard_D2s_v5 |
machine type e2-medium, n2-standard-4, or custom (--custom-cpu, --custom-memory) |
| Boot script | user data | custom data (cloud-init) or the Custom Script Extension | startup-script metadata |
| SSH | key pair | --generate-ssh-keys / --ssh-key-values, or Entra ID login |
OS Login (IAM-controlled SSH) or project/instance SSH keys in metadata |
| Bastion | Session Manager, EC2 Instance Connect | Azure Bastion, az ssh vm |
IAP TCP forwarding (gcloud compute ssh --tunnel-through-iap) |
| Stop and stop paying for compute | stop | deallocate (a stopped-but-allocated VM is still billed) | stop |
| Spot | Spot Instances | Azure Spot VMs (--priority Spot) |
Spot VMs (--provisioning-model=SPOT) |
| Commitments | Savings Plans, Reserved Instances | Reservations, Azure savings plan for compute | committed use discounts (resource- or spend-based), sustained use discounts applied automatically on some families |
| Dedicated hosts | Dedicated Hosts | Dedicated Host | sole-tenant nodes |
The deallocate row costs people money. In Azure, az vm stop powers off the OS but keeps the hardware reserved, and you keep paying for compute. az vm deallocate releases it. Shutting down from inside the OS has the same "stopped, not deallocated" effect.
Reading size names
Size names encode the family, the vCPU count and features. A small parser for the common patterns:
import re
def azure_size(name):
# Standard_<family><vcpus><features>_v<version>, e.g. Standard_D4as_v5
m = re.fullmatch(r"Standard_([A-Z]+)(\d+)([a-z]*)_v(\d+)", name)
family, vcpus, feats, ver = m.groups()
flags = {"a": "AMD", "p": "Arm", "d": "local temp disk", "s": "premium SSD capable",
"l": "low memory", "m": "more memory", "i": "isolated"}
return f"family {family}, {vcpus} vCPU, v{ver}, " + ", ".join(flags[c] for c in feats if c in flags)
def gcp_type(name):
# <series>-<shape>-<vcpus>, e.g. n2-highmem-8; e2-medium is a fixed shared-core size
parts = name.split("-")
if len(parts) == 2:
return f"series {parts[0]}, predefined size '{parts[1]}'"
series, shape, vcpus = parts
gib_per_vcpu = {"standard": 4, "highmem": 8, "highcpu": 1}[shape]
return f"series {series}, {vcpus} vCPU, {shape}: ~{gib_per_vcpu * int(vcpus)} GiB memory"
for n in ["Standard_D2s_v5", "Standard_D4as_v5", "Standard_E8ds_v5", "Standard_D4ps_v6"]:
print(f"{n:<18} {azure_size(n)}")
for n in ["e2-medium", "n2-standard-4", "n2-highmem-8", "n2-highcpu-16"]:
print(f"{n:<18} {gcp_type(n)}")Standard_D2s_v5 family D, 2 vCPU, v5, premium SSD capable
Standard_D4as_v5 family D, 4 vCPU, v5, AMD, premium SSD capable
Standard_E8ds_v5 family E, 8 vCPU, v5, local temp disk, premium SSD capable
Standard_D4ps_v6 family D, 4 vCPU, v6, Arm, premium SSD capable
e2-medium series e2, predefined size 'medium'
n2-standard-4 series n2, 4 vCPU, standard: ~16 GiB memory
n2-highmem-8 series n2, 8 vCPU, highmem: ~64 GiB memory
n2-highcpu-16 series n2, 16 vCPU, highcpu: ~16 GiB memory
The memory ratios are typical, not exact for every series (some highcpu shapes have 2 GiB per vCPU, for example); check the machine-type list for the series you pick. Roughly, families map like this:
| Workload | AWS | Azure | Google Cloud |
|---|---|---|---|
| General purpose | M, T (burstable) | D, B (burstable) | E2, N2/N4, C3/C4 |
| Memory optimised | R, X | E, M | M-series, highmem shapes |
| Compute optimised | C | F, FX | C-series highcpu, H-series |
| Arm | Graviton (g suffix) |
Cobalt / Ampere (p in the size) |
Axion (C4A), Tau T2A |
| GPU | P, G | NC, ND, NV | A-series, G-series, or GPUs attached to N1 |
Creating a VM
Azure, sample session: a private VM pinned to zone 1, using a managed identity, no public IP.
az vm create -g rg-shop-dev-app -n vm-api-1 \
--image Ubuntu2404 --size Standard_D2s_v5 --zone 1 \
--vnet-name vnet-shop-dev --subnet snet-app --public-ip-address "" --nsg "" \
--assign-identity [system] \
--admin-username azureuser --generate-ssh-keys \
--custom-data cloud-init.yaml
az vm deallocate -g rg-shop-dev-app -n vm-api-1 # stop paying for compute--public-ip-address "" and --nsg "" stop az vm create from creating a public IP and a per-NIC NSG, which it does by default, convenient for tutorials and wrong for production.
Google Cloud, sample session: the equivalent, with OS Login and Shielded VM.
gcloud compute instances create api-1 --zone=europe-west1-b \
--machine-type=e2-standard-2 --image-family=debian-12 --image-project=debian-cloud \
--subnet=app-ew1 --no-address \
--service-account=shop-api@shop-dev-4821.iam.gserviceaccount.com --scopes=cloud-platform \
--metadata=enable-oslogin=TRUE --metadata-from-file=startup-script=startup.sh \
--shielded-secure-boot
gcloud compute ssh api-1 --zone=europe-west1-b --tunnel-through-iap--no-address means no external IP. IAP TCP forwarding then gives SSH without a bastion host, as long as a firewall rule allows 35.235.240.0/20 (IAP's range) on port 22.
Spot, sample:
az vm create ... --priority Spot --eviction-policy Deallocate --max-price -1
gcloud compute instances create ... --provisioning-model=SPOT --instance-termination-action=STOPBoth can reclaim capacity with about 30 seconds of notice. Use them for stateless, interruptible work, the same as AWS Spot.
Test yourself
You run az vm stop on an Azure VM. Are you still paying for its compute?
- No
- Yes: it is stopped but still allocated; use
az vm deallocate - Only for the disk
- Only in production subscriptions
What does the s in Standard_D4s_v5 indicate?
- Spot
- Premium SSD capable
- Small
- Shared core
How can you SSH to a Compute Engine VM that has no external IP and no bastion?
- You can't
gcloud compute ssh --tunnel-through-iapwith a firewall rule for IAP's range- Through Cloud NAT
- With a service account key