This guide walks you through setting up AWS access and deploying your Flight server to AWS EC2 behind a Network Load Balancer.
- AWS Account: You need an active AWS account
- Java Application: Built JAR file (
mvn clean package) - AWS CLI: Installed and configured on your local machine
curl "https://awscli.amazonaws.com/AWSCLIV2.pkg" -o "AWSCLIV2.pkg"
sudo installer -pkg AWSCLIV2.pkg -target /curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/installDownload and run the AWS CLI MSI installer from: https://awscli.amazonaws.com/AWSCLIV2.msi
aws --version- Log into AWS Console: https://console.aws.amazon.com/
- Navigate to IAM: Services → IAM
- Create a User:
- Click "Users" → "Add users"
- Username:
flight-server-deployer - Select "Programmatic access"
- Attach Policies:
AmazonEC2FullAccessCloudFormationFullAccessElasticLoadBalancingFullAccessIAMFullAccess(for creating roles)
- Save Access Keys: Download the CSV file with your Access Key ID and Secret Access Key
aws configureEnter the following when prompted:
- AWS Access Key ID: Your access key from Step 2
- AWS Secret Access Key: Your secret key from Step 2
- Default region name:
us-east-1(or your preferred region) - Default output format:
json
aws sts get-caller-identityThis should return your account information.
You need an EC2 Key Pair for SSH access to your instance.
aws ec2 create-key-pair --key-name your-key-name --query 'KeyMaterial' --output text > your-key-name.pem
chmod 400 your-key-name.pem- Go to EC2 Console → Key Pairs
- Click "Create key pair"
- Name:
flight-server-key - Type: RSA
- Format: .pem
- Download and save the .pem file
- Set permissions:
chmod 400 flight-server-key.pem
mvn clean package./deploy-to-aws.shThe script will prompt you for:
- AWS Region: Default is
us-east-1 - EC2 Key Pair Name: Enter
flight-server-key(or your key name) - Instance Type: Default is
t3.medium - Allowed CIDR: Default is
0.0.0.0/0(allows access from anywhere)
-
VPC and Networking:
- New VPC with public subnets in 2 availability zones
- Internet Gateway and routing tables
- Security groups for EC2 and Load Balancer
-
EC2 Instance:
- Amazon Linux 2023 with Java 21 pre-installed
- Systemd service for the Flight server
- CloudWatch monitoring enabled
-
Network Load Balancer:
- Internet-facing NLB
- Target group pointing to EC2 instance
- Health checks on port 8815
-
Security:
- IAM role for EC2 instance
- Security groups allowing only necessary traffic
After deployment completes, you'll get output like:
Instance Public IP: 54.123.45.67
Load Balancer DNS: flight-server-nlb-1234567890.elb.us-east-1.amazonaws.com
Flight Server Endpoint: flight-server-nlb-1234567890.elb.us-east-1.amazonaws.com:8815
ssh -i flight-server-key.pem ec2-user@54.123.45.67sudo systemctl status flight-server
sudo journalctl -u flight-server -fUpdate your client code to connect to the load balancer endpoint:
Location location = Location.forGrpcInsecure("flight-server-nlb-1234567890.elb.us-east-1.amazonaws.com", 8815);ssh -i flight-server-key.pem ec2-user@54.123.45.67
sudo journalctl -u flight-server -fThe instance is configured with CloudWatch agent for centralized logging.
To avoid ongoing charges, delete the CloudFormation stack:
aws cloudformation delete-stack --stack-name flight-server-stack --region us-east-1-
Key Pair Not Found:
- Ensure the key pair exists in the correct region
- Check the key pair name spelling
-
Permission Denied (SSH):
- Check key file permissions:
chmod 400 your-key.pem - Verify you're using the correct key file
- Check key file permissions:
-
Service Not Starting:
- SSH to instance and check:
sudo systemctl status flight-server - Check logs:
sudo journalctl -u flight-server
- SSH to instance and check:
-
Load Balancer Health Check Failing:
- Verify the Flight server is running on port 8815
- Check security group rules
- Wait a few minutes for health checks to stabilize
-
Client Connection Issues:
- Ensure you're using the Load Balancer DNS name, not the instance IP
- Verify port 8815 is accessible
- Check that your client has the correct JVM arguments
Approximate monthly costs (us-east-1 region):
- t3.medium EC2 instance: ~$30/month
- Network Load Balancer: ~$16/month + data processing charges
- Data transfer: Varies based on usage
- Total: ~$50-60/month for basic usage
- Restrict Access: Change the
AllowedCIDRparameter to limit access to specific IP ranges - Key Management: Store your .pem files securely
- Regular Updates: Keep the EC2 instance updated with security patches
- Monitoring: Set up CloudWatch alarms for unusual activity
- Custom Domain: Set up a custom domain name pointing to your load balancer
- SSL/TLS: Configure SSL certificates for encrypted communication
- Auto Scaling: Add auto scaling groups for high availability
- Monitoring: Set up detailed CloudWatch monitoring and alerting