Automated AWS EC2 GPU instance launcher with ComfyUI and ComfyUI-Manager pre-installed. Launch powerful GPU workstations in minutes with automatic setup, live pricing, and one-command teardown. This script is something I put together to help anyone who needs a more powerful system for ComfyUI, workflow processing, or rendering. It automatically builds an EC2 instance, installs and configures everything, and then sets it up so you’re ready to start working as soon as the process completes.
You’ll need to have a paid AWS account and make sure your vCPU quota is high enough — you can check or increase this in the AWS Service Quotas or EC2 vCPU limits section of your account.
- One-Command Launch - Fully automated EC2 instance creation and setup
- Live Pricing - Real-time AWS pricing via Pricing API
- Automatic Key Management - Creates and saves SSH key pairs automatically
- Pre-installed Software - ComfyUI + ComfyUI-Manager ready to use
- Auto Browser Launch - Opens ComfyUI web UI when ready
- Security - Automatic security group configuration with your IP
- Easy Cleanup - One command to destroy all resources
- Multiple GPU Options - Support for g6, g6e, and p5 instance types
- Multi-Account Support - Target any AWS named profile with
--profile - Pre-Flight Checks - Verifies AWS connectivity and confirms the chosen instance type has quota/capacity before creating anything
- Python 3.7+
- AWS Account with appropriate permissions
- AWS CLI configured (
aws configureoraws sso login) - Required Python packages:
pip install boto3 requests
aws configure
# OR
aws sso loginpython aws_ai_box.py create
# or, to target a specific AWS profile/account:
python aws_ai_box.py create --profile workBefore touching AWS, the script confirms it can connect using your credentials and prints the account ID/ARN it's about to operate on — so you know exactly which account is in play.
Follow the interactive prompts to:
- Select AWS region (default: us-east-1)
- Choose instance type from the pricing table
- Confirm your public IP (auto-detected from several fallback services; you'll be prompted to enter it manually if all of them fail)
- Pick an Availability Zone, or leave blank to auto-try every AZ that offers the instance type until one has capacity
- Optionally specify a custom AMI
Once you've picked an instance type, the script checks that it's actually offered in your chosen region/AZ, checks your real vCPU service quota, and dry-run launches in each candidate AZ (in order) to find one with capacity — all before creating any real resources. If you pin a specific AZ and it turns out to have no capacity, the script fails fast with that AZ named rather than silently trying others.
Once launched, the script will:
- Display SSH connection command
- Wait for ComfyUI to be ready
- Automatically open the web UI in your browser
When finished:
python aws_ai_box.py destroy
# or:
python aws_ai_box.py destroy --profile workThis terminates the instance and cleans up security groups.
| Instance Type | GPU | vCPUs | RAM | VRAM | Est. Cost/hr |
|---|---|---|---|---|---|
| g6.xlarge | NVIDIA L4 | 4 | 16 GB | 24 GB | ~$0.55 |
| g6.8xlarge | NVIDIA L4 | 32 | 128 GB | 24 GB | ~$2.30 |
| g6.12xlarge | 4×NVIDIA L4 | 48 | 192 GB | 96 GB | ~$3.90 |
| g6e.xlarge | NVIDIA L4 | 4 | 16 GB | 24 GB | ~$0.65 |
| g6e.2xlarge | NVIDIA L4 | 8 | 32 GB | 24 GB | ~$1.10 |
| g6e.4xlarge | NVIDIA L4 | 16 | 64 GB | 24 GB | ~$2.00 |
| g6e.12xlarge | 3×NVIDIA L4 | 48 | 192 GB | 72 GB | ~$6.00 |
| g6e.12xlargw | 3×NVIDIA L4 (W-Opt) | 48 | 192 GB | 72 GB | ~$6.10 |
| g6e.24xlarge | 4×NVIDIA L4 | 96 | 384 GB | 96 GB | ~$8.50 |
| p5.4xlarge | NVIDIA H100 | 24 | 96 GB | 80 GB | ~$6.80 |
Prices are estimates and vary by region. Live pricing is shown when running the script.
- Default Instance:
g6e.4xlarge - Default Region:
us-east-1 - Security Group:
ai-g6e-box-sg - Open Ports: 22 (SSH), 8188 (ComfyUI), 7860 (Gradio), 8888 (Jupyter)
Use the --profile flag to target any named profile from your AWS CLI config (~/.aws/config / ~/.aws/credentials):
python aws_ai_box.py create --profile personal
python aws_ai_box.py create --profile workIf --profile is omitted, the script uses the AWS_PROFILE environment variable if set, otherwise your default profile. Run aws configure list-profiles to see what's available, and aws configure --profile <name> or aws sso login --profile <name> to set one up.
The script automatically finds the latest Deep Learning Base AMI with CUDA support. If unavailable, it falls back to:
- Latest Deep Learning Base AMI by name search
- Latest Ubuntu 22.04 AMI (requires manual NVIDIA driver installation)
You can also specify a custom AMI ID when prompted.
After launch, connect via SSH:
ssh ubuntu@<PUBLIC_IP> -i ai_box_key_<timestamp>.pemThe key file is automatically saved in the same directory as the script.
The instance comes with:
- ComfyUI - Web-based Stable Diffusion UI
- ComfyUI-Manager - Plugin manager for ComfyUI
- PyTorch with CUDA 12.1 support
- Python 3 with venv
- tmux - ComfyUI runs in a persistent tmux session
- Development tools - git, curl, wget, etc.
- Web UI:
http://<PUBLIC_IP>:8188 - tmux session:
tmux attach -t comfyui
Fixed: The script now handles duplicate security group rules gracefully.
Fixed: The script now dynamically finds the latest available AMI in your region.
The script tries several IP-echo services (checkip.amazonaws.com, ipify.org, ifconfig.me, icanhazip.com) in turn and, if all of them fail, prompts you to enter your IP manually — find it at whatismyip.com or run curl ifconfig.me.
The most common cause on macOS is CERTIFICATE_VERIFY_FAILED: a python.org-installed Python doesn't automatically trust the system's CA certificates. The script uses the requests library (which bundles its own trusted certs) specifically to avoid this, but if you still hit SSL errors elsewhere, run /Applications/Python\ 3.x/Install\ Certificates.command (from your Python.org install folder) or pip install --upgrade certifi. A restrictive proxy/firewall blocking outbound HTTPS can also cause this.
Before creating anything, the script runs three pre-flight checks: instance-type availability in the target region/AZ, a real vCPU service-quota lookup, and a dry-run launch (which catches permission/capacity issues but — per AWS's own design — not quota issues, since RunInstances DryRun only validates IAM permissions and request parameters).
- Not offered in region: pick a different region or instance type.
- vCPU quota too low / VcpuLimitExceeded / InstanceLimitExceeded: many new AWS accounts default to a 0 vCPU quota for GPU instance families (G/VT and P instances) until you explicitly request an increase. The script now checks this proactively and tells you the exact quota code and console link; you can also request it directly:
(
aws service-quotas request-service-quota-increase \ --service-code ec2 --quota-code L-DB2E81BA \ --desired-value 32 --region us-east-1
L-DB2E81BAis for G/VT instances — g6/g6e; useL-417A185Bfor P instances — p5. Increases can take from minutes to a day or two for AWS to approve.) - InsufficientInstanceCapacity: if you left the AZ prompt blank, the script already auto-tries every AZ that offers the instance type and only fails once none of them have capacity (it lists which AZs it tried). If you pinned a specific AZ, re-run and leave the AZ prompt blank to let it search all AZs, try again later, or fall back to a different instance type/region.
- SSH into instance and check logs:
tmux attach -t comfyui - Verify security group allows your IP on port 8188
- Ensure your IP hasn't changed since launch
- Check the key file permissions:
chmod 400 ai_box_key_*.pem - Verify security group rules in AWS console
Important: GPU instances are expensive!
- g6e.xlarge: ~$0.65/hour = ~$468/month if left running
- g6e.4xlarge: ~$2.00/hour = ~$1,440/month if left running
- p5.4xlarge: ~$6.80/hour = ~$4,896/month if left running
Always remember to destroy your instance when done:
python aws_ai_box.py destroySet up billing alerts in AWS to avoid unexpected charges.
- The script only allows SSH/HTTP access from your public IP
- SSH keys are created with 400 permissions
- Security groups are cleaned up on destroy
- All resources are tagged for easy identification
- us-east-1 (N. Virginia)
- us-east-2 (Ohio)
- us-west-1 (N. California)
- us-west-2 (Oregon)
Additional regions can be added by updating the REGION_LOCATION dictionary.
┌─────────────────┐
│ Your Machine │
│ (Run Script) │
└────────┬────────┘
│
├─ Verify AWS Connection (STS get-caller-identity)
├─ Check Instance Type Availability (region/AZ)
├─ Check vCPU Service Quota
├─ Dry-Run Capacity Check (per AZ, auto-fallback)
├─ Create Key Pair
├─ Setup Security Group
├─ Launch EC2 Instance
│ └─ Deep Learning Base AMI
│ └─ Auto-install ComfyUI
│
└─ Wait & Open Browser
↓
┌──────────────────┐
│ EC2 GPU Instance │
│ - NVIDIA Drivers │
│ - CUDA 12.1 │
│ - ComfyUI:8188 │
└──────────────────┘
.
├── aws_ai_box.py # Main launcher script
├── README.md # This file
└── ai_box_key_*.pem # Generated SSH keys (git ignored)
- Instance status command
- Support for more regions
- Spot instance support
- Custom user data scripts
- Multiple simultaneous instances
- Web dashboard
- Fixed: Public IP auto-detection silently failing due to
CERTIFICATE_VERIFY_FAILEDon some Python installs (notably python.org builds on macOS) — now usesrequestsinstead ofurllib, plus tries 4 fallback IP-echo services before prompting for manual entry. - Added:
--profileflag for multi-account support — target any named AWS CLI profile. - Added: Pre-flight AWS connectivity check (
sts get-caller-identity) that shows which account/ARN you're about to operate on before anything is created. - Added: Proactive vCPU service-quota check — catches accounts with a 0 vCPU GPU quota (the AWS default for new accounts) with an actionable fix, instead of failing deep into the launch with a raw
VcpuLimitExceedederror. - Added: Instance-type-availability check per region/AZ before launching.
- Added: Availability Zone selection — pick a specific AZ or auto-try every AZ that offers the instance type until one has capacity, instead of failing on the first
InsufficientInstanceCapacity. - Added:
.gitignoreso generated.pemkey files and__pycache__/are never accidentally committed.
This project is provided as-is for educational and development purposes.
Contributions are welcome! Please feel free to submit a Pull Request.
This tool creates AWS resources that incur costs. Users are responsible for:
- Monitoring and managing AWS costs
- Securing their instances and data
- Complying with AWS terms of service
- Following security best practices
Remember to destroy instances when not in use to avoid unnecessary charges!
For issues or questions:
- Check the Troubleshooting section above
- Review AWS CloudWatch logs
- Check AWS EC2 console for instance status
- Open an issue on GitHub
**Happy GPU Computing! **