Automatically deploy a web game to an EC2 server whenever a new
game.zipis uploaded to Amazon S3.
Introduction
In this project, I built a simple but practical serverless CI/CD deployment pipeline on AWS using Amazon S3, AWS Lambda, AWS Systems Manager, Amazon EC2, IAM, CloudWatch, and Nginx.
The application itself is a small browser-based Neon Snake game. However, the main purpose of the project is not the game—it is the automated deployment architecture behind it.
The idea is simple:
Upload game.zip → S3 detects the upload → Lambda is triggered → Lambda sends a command through SSM → EC2 downloads and extracts the game → Nginx serves it → The game becomes available in the browser.
This project demonstrates how different AWS services can work together to create a lightweight deployment pipeline without manually logging into the EC2 server every time a new version is released.
Architecture
The complete architecture looks like this:
┌─────────────────────┐
│ Developer │
│ Upload game.zip │
└──────────┬──────────┘
│
▼
┌─────────────────────┐
│ Amazon S3 │
│ neon-snake-artifacts│
│ game.zip │
└──────────┬──────────┘
│
Object Created
│
▼
┌─────────────────────┐
│ AWS Lambda │
│ SnakeDeployer │
└──────────┬──────────┘
│
SSM SendCommand
│
▼
┌─────────────────────┐
│ AWS Systems Manager │
│ Run Command │
└──────────┬──────────┘
│
▼
┌─────────────────────┐
│ Amazon EC2 │
│ NeonSnakeServer │
│ Amazon Linux 2023 │
└──────────┬──────────┘
│
Download & Extract
│
▼
┌─────────────────────┐
│ Nginx │
│ Web Server │
└──────────┬──────────┘
│
▼
┌─────────────────────┐
│ Browser │
│ Neon Snake Game │
└─────────────────────┘
AWS Service Relationships
-
Amazon S3 — stores the deployment artifact (
game.zip) - AWS Lambda — reacts to the S3 upload
- AWS Systems Manager (SSM) — executes deployment commands on EC2
- Amazon EC2 — hosts the game
- Nginx — serves the HTML game
- IAM — controls permissions between services
- CloudWatch — provides Lambda logs and monitoring
1. Project Objective
The objective was to create a deployment workflow where the developer does not need to manually copy files to the web server.
Instead, the deployment should work like this:
Developer
↓
Upload game.zip
↓
Amazon S3
↓
S3 Event
↓
AWS Lambda
↓
AWS Systems Manager
↓
EC2
↓
Nginx
↓
Live Website
This is a simple example of event-driven deployment automation.
2. Creating the S3 Artifact Bucket
The first component is Amazon S3.
I created an S3 bucket:
neon-snake-artifacts-toqeer123
The bucket was created in:
us-east-1
The purpose of this bucket is to store the application deployment package.
The package is:
game.zip
The ZIP contains the web application files, including:
index.html
README.txt
The important point is that S3 is not hosting the game for users in this architecture.
Instead, S3 acts as the artifact storage location.
3. Creating the EC2 Server
Next, I created an EC2 instance named:
NeonSnakeServer
The instance uses:
Amazon Linux 2023
and a small instance type:
t3.micro
The EC2 server is responsible for hosting the actual web application.
Nginx Installation
Nginx was installed on the EC2 instance.
Nginx serves files from:
/usr/share/nginx/html
Initially, this directory contained the default Nginx files.
After deployment, the application files are placed in the same directory.
4. EC2 IAM Role
The EC2 instance needs permission to communicate with AWS services.
I attached the IAM role:
iam_role_snake_server
The important permissions include:
AmazonSSMManagedInstanceCore
AmazonS3ReadOnlyAccess
These permissions allow the EC2 instance to:
- Connect to AWS Systems Manager
- Receive SSM commands
- Read the deployment artifact from S3
This is important because the EC2 server needs to download:
s3://neon-snake-artifacts-toqeer123/game.zip
5. AWS Systems Manager
One of the important components of this project is AWS Systems Manager (SSM).
Instead of connecting to the EC2 server through SSH and manually running commands, Lambda can send commands to the instance through SSM.
The deployment commands can perform tasks such as:
aws s3 cp s3://bucket/game.zip /tmp/game.zip
Then:
unzip -o /tmp/game.zip -d /tmp/deploy_temp/
Then the application files can be copied to:
/usr/share/nginx/html/
Finally:
systemctl restart nginx
This makes the deployment process automated.
6. Creating the Lambda Function
The next component is AWS Lambda.
I created a Lambda function named:
SnakeDeployer
The Lambda function is responsible for receiving the S3 event and starting the deployment process.
The basic logic is:
import boto3
import urllib.parse
ssm = boto3.client('ssm')
def lambda_handler(event, context):
bucket = event['Records'][0]['s3']['bucket']['name']
key = urllib.parse.unquote_plus(
event['Records'][0]['s3']['object']['key']
)
commands = [
f"aws s3 cp s3://{bucket}/{key} /tmp/game.zip",
"sudo rm -rf /usr/share/nginx/html/*",
"sudo mkdir -p /tmp/deploy_temp",
"sudo unzip -o /tmp/game.zip -d /tmp/deploy_temp/",
"sudo mv /tmp/deploy_temp/* /usr/share/nginx/html/",
"sudo rm -rf /tmp/deploy_temp /tmp/game.zip",
"sudo systemctl restart nginx"
]
ssm.send_command(
Targets=[
{
'Key': 'tag:Name',
'Values': ['NeonSnakeServer']
}
],
DocumentName="AWS-RunShellScript",
Parameters={
'commands': commands
}
)
return {
"status": "Snake Deployed successfully"
}
The Lambda function does not directly log into EC2.
Instead, it uses:
AWS Systems Manager → Run Command
to execute the deployment commands.
7. Lambda IAM Permissions
Lambda also needs an IAM execution role.
I used:
iam_role_snake_deployer
The role needs permissions required to perform the deployment workflow.
Important permissions include:
AWSLambdaBasicExecutionRole
AmazonSSMFullAccess
AmazonS3ReadOnlyAccess
The most important permission for the deployment action is the ability to send commands through SSM.
Without the required SSM permission, Lambda can be triggered successfully but the deployment command will fail with an authorization error.
This was one of the important troubleshooting points during the project.
8. Connecting S3 to Lambda
The next step was creating an S3 event trigger for Lambda.
The event is:
Object Created
So whenever a new object is uploaded to the bucket, S3 can trigger:
SnakeDeployer
For example:
Upload game.zip
↓
S3 Object Created
↓
SnakeDeployer Lambda
This is what makes the deployment event-driven.
9. The Complete Deployment Process
Now let's understand the complete workflow.
Step 1 — Developer uploads the application
The developer uploads:
game.zip
to:
neon-snake-artifacts-toqeer123
Step 2 — S3 detects the upload
S3 generates an object-created event.
Step 3 — Lambda receives the event
The event contains information such as:
Bucket name
Object key
Lambda reads this information.
Step 4 — Lambda sends an SSM command
Lambda calls:
ssm.send_command()
and targets:
NeonSnakeServer
Step 5 — EC2 downloads the ZIP
The EC2 instance runs:
aws s3 cp s3://neon-snake-artifacts-toqeer123/game.zip /tmp/game.zip
Step 6 — ZIP is extracted
The deployment package is extracted:
unzip -o /tmp/game.zip -d /tmp/deploy_temp/
Step 7 — Application files are deployed
The files are copied to:
/usr/share/nginx/html/
Step 8 — Nginx restarts
systemctl restart nginx
Step 9 — Browser accesses the application
The user opens the EC2 public IP through HTTP.
The browser receives the HTML application from Nginx.
10. Troubleshooting During Deployment
One of the most useful parts of this project was troubleshooting the deployment.
Initially, the Lambda invocation showed an:
AccessDeniedException
This indicated that the Lambda execution role did not have the required permissions.
After checking the Lambda execution role, the required SSM/S3 permissions were added.
Another important test was checking whether EC2 could actually download the artifact from S3.
I manually tested:
rm -f /tmp/game.zip
aws s3 cp \
s3://neon-snake-artifacts-toqeer123/game.zip \
/tmp/game.zip
ls -lh /tmp/game.zip
The download was successful:
download: s3://neon-snake-artifacts-toqeer123/game.zip
to ../../tmp/game.zip
-rw-r--r--. 1 root root 2.3K /tmp/game.zip
This confirmed that:
EC2 → S3
connectivity and permissions were working correctly.
11. Testing the ZIP Extraction
After downloading the ZIP, I tested the extraction manually:
rm -rf /tmp/deploy_temp
mkdir -p /tmp/deploy_temp
unzip -o /tmp/game.zip -d /tmp/deploy_temp
ls -lah /tmp/deploy_temp
The result showed:
README.txt
index.html
This confirmed that the deployment package itself was valid.
12. Deploying the Game to Nginx
The extracted files were then copied into the Nginx web directory:
rm -rf /usr/share/nginx/html/*
cp -r /tmp/deploy_temp/* \
/usr/share/nginx/html/
systemctl restart nginx
The final directory contained:
README.txt
index.html
and Nginx restarted successfully.
This confirmed that the application was successfully deployed on the EC2 server.
13. Why Use SSM Instead of SSH?
A major advantage of this architecture is that deployment does not require traditional SSH access.
With SSH-based deployment, we would typically need:
SSH key
↓
Server login
↓
Manual commands
↓
File transfer
↓
Restart service
With Systems Manager:
Lambda
↓
SSM Run Command
↓
EC2
This provides a more AWS-native approach to remote command execution.
It also reduces the need to expose SSH access for the deployment process.
14. IAM and Security
IAM is one of the most important parts of this architecture.
There are two major roles:
EC2 Role
iam_role_snake_server
Used by EC2.
Its job includes:
Read deployment artifact from S3
Communicate with Systems Manager
Lambda Role
iam_role_snake_deployer
Used by Lambda.
Its job includes:
Write Lambda logs
Send commands through SSM
Access required S3 resources
The overall principle is:
Give each AWS service only the permissions required to perform its job.
For a production system, these broad managed policies should ideally be replaced with more restrictive custom IAM policies using specific resources and actions.
15. Monitoring with CloudWatch
Lambda automatically integrates with Amazon CloudWatch Logs.
This makes it possible to inspect:
- Lambda invocations
- Errors
- Execution information
- Permission problems
- Runtime exceptions
For example, when the Lambda initially returned an AccessDeniedException, CloudWatch/Lambda execution information helped identify that the problem was related to permissions.
Monitoring is important because an automated pipeline should not silently fail.
16. Project Folder Structure
The deployment package is simple:
game.zip
│
├── index.html
└── README.txt
The important requirement is that index.html is available at the expected location after extraction.
The deployed application ultimately becomes:
/usr/share/nginx/html/
│
├── index.html
└── README.txt
Nginx then serves index.html as the website.
17. Technologies Used
| Technology | Purpose |
|---|---|
| Amazon S3 | Store deployment artifact |
| AWS Lambda | Trigger deployment |
| AWS Systems Manager | Execute commands on EC2 |
| Amazon EC2 | Host application |
| Nginx | Web server |
| IAM | Permissions and access control |
| CloudWatch | Logging and monitoring |
| HTML/CSS/JavaScript | Neon Snake game |
18. What Makes This a CI/CD Project?
The project demonstrates an important CI/CD concept:
A new application artifact can automatically trigger deployment.
Traditional manual deployment:
Build
↓
Copy files manually
↓
Login to server
↓
Extract files
↓
Restart server
Our automated architecture:
New Artifact
↓
S3
↓
Lambda
↓
SSM
↓
EC2
↓
Nginx
↓
Browser
The deployment process becomes repeatable and much less dependent on manual server access.
19. Benefits of the Architecture
Automation
A new artifact can trigger the deployment process automatically.
Reduced Manual Work
There is no need to manually copy files to EC2.
Event-Driven
The pipeline starts from an S3 object-created event.
AWS Native
The architecture uses managed AWS services.
Easy to Understand
Each service has a clear responsibility.
Monitoring
Lambda execution and errors can be monitored through CloudWatch.
Scalable Architecture
The same concept can be extended to larger applications and more advanced deployment systems.
20. Limitations and Production Improvements
This project is designed as a learning and demonstration project, so there are several areas that could be improved for production.
1. Use Least-Privilege IAM
Instead of broad managed policies, create custom policies with only the required actions.
2. Add Versioning
S3 versioning can help maintain previous application artifacts.
3. Add Rollback
A production pipeline should be able to automatically return to a previous working version if deployment fails.
4. Add Testing
Automated tests should run before deployment.
5. Add Build Automation
A future version could use:
GitHub
↓
CodePipeline
↓
CodeBuild
↓
S3
↓
Lambda
↓
SSM
↓
EC2
6. Use HTTPS
For a production web application, HTTPS should be configured instead of plain HTTP.
7. Add Better Observability
CloudWatch metrics, alarms, dashboards, and notifications can be added.
21. Future Architecture
The current project starts with a manually prepared game.zip.
A more advanced version could start from a Git repository:
Developer
↓
GitHub
↓
CodePipeline
↓
CodeBuild
↓
S3 Artifact
↓
Lambda
↓
SSM
↓
EC2
↓
Nginx
↓
Neon Snake
This would provide a more complete CI/CD workflow from source-code commit to production deployment.
22. Final Result
The final result is a working browser-based Neon Snake application hosted on an Amazon EC2 instance.
The application files are deployed to:
/usr/share/nginx/html/
and served through:
Nginx
The most important achievement of the project is not simply running a game.
It is understanding how multiple AWS services can be connected together to automate application deployment.
The project demonstrates:
S3
↓
Lambda
↓
Systems Manager
↓
EC2
↓
Nginx
↓
Browser
This is a practical example of event-driven deployment automation on AWS.
Conclusion
The Neon Snake Serverless CI/CD Pipeline is a small project with a useful real-world concept behind it.
By combining Amazon S3, AWS Lambda, Systems Manager, EC2, Nginx, IAM, and CloudWatch, we can create a deployment workflow where uploading a new application artifact can initiate the deployment process automatically.
The project also provided practical experience with:
- AWS IAM permissions
- S3 event triggers
- Lambda functions
- Systems Manager Run Command
- EC2 configuration
- Nginx web hosting
- S3-to-EC2 file transfer
- Troubleshooting
AccessDeniedException - CloudWatch logging
- Event-driven architecture
- CI/CD concepts
The biggest lesson from this project is that automation is not just about writing code—it is about connecting services together so that the entire delivery process becomes reliable, repeatable, and easier to manage.
Key Takeaway
Upload once. Trigger automatically. Deploy through SSM. Serve through Nginx. Play Neon Snake.
Top comments (0)