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
- 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 main.py createFollow the interactive prompts to:
- Select AWS region (default: us-east-1)
- Choose instance type from the pricing table
- Confirm your public IP (auto-detected)
- Optionally specify a custom AMI
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 main.py destroyThis 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)
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.
- Check instance is running:
python main.py status(if implemented) - 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 main.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) │
└────────┬────────┘
│
├─ 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 │
└──────────────────┘
.
├── main.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
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! **