Compute Instance Management
Complete guide to managing Lambda compute instances.
Instance Lifecycle
Understanding the complete lifecycle of a Lambda instance.
Creating Instances
You can create instances using the Dashboard (recommended for beginners) or the CLI (for automation).
Option 1: Using the Dashboard
- Go to dashboard.lambda.io/instances
- Click "Create Instance"
- Fill in the configuration:
- Name:
my-instance - Type:
compute-4x - Region:
us-west-1 - Image:
ubuntu-22.04
- Name:
- (Optional) Add SSH keys, tags, and advanced options
- Click "Launch Instance"
Option 2: Using the CLI
Basic Creation:
lambda create instance \
--name my-instance \
--type compute-4x \
--region us-west-1 \
--image ubuntu-22.04Advanced Creation:
lambda create instance \
--name production-api \
--type compute-8x \
--region eu-west-1 \
--image ubuntu-22.04 \
--ssh-keys key_abc123,key_def456 \
--tags env=production,app=api,team=backend \
--encryption-key ~/.keys/master-key.pem \
--user-data ./cloud-init.sh \
--firewall-preset web-server \
--monitoring enabled \
--backup-schedule daily \
--waitCreation Options Explained
| Option | Description | Required |
|---|---|---|
--name | Instance name | Yes |
--type | Instance type (compute-, memory-, etc.) | Yes |
--region | Geographic region | Yes |
--image | OS image | Yes |
--ssh-keys | SSH key IDs (comma-separated) | No |
--tags | Key=value tags | No |
--encryption-key | Custom encryption key | No |
--user-data | Initialization script | No |
--firewall-preset | Preset firewall config | No |
--monitoring | Enable monitoring | No |
--backup-schedule | Auto-snapshot schedule | No |
--wait | Wait until ready | No |
Instance Types
Choosing the Right Type
Compute-Optimized (compute-*)
Best for:
- Web servers
- API backends
- Microservices
- CI/CD runners
- General purpose workloads
Specifications:
| Type | vCPU | RAM | Storage | Price/hr |
|---|---|---|---|---|
| compute-1x | 1 | 2 GB | 25 GB | $0.05 |
| compute-2x | 2 | 4 GB | 50 GB | $0.10 |
| compute-4x | 4 | 8 GB | 100 GB | $0.20 |
| compute-8x | 8 | 16 GB | 200 GB | $0.40 |
| compute-16x | 16 | 32 GB | 400 GB | $0.80 |
| compute-32x | 32 | 64 GB | 800 GB | $1.60 |
Memory-Optimized (memory-*)
Best for:
- Databases (PostgreSQL, MySQL, MongoDB)
- Redis/Memcached
- Elasticsearch
- Big data analytics
- In-memory processing
Specifications:
| Type | vCPU | RAM | Storage | Price/hr |
|---|---|---|---|---|
| memory-2x | 2 | 16 GB | 50 GB | $0.15 |
| memory-4x | 4 | 32 GB | 100 GB | $0.30 |
| memory-8x | 8 | 64 GB | 200 GB | $0.60 |
| memory-16x | 16 | 128 GB | 400 GB | $1.20 |
| memory-32x | 32 | 256 GB | 800 GB | $2.40 |
Storage-Optimized (storage-*)
Best for:
- Data warehouses
- Log aggregation
- Search engines
- Time-series databases
- High-throughput workloads
Specifications:
| Type | vCPU | RAM | Storage | IOPS | Price/hr |
|---|---|---|---|---|---|
| storage-2x | 2 | 8 GB | 500 GB | 10K | $0.20 |
| storage-4x | 4 | 16 GB | 1 TB | 20K | $0.40 |
| storage-8x | 8 | 32 GB | 2 TB | 40K | $0.80 |
| storage-16x | 16 | 64 GB | 4 TB | 80K | $1.60 |
GPU-Enabled (gpu-*)
Best for:
- Machine learning training
- Deep learning inference
- Video transcoding
- Scientific computing
- Graphics rendering
Specifications:
| Type | GPU | vCPU | RAM | Storage | Price/hr |
|---|---|---|---|---|---|
| gpu-1x | 1x A100 40GB | 8 | 64 GB | 500 GB | $2.50 |
| gpu-2x | 2x A100 40GB | 16 | 128 GB | 1 TB | $5.00 |
| gpu-4x | 4x A100 40GB | 32 | 256 GB | 2 TB | $10.00 |
| gpu-h100-1x | 1x H100 80GB | 8 | 128 GB | 1 TB | $4.00 |
| gpu-h100-2x | 2x H100 80GB | 16 | 256 GB | 2 TB | $8.00 |
Managing Instances
Listing Instances
# List all instances
lambda list instances
# Filter by status
lambda list instances --status running
# Filter by region
lambda list instances --region us-west-1
# Filter by tags
lambda list instances --tag env=production
# JSON output
lambda list instances --output jsonGetting Instance Details
# Basic info
lambda status inst_abc123
# Detailed info
lambda info inst_abc123 --verbose
# JSON output
lambda info inst_abc123 --output jsonStarting, Stopping, and Restarting
Via Dashboard:
- Go to Dashboard → Instances
- Click on your instance
- Use action buttons:
- Start - Power on stopped instance
- Stop - Gracefully shut down
- Force Stop - Immediate shutdown
- Restart - Reboot instance
Via CLI:
# Start stopped instance
lambda start inst_abc123
# Stop running instance
lambda stop inst_abc123
# Force stop (immediate, no graceful shutdown)
lambda stop inst_abc123 --force
# Restart instance
lambda restart inst_abc123
# All with wait flag
lambda start inst_abc123 --waitResizing Instances
Via Dashboard:
- Go to your instance page
- Click "Resize" button
- Select new instance type
- Click "Resize Instance"
- Instance will restart automatically with new resources
Via CLI:
# Resize to larger type
lambda resize inst_abc123 --type compute-8x
# Resize with wait
lambda resize inst_abc123 --type memory-16x --wait
# Check if resize requires restart
lambda resize inst_abc123 --type storage-4x --dry-runNote: Resizing causes brief downtime (typically 30-60 seconds).
Instance Configuration
User Data (Cloud-Init)
Execute scripts at instance creation:
# Create init script
cat > init.sh << 'EOF'
#!/bin/bash
apt update && apt upgrade -y
apt install -y nginx docker.io
systemctl enable nginx
systemctl start nginx
echo "Setup complete" > /var/log/init-complete.log
EOF
# Create instance with user data
lambda create instance \
--name auto-configured \
--type compute-4x \
--region us-west-1 \
--image ubuntu-22.04 \
--user-data init.shMetadata Service
Access instance metadata from within the instance:
# Get instance ID
curl http://169.254.169.254/latest/meta-data/instance-id
# Get instance type
curl http://169.254.169.254/latest/meta-data/instance-type
# Get public IP
curl http://169.254.169.254/latest/meta-data/public-ipv4
# Get user data
curl http://169.254.169.254/latest/user-dataTags
Organize and filter instances with tags:
# Add tags
lambda tag add inst_abc123 \
env=production \
app=api \
version=2.0
# List tags
lambda tag list inst_abc123
# Remove tag
lambda tag remove inst_abc123 env
# Filter by tags
lambda list instances --tag env=production,app=apiNetworking
Public vs Private IPs
Public IP:
- Accessible from internet
- Static (doesn't change)
- Used for external access
- Can be released and reassigned
Private IP:
- Used for instance-to-instance communication
- Never exposed to internet
- Free data transfer between instances
- Assigned automatically
# Get network info
lambda network info inst_abc123
# Assign public IP
lambda network assign-ip inst_abc123
# Release public IP (makes instance private-only)
lambda network release-ip inst_abc123DNS
Lambda provides automatic DNS for instances:
inst_abc123.lambda.io → 203.0.113.42
inst_abc123.internal → 10.0.1.5Storage Management
Root Volume
Every instance has a root volume:
- Contains OS and system files
- Size determined by instance type
- Encrypted with your keys
- Persists when instance is stopped
- Deleted when instance is destroyed
Attached Volumes
Add extra storage:
# Create volume
lambda create volume \
--name app-data \
--size 500GB \
--region us-west-1
# Attach to instance
lambda attach volume vol_abc123 --instance inst_xyz789
# Inside instance, mount it
ssh lambda@instance-ip
sudo mkfs.ext4 /dev/vdb
sudo mount /dev/vdb /mnt/data
# Detach volume
lambda detach volume vol_abc123Resize Root Volume
# Resize volume
lambda volume resize vol_abc123 --size 200GB
# Expand filesystem (inside instance)
ssh lambda@instance-ip
sudo resize2fs /dev/vda1Backups & Snapshots
Manual Snapshots
Via Dashboard:
- Go to Dashboard → Instances
- Click on your instance
- Go to "Snapshots" tab
- Click "Create Snapshot"
- Enter name and description
- Click "Create"
To restore: Go to "Snapshots" section, select snapshot, click "Create Instance from Snapshot"
Via CLI:
# Create snapshot
lambda snapshot create inst_abc123 \
--name "pre-deploy-$(date +%Y%m%d)" \
--description "Backup before deployment"
# List snapshots
lambda snapshot list --instance inst_abc123
# Restore from snapshot
lambda create instance \
--from-snapshot snap_abc123 \
--name restored-instance
# Delete snapshot
lambda snapshot delete snap_abc123Scheduled Snapshots
Via Dashboard:
- Go to your instance → "Snapshots" tab
- Click "Schedule Automatic Snapshots"
- Configure:
- Frequency: Daily/Weekly/Monthly
- Time: Select hour (UTC)
- Retention: Number of snapshots to keep
- Click "Save Schedule"
Via CLI:
# Daily at 2 AM UTC, keep 7 days
lambda snapshot schedule inst_abc123 \
--frequency daily \
--time "02:00" \
--retain 7
# Weekly on Sunday, keep 4 weeks
lambda snapshot schedule inst_abc123 \
--frequency weekly \
--day sunday \
--retain 4
# View snapshot schedule
lambda snapshot schedule inst_abc123 --show
# Disable schedule
lambda snapshot schedule inst_abc123 --disableMonitoring
Real-Time Metrics
Via Dashboard (Recommended):
- Go to Dashboard → Instances
- Click on your instance
- View the "Metrics" tab for:
- CPU usage graphs
- Memory utilization
- Network traffic
- Disk I/O
- Custom time ranges
Via CLI:
# View live metrics
lambda metrics inst_abc123
# Specific metric
lambda metrics inst_abc123 --metric cpu
lambda metrics inst_abc123 --metric memory
lambda metrics inst_abc123 --metric network
# Time period
lambda metrics inst_abc123 --period 24h --metric cpuAlerts
Via Dashboard:
- Go to your instance → "Alerts" tab
- Click "Create Alert"
- Configure:
- Name:
High CPU - Metric: CPU
- Condition:
> 80% - Duration:
5 minutes - Notification: Email/Webhook/Slack
- Name:
- Click "Create Alert"
Via CLI:
# Create alert
lambda alert create inst_abc123 \
--name "High CPU" \
--condition "cpu > 80" \
--duration "5m" \
--notify email:ops@example.com
# List alerts
lambda alert list inst_abc123
# Delete alert
lambda alert delete alert_abc123Health Checks
# Enable health checks
lambda health-check enable inst_abc123 \
--type http \
--path "/health" \
--port 80 \
--interval 30s
# View health status
lambda health-check status inst_abc123Security
Firewall Rules
# Allow HTTP
lambda firewall allow inst_abc123 \
--port 80 \
--source 0.0.0.0/0
# Allow SSH from specific IP
lambda firewall allow inst_abc123 \
--port 22 \
--source 203.0.113.0/24
# List rules
lambda firewall list inst_abc123
# Remove rule
lambda firewall remove inst_abc123 --rule rule_abc123SSH Key Management
# List keys on instance
lambda ssh-keys list --instance inst_abc123
# Add key to instance
lambda ssh-keys update inst_abc123 --add key_new123
# Remove key from instance
lambda ssh-keys update inst_abc123 --remove key_old123Security Hardening
# Run security audit
lambda security audit inst_abc123
# Apply hardening
lambda security harden inst_abc123 \
--disable-root \
--force-key-auth \
--enable-firewall \
--auto-updatesCost Optimization
Stop Unused Instances
# Stop instance (pay only for storage)
lambda stop inst_abc123
# Savings: ~90% (still pay for storage)Right-Sizing
# Check utilization
lambda metrics inst_abc123 --period 7d
# If consistently < 50% CPU/memory, downsize
lambda resize inst_abc123 --type compute-2xUse Spot Instances (Coming Soon)
For non-critical workloads, spot instances offer 60-80% discounts.
Automation
Using API
from lambda_sdk import Lambda
lambda_client = Lambda(api_key='λ_sk_...')
# Create instance
instance = lambda_client.instances.create(
name='auto-instance',
instance_type='compute-4x',
region='us-west-1',
image='ubuntu-22.04'
)
# Wait until ready
instance.wait_until_ready()
# Deploy application
instance.ssh_execute('git clone https://github.com/user/app')
# Create snapshot
snapshot = instance.create_snapshot(name='deployed')Terraform
resource "lambda_instance" "web" {
name = "web-server"
type = "compute-4x"
region = "us-west-1"
image = "ubuntu-22.04"
ssh_keys = [lambda_ssh_key.deploy.id]
tags = {
Environment = "production"
Application = "web"
}
}
resource "lambda_firewall_rule" "http" {
instance_id = lambda_instance.web.id
port = 80
source = "0.0.0.0/0"
protocol = "tcp"
}Best Practices
1. Use Tags for Organization
lambda tag add inst_abc123 \
env=production \
app=api \
team=backend \
cost-center=engineering2. Enable Automatic Backups
lambda snapshot schedule inst_abc123 \
--frequency daily \
--retain 73. Set Up Monitoring
lambda monitoring enable inst_abc123 \
--alerts cpu,memory,disk \
--notify email:team@example.com4. Use Security Groups
Create reusable firewall presets:
lambda firewall-preset create web-server \
--allow 80/tcp \
--allow 443/tcp \
--allow 22/tcp:203.0.113.0/245. Document Instance Purpose
lambda instance update inst_abc123 \
--description "Production API server - handles user authentication"Next Step
Secure your instances with our best practices guide.
Think Lambda, Think Privacy
