cloudemu

Compute

VMs and instances — drive EC2 / Azure VMs / GCE with the real cloud SDK

Compute

Emulates VM/instance services: EC2 (AWS), Virtual Machines (Azure), Compute Engine (GCP).

ProviderServiceSDK-compatDriver
AWSEC2 + full VPC stack✓ Liveaws.EC2
AzureVirtual Machines + Disks/Snapshots/Images/SSH Keys✓ Liveazure.VirtualMachines
GCPCompute Engine + Disks/Snapshots/Images✓ Livegcp.GCE
import (
    "github.com/aws/aws-sdk-go-v2/service/ec2"
    "github.com/aws/aws-sdk-go-v2/service/ec2/types"
    "github.com/stackshy/cloudemu"
    awsserver "github.com/stackshy/cloudemu/server/aws"
)

cloud := cloudemu.NewAWS()
ts := httptest.NewServer(awsserver.New(awsserver.Drivers{
    EC2: cloud.EC2, VPC: cloud.VPC,
}))

client := ec2.NewFromConfig(cfg, func(o *ec2.Options) {
    o.BaseEndpoint = aws.String(ts.URL)
})

out, _ := client.RunInstances(ctx, &ec2.RunInstancesInput{
    ImageId:      aws.String("ami-0abcdef1234"),
    InstanceType: types.InstanceTypeT3Large,
    MinCount:     aws.Int32(1),
    MaxCount:     aws.Int32(3),
})

client.StopInstances(ctx, &ec2.StopInstancesInput{
    InstanceIds: []string{*out.Instances[0].InstanceId},
})

Same pattern with armcompute for Azure and cloud.google.com/go/compute/apiv1 for GCP — see SDK-Compat Server.

Operations supported via SDK-compat

EC2: RunInstances, DescribeInstances (filters: instance-id, instance-type, instance-state-name, tag:*), Start/Stop/Reboot/TerminateInstances, ModifyInstanceAttribute.

EC2 — VPC stack: VPCs, Subnets, Security Groups + ingress/egress rules, Internet Gateways, Route Tables + Routes, NAT Gateways, VPC Peering, Flow Logs, Network ACLs, EBS Volumes, Key Pairs, Snapshots, AMIs, Spot Instances, Launch Templates, Auto Scaling Groups + scaling policies.

Azure VMs: CreateOrUpdate, Get, List, Delete, start/powerOff/restart actions; full Disks/Snapshots/Images/SSHPublicKeys CRUD.

GCP Compute Engine: Instances + Disks + Snapshots + Images insert/get/list/delete with LRO envelopes.

Realistic behaviors

  • State machine enforces valid lifecycle transitions (pending → running → stopped → terminated). Illegal transitions return errors — same as real EC2.
  • Auto-metrics: RunInstances automatically pushes CPU, Network, and Disk metrics to the monitoring service. Stop/start/terminate emit matching values.
  • Lifecycle metric emission: every StartInstances / StopInstances / RebootInstances / TerminateInstances call writes corresponding metric values too.

Alternative: Portable Go API

aws.EC2.RunInstances(ctx, computedriver.InstanceConfig{
    ImageID: "ami-0abcdef1234", InstanceType: "t3.large",
}, 3)
aws.EC2.StopInstances(ctx, []string{instanceID})
aws.EC2.TerminateInstances(ctx, []string{instanceID})

Use the Portable API when you want direct in-process calls without the HTTP hop.

On this page