This repository provides two ways to deploy a Shadowsocks server on AWS EC2:
- Terraform (recommended): Infrastructure-as-code approach with declarative configuration
- Python Script: Automated deployment using the AWS SDK for Python (boto3)
Both methods leverage AWS services such as EC2, IAM, VPC, and security groups for streamlined setup.
- Automated Shadowsocks Deployment: Sets up a Shadowsocks server on an EC2 instance
- Infrastructure as Code (Terraform): Declarative configuration with version control
- Flexible Architecture: Support for both x86 (t3.nano) and ARM (t4g.nano) instances
- Secure Configuration: Configurable password and SSH access restrictions
- Predefined Security Rules: Automatically configures security groups for Shadowsocks and SSH traffic
- Systemd Service: Shadowsocks runs as a managed systemd service with auto-restart
- IPv6 Support: Optional IPv6-only mode (experimental)
- Secure Password Storage: Uses AWS SSM Parameter Store to securely store credentials
- IAM Role Management: Creates and assigns IAM roles for secure SSM access
- Terraform >= 1.6.0 (install instructions)
- AWS CLI configured with credentials (
aws configure) - AWS account with permissions to manage EC2, VPC, and security groups
- Clone this repository:
git clone https://github.com/yourusername/shadowsocks-aws.git
cd shadowsocks-aws- Initialize Terraform:
terraform init- (Optional) Customize variables by creating a
terraform.tfvarsfile:
aws_region = "ap-east-1" # AWS region
instance_type = "t4g.nano" # t3.nano (x86) or t4g.nano (ARM)
ss_password = "your-password" # Shadowsocks password
ssh_cidr = "1.2.3.4/32" # Restrict SSH to your IP- Deploy the infrastructure:
terraform apply- Get the connection details:
terraform outputThe Terraform configuration supports the following variables (see shadowsocks.tf):
aws_region- AWS region (default: "ap-east-1")instance_type- EC2 instance type: "t3.nano" or "t4g.nano" (default: "t4g.nano")amazon_linux_generation- AMI generation: "al2023" or "al2" (default: "al2023")ss_password- Shadowsocks password (default: "123", change in production)ssh_cidr- CIDR block for SSH access (default: "0.0.0.0/0", restrict to your IP)ipv6_only- Use IPv6 only instead of IPv4 (default: false, currently unsupported)
To destroy the infrastructure:
terraform destroy
⚠️ DEPRECATED: This deployment method is outdated and no longer actively maintained. Please use the Terraform deployment (Option 1) for new deployments. The Python script has the following limitations:
- Hardcoded, region-specific AMI ID that may be outdated
- No support for ARM instances (t4g.nano)
- No systemd service configuration (runs as background process)
- Requires additional AWS services (SSM Parameter Store, IAM roles)
- Less robust and harder to maintain
- AWS CLI: Ensure that the AWS CLI is installed and configured with appropriate credentials. To set up, use
aws configure
-
Ensure that your AWS account has permission to
- Manage EC2 instances
- Create IAM roles and policies
- Access SSM Parameter Store
-
Python 3.6 or higher
-
Install required dependencies using
pip install boto3
- Password Storage
- Security Group Setup
- IAM Role Creation
- EC2 Instance Launch
- Retrieve Public IP
- Clone this repository
git clone https://github.com/yourusername/shadowsocks-aws.git
cd shadowsocks-deployment
- Open the script and configure the following variables as needed, can be left as is
SHADOWSOCKS_PASSWORD: Set the password your clients will use to authenticate themselves to the serverINSTANCE_TYPE: Choose the EC@ instance typeAMI_ID: Specify the Amazon Machine Image (AMI) ID
- Execute the sscript:
python shadowsocks_deployment.py
- Upon successful deployment, the script will output the information needed to connect to the Shadowsocks server
- Public IP
- Port (default 8488)
- Shadowsocks password
- (Optional) Add
start.shtoec2-userhome for easy control
--- Shadowsocks ---
IP Address: 3.92.183.45
Port: 8488
Shadowsocks Password: insert_your_password_here
Optional uptime server
https://github.com/derekjtong/shadowsocks_status
- EC2 (Elastic Compute Cloud)
- VPC (Virtual Private Cloud)
- Security Groups
- AMI (Amazon Machine Images)
- EC2 (Elastic Compute Cloud)
- SSM Parameter Store (Secure password storage)
- IAM (Identity and Access Management)
- VPC Security Groups