AWS Builder Center
⚔️ Build a Warrior Game on AWS: Create and Host an Action-Adventure Game Using Serverless Services

⚔️ Build a Warrior Game on AWS: Create and Host an Action-Adventure Game Using Serverless Services

The goal is to demonstrate how developers can combine game development with AWS cloud architecture without starting with complicated game-server infrastructure.

Cloud Data Engineer



Introduction

Game development is an exciting way to explore software engineering, cloud architecture, and interactive application design.
But building a game is not only about creating characters, animations, and levels. A modern game may also need hosting, player authentication, score management, data storage, content delivery, and backend services.
In this hands-on project, we're going to explore how to build a browser-based action-adventure game called Warrior Quest using AWS.
Imagine a warrior entering a dangerous fantasy world filled with enemies, obstacles, and challenges. Players must move, attack, survive enemy waves, collect points, and achieve the highest possible score.
We'll build the game using HTML, CSS, and JavaScript, then use AWS services to host the application and support its backend functionality.

1. What Are We Building?

Warrior Quest is a simple 2D action-adventure browser game.
The player controls a warrior who must defeat enemies and survive as long as possible.

Core gameplay features

  • Warrior character with movement controls.
  • Enemy characters that approach the warrior.
  • Sword attack functionality.
  • Health and enemy damage mechanics.
  • Score tracking.
  • Multiple enemy waves.
  • Game-over and restart functionality.
  • Leaderboard for top players.

Target audience

This project is suitable for:
  • Developers learning AWS.
  • Students exploring game development.
  • Cloud engineers interested in serverless applications.
  • Beginners experimenting with JavaScript and browser games.
  • AWS builders looking for practical project ideas.

2. Technology Stack

We'll use a combination of frontend technologies and AWS managed services.
Technology
Purpose
HTML5 Canvas
Render the game world and characters
CSS3
Game interface and styling
JavaScript
Game mechanics and interactions
Amazon S3
Store and host game files
Amazon CloudFront
Deliver game content through a CDN
Amazon API Gateway
Expose backend APIs
AWS Lambda
Process player scores
Amazon DynamoDB
Store leaderboard records
Amazon Cognito
Optional player authentication
Amazon CloudWatch
Monitor backend activity
For this first version, we'll use a single-player browser game with a serverless leaderboard. Multiplayer gameplay can be introduced later using dedicated game-server infrastructure.

3. Understanding the AWS Architecture

The architecture separates the game client from the backend services.

High-level architecture

PLAYERS
|
v
Amazon CloudFront
|
v
Amazon S3
Game Frontend
|
| HTTPS API Requests
v
Amazon API Gateway
|
v
AWS Lambda
Score Processing
|
v
Amazon DynamoDB
Leaderboard

Optional Player Authentication
|
v
Amazon Cognito

Monitoring and Logs
|
v
Amazon CloudWatch

1. Amazon S3 — Game Hosting

Amazon S3 stores the static game application.
Our game files might look like this:
warrior-quest/
│
├── index.html
├── style.css
├── game.js
│
└── assets/
├── warrior.png
├── enemy.png
├── background.png
├── sword.png
└── sounds/
├── attack.wav
└── game-over.wav
S3 provides durable object storage for these files.
For a public production website, we can configure CloudFront with an S3 origin and use HTTPS rather than exposing an S3 website endpoint directly.

2. Amazon CloudFront — Content Delivery

CloudFront distributes the game files through AWS edge locations.
This can improve content delivery for players accessing the game from different geographic locations.
It can also cache static assets such as:
  • Game backgrounds.
  • Character sprites.
  • Audio files.
  • CSS and JavaScript files.

3. Amazon API Gateway — Backend Communication

The browser game communicates with backend functionality through API Gateway.
For example:
POST /scores
GET /leaderboard
The game sends completed player scores to the backend, while the leaderboard endpoint retrieves the highest scores.

4. AWS Lambda — Game Backend Logic

AWS Lambda processes backend requests.
Possible functions include:
  • Save player score.
  • Retrieve leaderboard.
  • Validate player identity.
  • Check score submission limits.
The advantage is that we don't need to maintain a continuously running application server for these simple backend operations.

5. Amazon DynamoDB — Leaderboard Storage

DynamoDB stores player information and scores.
A simple leaderboard record might look like this:
{
"playerId": "player-001",
"playerName": "WarriorKing",
"score": 2500,
"level": 5,
"createdAt": "2026-11-04T10:00:00Z"
}
For a production implementation, we should design the table and indexes around the leaderboard query pattern.
For example, a leaderboard can use a partition key such as  seasonId  and a sort key that combines score ordering with a unique submission identifier.

4. Build the Warrior Game Frontend

Let's start with the game itself.
We'll use HTML Canvas to render the warrior, enemies, and game environment.
Create a file named  index.html :
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, initial-scale=1.0">

<title>Warrior Quest</title>
<link rel="stylesheet" href="style.css">
</head>

<body>

<main class="game-container">
<h1>⚔️ Warrior Quest</h1>

<div class="game-info">
<span>Health: <strong id="health">100</strong></span>
<span>Score: <strong id="score">0</strong></span>
<span>Level: <strong id="level">1</strong></span>
</div>

<canvas id="gameCanvas"
width="800"
height="450">
</canvas>

<p>
Move: Arrow Keys or WASD |
Attack: Space
</p>

<button id="restartButton">
Restart Game
</button>
</main>

<script src="game.js"></script>

</body>
</html>

5. Add Game Styling

Create  style.css :
* {
box-sizing: border-box;
}

body {
margin: 0;
min-height: 100vh;
background: #111827;
color: white;
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
}

.game-container {
width: min(95%, 900px);
text-align: center;
}

h1 {
color: #fbbf24;
}

.game-info {
display: flex;
justify-content: space-around;
padding: 15px;
background: #1f2937;
border-radius: 10px;
margin-bottom: 12px;
}

canvas {
width: 100%;
background: #374151;
border: 3px solid #fbbf24;
border-radius: 8px;
}

button {
background: #d97706;
color: white;
padding: 12px 24px;
border: none;
border-radius: 6px;
cursor: pointer;
font-weight: bold;
}

button:hover {
background: #b45309;
}

6. Implement the Warrior Game Logic

Now let's add movement, enemies, attacks, health, and scoring.
Create  game.js :
const canvas = document.getElementById("gameCanvas");
const ctx = canvas.getContext("2d");

const healthDisplay = document.getElementById("health");
const scoreDisplay = document.getElementById("score");
const levelDisplay = document.getElementById("level");

const keys = {};

const warrior = {
x: 100,
y: 300,
width: 35,
height: 55,
speed: 4,
health: 100,
attacking: false,
attackCooldown: 0
};

let enemies = [];
let score = 0;
let level = 1;
let gameOver = false;
let spawnTimer = 0;

document.addEventListener("keydown", (event) => {
keys[event.key.toLowerCase()] = true;

if (event.code === "Space") {
attack();
event.preventDefault();
}
});

document.addEventListener("keyup", (event) => {
keys[event.key.toLowerCase()] = false;
});

function spawnEnemy() {
enemies.push({
x: canvas.width + 30,
y: 305,
width: 35,
height: 50,
health: 2,
speed: 1 + level * 0.3
});
}

function attack() {
if (gameOver || warrior.attackCooldown > 0) return;

warrior.attacking = true;
warrior.attackCooldown = 25;

enemies.forEach(enemy => {
const closeEnough =
Math.abs(enemy.x - warrior.x) < 75;

if (closeEnough) {
enemy.health--;
if (enemy.health <= 0) {
score += 100;
}
}
});

enemies = enemies.filter(enemy => enemy.health > 0);
}

function update() {
if (gameOver) return;

if (keys["arrowleft"] || keys["a"]) {
warrior.x -= warrior.speed;
}

if (keys["arrowright"] || keys["d"]) {
warrior.x += warrior.speed;
}

if (keys["arrowup"] || keys["w"]) {
warrior.y -= warrior.speed;
}

if (keys["arrowdown"] || keys["s"]) {
warrior.y += warrior.speed;
}

warrior.x = Math.max(
0,
Math.min(canvas.width - warrior.width, warrior.x)
);

warrior.y = Math.max(
0,
Math.min(canvas.height - warrior.height, warrior.y)
);

if (warrior.attackCooldown > 0) {
warrior.attackCooldown--;
} else {
warrior.attacking = false;
}

spawnTimer++;

if (spawnTimer > Math.max(35, 100 - level * 5)) {
spawnEnemy();
spawnTimer = 0;
}

enemies.forEach(enemy => {
enemy.x -= enemy.speed;

const collision =
warrior.x < enemy.x + enemy.width &&
warrior.x + warrior.width > enemy.x &&
warrior.y < enemy.y + enemy.height &&
warrior.y + warrior.height > enemy.y;

if (collision) {
warrior.health = Math.max(
0,
warrior.health - 0.5
);
}
});

enemies = enemies.filter(
enemy => enemy.x > -enemy.width
);

if (score >= level * 500) {
level++;
}

if (warrior.health <= 0) {
gameOver = true;
}

healthDisplay.textContent =
Math.ceil(warrior.health);

scoreDisplay.textContent = score;
levelDisplay.textContent = level;
}

function draw() {
ctx.clearRect(0, 0, canvas.width, canvas.height);

// Ground
ctx.fillStyle = "#166534";
ctx.fillRect(0, 370, canvas.width, 80);

// Warrior
ctx.fillStyle = "#fbbf24";
ctx.fillRect(
warrior.x,
warrior.y,
warrior.width,
warrior.height
);

// Warrior sword
if (warrior.attacking) {
ctx.fillStyle = "#e5e7eb";
ctx.fillRect(
warrior.x + warrior.width,
warrior.y + 15,
45,
6
);
}

// Enemies
enemies.forEach(enemy => {
ctx.fillStyle = "#dc2626";
ctx.fillRect(
enemy.x,
enemy.y,
enemy.width,
enemy.height
);
});

if (gameOver) {
ctx.fillStyle = "white";
ctx.font = "bold 40px Arial";
ctx.textAlign = "center";

ctx.fillText(
"GAME OVER",
canvas.width / 2,
canvas.height / 2
);

ctx.font = "20px Arial";
ctx.fillText(
"Final Score: " + score,
canvas.width / 2,
canvas.height / 2 + 40
);
}
}

function gameLoop() {
update();
draw();

requestAnimationFrame(gameLoop);
}

document.getElementById("restartButton")
.addEventListener("click", () => {
warrior.x = 100;
warrior.y = 300;
warrior.health = 100;
warrior.attackCooldown = 0;

enemies = [];
score = 0;
level = 1;
spawnTimer = 0;
gameOver = false;

gameLoop();
});

gameLoop();
This is a basic gameplay prototype. It uses colored rectangles as placeholder characters so the core mechanics are easy to understand.
A more polished version can replace these shapes with animated warrior and enemy sprites, background artwork, sound effects, and collision animations.
For a production game, the restart logic should also use a single animation loop rather than starting additional loops on every restart.

7. Create the AWS Backend

The next step is to connect the game to AWS.
We'll use API Gateway, Lambda, and DynamoDB to implement a simple leaderboard.

Step 1: Create a DynamoDB table

Create a table named:
WarriorLeaderboard
For a simple leaderboard design, use:
Partition Key: seasonId (String)
Sort Key: scoreKey (String)
The score key can be designed to sort higher scores first, for example by storing a zero-padded inverse score followed by a unique submission ID.
This allows the backend to query the top scores for a particular season.

Step 2: Create an IAM role for Lambda

Create an execution role that allows the Lambda function to access only the required DynamoDB table.
Avoid giving the function broad administrative permissions.

Step 3: Create the Lambda function

Create a Python Lambda function to process score submissions.
Example:
import json
import os
import boto3
import uuid
from datetime import datetime, timezone

dynamodb = boto3.resource("dynamodb")

table = dynamodb.Table(
os.environ["LEADERBOARD_TABLE"]
)

def lambda_handler(event, context):

try:
body = json.loads(event.get("body") or "{}")

player_name = str(
body.get("playerName", "Player")
)[:20]

score = int(body.get("score", 0))

if score < 0 or score > 1000000:
return {
"statusCode": 400,
"body": json.dumps({
"message": "Invalid score"
})
}

submission_id = str(uuid.uuid4())

score_key = (
f"{999999999 - score:09d}"
f"#{submission_id}"
)

table.put_item(
Item={
"seasonId": "season-2026-01",
"scoreKey": score_key,
"submissionId": submission_id,
"playerName": player_name,
"score": score,
"createdAt": datetime.now(
timezone.utc
).isoformat()
}
)

return {
"statusCode": 200,
"headers": {
"Content-Type": "application/json"
},
"body": json.dumps({
"message": "Score submitted successfully"
})
}

except (ValueError, TypeError):
return {
"statusCode": 400,
"body": json.dumps({
"message": "Invalid request"
})
}

except Exception:
return {
"statusCode": 500,
"body": json.dumps({
"message": "Unable to save score"
})
}
Configure the Lambda environment variable:
LEADERBOARD_TABLE=WarriorLeaderboard
This example demonstrates score storage. A public production leaderboard also needs server-side score validation, player authentication, request throttling, and protections against score manipulation. A browser client should never be trusted to submit an authoritative score.

Step 4: Create an API Gateway endpoint

Create an API Gateway HTTP API with a route:
POST /scores
Integrate the route with the Lambda function.
Configure CORS to allow only your game application's origin.
The browser can then submit a score after the game ends.
Example frontend request:
async function submitScore(playerName, score) {

const response = await fetch(
"YOUR_API_GATEWAY_ENDPOINT/scores",
{
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
playerName,
score
})
}
);

if (!response.ok) {
throw new Error("Score submission failed");
}

return response.json();
}
Replace  YOUR_API_GATEWAY_ENDPOINT  with your deployed API URL.
For a production implementation, retrieve player identity from a verified authentication token and validate gameplay results on a trusted backend.

8. Deploy the Game on Amazon S3 and CloudFront

Once the frontend is ready, we can deploy it to AWS.

Step 1: Create an S3 bucket

Create a bucket with a unique name, for example:
warrior-quest-game
Upload:
index.html
style.css
game.js
assets/

Step 2: Configure CloudFront

Create a CloudFront distribution using the S3 bucket as its origin.
For production, use Origin Access Control (OAC) so that the bucket does not need to be publicly accessible.
Configure:
  • HTTPS.
  • Default root object:  index.html .
  • Appropriate cache policies.
  • A custom domain, if required.

Step 3: Test the application

Open the CloudFront distribution URL.
Verify that:
  • The game loads correctly.
  • The warrior moves.
  • Enemies spawn.
  • Attacks work.
  • Health and scores update.
  • Restart works.
  • The leaderboard API can receive a valid request.

9. Security and Performance Considerations

A game may appear simple, but public applications need proper security and operational controls.
Here are some important considerations.
Authentication
Use Amazon Cognito if you want registered player accounts and persistent player identities.
API protection
Use API Gateway throttling and appropriate AWS WAF protections where needed.
Score validation
Never trust scores submitted directly by a browser. Validate important gameplay events on a trusted server.
IAM permissions
Give Lambda only the DynamoDB permissions required by the application.
Content delivery
Use CloudFront to distribute static game assets efficiently.
Monitoring
Use Amazon CloudWatch logs and metrics to monitor Lambda errors, API requests, and backend performance.
Cost management
Set AWS Budgets and monitor usage. Even serverless applications can incur charges through requests, storage, data transfer, and other services.

10. How Can We Extend Warrior Quest?

Once the basic game works, we can introduce more advanced capabilities.
Feature
AWS service or technology
Player registration
Amazon Cognito
Global leaderboard
Amazon DynamoDB
Multiplayer sessions
Amazon GameLift Servers
Matchmaking
Amazon GameLift Servers FlexMatch
Live player messaging
API Gateway WebSockets
Game event processing
Amazon EventBridge
Background tasks
AWS Lambda
Game asset delivery
Amazon CloudFront
Logs and metrics
Amazon CloudWatch
For real-time multiplayer action games, a dedicated authoritative game server is generally more appropriate than relying on browser-side logic or ordinary request-response Lambda functions.
Amazon GameLift Servers can help host and scale dedicated game server processes. AWS also provides reference architectures combining GameLift with serverless backend services.

Conclusion

Building Warrior Quest is a practical way to explore both game development and AWS cloud architecture.
We started with a simple browser-based warrior game and designed a cloud backend around Amazon S3, CloudFront, API Gateway, Lambda, and DynamoDB.
The project demonstrates how different AWS services can work together to support game hosting, player data, and leaderboard functionality.
More importantly, it provides a foundation that can grow from a small single-player prototype into a more advanced gaming application with authentication, multiplayer sessions, matchmaking, and real-time services.
My key takeaway: You don't need to build a complicated gaming infrastructure on day one. Start with a working game, use managed AWS services for the backend, and introduce more advanced architecture as your player base and gameplay requirements grow.

Let's Discuss!

If you were building your own action-adventure game on AWS, which feature would you implement first?
  • Global leaderboard
  • Multiplayer battles
  • Player authentication
  • AI-powered enemies
  • Real-time matchmaking
Share your ideas and experience in the comments!



Official AWS References

#AWS #GameDevelopment #AmazonS3 #AWSLambda #AmazonDynamoDB #AmazonGameLift #Serverless #CloudComputing #AWSCommunity
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article