DEV Community

Cover image for Neon Snake: Building a Serverless CI/CD Pipeline on AWS with S3, Lambda, SSM & EC2
Toqeer Afzal
Toqeer Afzal

Posted on

Neon Snake: Building a Serverless CI/CD Pipeline on AWS with S3, Lambda, SSM & EC2

Automatically deploy a web game to an EC2 server whenever a new game.zip is 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   │
                    └─────────────────────┘
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

The bucket was created in:

us-east-1
Enter fullscreen mode Exit fullscreen mode

The purpose of this bucket is to store the application deployment package.

The package is:

game.zip
Enter fullscreen mode Exit fullscreen mode

The ZIP contains the web application files, including:

index.html
README.txt
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

The instance uses:

Amazon Linux 2023
Enter fullscreen mode Exit fullscreen mode

and a small instance type:

t3.micro
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

The important permissions include:

AmazonSSMManagedInstanceCore
AmazonS3ReadOnlyAccess
Enter fullscreen mode Exit fullscreen mode

These permissions allow the EC2 instance to:

  1. Connect to AWS Systems Manager
  2. Receive SSM commands
  3. Read the deployment artifact from S3

This is important because the EC2 server needs to download:

s3://neon-snake-artifacts-toqeer123/game.zip
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Then:

unzip -o /tmp/game.zip -d /tmp/deploy_temp/
Enter fullscreen mode Exit fullscreen mode

Then the application files can be copied to:

/usr/share/nginx/html/
Enter fullscreen mode Exit fullscreen mode

Finally:

systemctl restart nginx
Enter fullscreen mode Exit fullscreen mode

This makes the deployment process automated.


6. Creating the Lambda Function

The next component is AWS Lambda.

I created a Lambda function named:

SnakeDeployer
Enter fullscreen mode Exit fullscreen mode

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"
    }
Enter fullscreen mode Exit fullscreen mode

The Lambda function does not directly log into EC2.

Instead, it uses:

AWS Systems Manager → Run Command
Enter fullscreen mode Exit fullscreen mode

to execute the deployment commands.


7. Lambda IAM Permissions

Lambda also needs an IAM execution role.

I used:

iam_role_snake_deployer
Enter fullscreen mode Exit fullscreen mode

The role needs permissions required to perform the deployment workflow.

Important permissions include:

AWSLambdaBasicExecutionRole
AmazonSSMFullAccess
AmazonS3ReadOnlyAccess
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

So whenever a new object is uploaded to the bucket, S3 can trigger:

SnakeDeployer
Enter fullscreen mode Exit fullscreen mode

For example:

Upload game.zip
       ↓
S3 Object Created
       ↓
SnakeDeployer Lambda
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

to:

neon-snake-artifacts-toqeer123
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Lambda reads this information.

Step 4 — Lambda sends an SSM command

Lambda calls:

ssm.send_command()
Enter fullscreen mode Exit fullscreen mode

and targets:

NeonSnakeServer
Enter fullscreen mode Exit fullscreen mode

Step 5 — EC2 downloads the ZIP

The EC2 instance runs:

aws s3 cp s3://neon-snake-artifacts-toqeer123/game.zip /tmp/game.zip
Enter fullscreen mode Exit fullscreen mode

Step 6 — ZIP is extracted

The deployment package is extracted:

unzip -o /tmp/game.zip -d /tmp/deploy_temp/
Enter fullscreen mode Exit fullscreen mode

Step 7 — Application files are deployed

The files are copied to:

/usr/share/nginx/html/
Enter fullscreen mode Exit fullscreen mode

Step 8 — Nginx restarts

systemctl restart nginx
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

This confirmed that:

EC2 → S3
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

The result showed:

README.txt
index.html
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

The final directory contained:

README.txt
index.html
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

With Systems Manager:

Lambda
↓
SSM Run Command
↓
EC2
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Used by EC2.

Its job includes:

Read deployment artifact from S3
Communicate with Systems Manager
Enter fullscreen mode Exit fullscreen mode

Lambda Role

iam_role_snake_deployer
Enter fullscreen mode Exit fullscreen mode

Used by Lambda.

Its job includes:

Write Lambda logs
Send commands through SSM
Access required S3 resources
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Our automated architecture:

New Artifact
     ↓
     S3
     ↓
   Lambda
     ↓
    SSM
     ↓
    EC2
     ↓
   Nginx
     ↓
   Browser
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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/
Enter fullscreen mode Exit fullscreen mode

and served through:

Nginx
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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.

AWS #CloudComputing #DevOps #CICD #Serverless #AmazonS3 #AWSLambda #AmazonEC2 #SystemsManager #Nginx #CloudWatch #IAM #WebDevelopment #DevTo

Top comments (0)