DEV Community

Cover image for Build an Action Game to Learn AWS Security in a Fun Way with Amazon Q CLI
Yuji Oshima for AWS Community Builders

Posted on • Originally published at yuj1osm.hatenablog.com

Build an Action Game to Learn AWS Security in a Fun Way with Amazon Q CLI

There was an interesting campaign about Amazon Q CLI.
If I build a game with Amazon Q CLI and publish a blog or video, I can get a limited T-shirt, so I tried it right away.

Build Games with Amazon Q CLI and score a T shirt 🏆👕

You can interact with other builders and get support on Discord, so if you're interested, join us.

Discord

Environment preparation

Create an AWS Builder ID.

Builder ID

Image description

Install Amazon Q CLI.
There are procedures for each OS, so please refer to them.

Linux

Essential guide to installing Amazon Q Developer CLI on Linux

Windows

The essential guide to installing Amazon Q Developer CLI on Windows

This time, I used the Windows WSL environment.
As you go through the steps, you will be able to run the installer.

./install.sh
Enter fullscreen mode Exit fullscreen mode

When running the installer, you will be asked questions, so answer them as follows.

  • Do you want to add it to the shell variable? → Yes
  • How do you want to change the login method? → Use for Free with Builder ID
? Do you want to modify your shell config (you will have to manually do this otherwise)? ›
❯ Yes
No

? Select login method ›
❯ Use for Free with Builder ID
Use with Pro license

Confirm the following code in the browser
Code: XXXX-XXXX

Open this URL: https://view.awsapps.com/start/#/device?user_code=XXXX-XXXX
▰▰▰▰▰▱▱ Logging in...

Device authorized
Logged in successfully

Enter fullscreen mode Exit fullscreen mode

Then a URL with the authentication code will be issued, so open it in your browser and continue.

Image description

You will be asked if you want Amazon Q Developer for command line to access your data, so allow it.

Image description

Your request has been approved.

Image description

You can confirm that q cli starts successfully by running the following command from WSL.

q chat
Enter fullscreen mode Exit fullscreen mode

Image description

Next, install PyGame, a library required for game development.

GettingStarted - pygame wiki

sudo apt-get install python3-pygame
Enter fullscreen mode Exit fullscreen mode

If you have trouble with dependencies, you can ask Q to do it for you.

Image description

Image description

Try to build a game with Amazon Q CLI

When you're not sure what to make, it's a good idea to ask Q to think about it.

> pygameでゲームを作ります。AWSセキュリティを学べる簡単なゲーム案を考えてください。
AWSセキュリティを学べるPygameゲームの案を考えてみましょう。以下は「AWS Security Defender」というゲーム案です:

## AWS Security Defender

プレイヤーはAWSクラウド環境のセキュリティ担当者となり、様々なセキュリティ脅威からリソースを守るゲームです。

### ゲームコンセプト
• 2Dサイドビューまたはトップダウン視点のアクションゲーム
• プレイヤーはAWSセキュリティエンジニアとして、クラウド環境を守る
• 様々なセキュリティ脅威(マルウェア、不正アクセス、設定ミスなど)が攻撃してくる
• 正しいセキュリティ対策を選んで脅威を撃退する

### ゲーム要素
1. ステージ構成:
   • EC2、S3、RDS、Lambdaなど異なるAWSサービスをテーマにしたレベル
   • 各レベルで特有のセキュリティ脅威と対策が登場

2. プレイメカニック:
   • プレイヤーは「セキュリティツール」を収集・使用して脅威を撃退
   • 例: IAMポリシー(アクセス制御)、WAF(Webアタック防御)、GuardDuty(異常検知)など
   • 正しいツールを正しい脅威に対して使うことでポイント獲得

3. 教育要素:
   • 各脅威とツールには実際のAWSセキュリティ概念の説明が付く
   • クイズ形式の「セキュリティチェックポイント」でAWSセキュリティの知識をテスト
   • ゲームオーバー時に「セキュリティベストプラクティス」のヒントを表示

4. ゲームの進行:
   • スコアはセキュリティ対策の適切さと速さで決まる
   • 高難度になるほど複雑なセキュリティシナリオが登場
   • 最終的にはマルチレイヤーのセキュリティ対策が必要になる

### 技術的な実装ポイント
• Pygameで2Dグラフィックスとアニメーションを実装
• シンプルな物理エンジンでキャラクター移動とアイテム収集を実現
• JSONファイルでセキュリティシナリオとクイズデータを管理
• スコアとプレイヤーの進捗を保存する機能

このゲームは楽しみながらAWSセキュリティの基本概念(最小権限の原則、多層防御、暗号化、監視など)を学べる教育ツールとして
機能します。プラットフォーマーゲームの要素を取り入れつつ、セキュリティの知識を実践的に身につけられる内容になっています。
Enter fullscreen mode Exit fullscreen mode

It looks good, so I asked Q to make it with this idea.

> pygameを使ってその案のゲームを作ってください。
それでは、AWS Security Defenderゲームをpygameで実装していきましょう。まずは基本的なゲーム構造を作成します。
Enter fullscreen mode Exit fullscreen mode

Then, Q created the game in no time.

AWS Security Defenderゲームの実装が完了しました!以下のファイルを作成しました:

1. main.py - メインゲームループとゲームロジック
2. player.py - プレイヤーキャラクターのクラス
3. threats.py - セキュリティ脅威のクラス
4. tools.py - セキュリティツールのクラス
5. levels.py - ゲームレベルの定義
6. README.md - ゲームの説明書

## ゲームの実行方法

ゲームを実行するには、以下のコマンドを使用します:

bash
python main.py


## ゲームの特徴

1. 教育的要素:
   • AWSセキュリティの基本概念を学べる
   • 各レベルで異なるセキュリティシナリオを体験
   • セキュリティクイズでAWSの知識をテスト

2. ゲームプレイ:
   • 左右矢印キーでプレイヤーを移動
   • スペースキーで攻撃
   • タブキーでセキュリティツールを切り替え
   • 正しいツールで脅威を撃退するとスコア獲得

3. レベル構成:
   • レベル1: EC2セキュリティ(基本的な脅威)
   • レベル2: S3データ保護(データ漏洩対策)
   • レベル3: ネットワーク防御(複合的な脅威)

## 拡張アイデア

このゲームは基本的な実装ですが、以下のように拡張できます:

1. グラフィック改善:
   • 単純な四角形の代わりに、AWSサービスのアイコンを使用
   • アニメーションの追加
   • 背景にAWSクラウド環境の視覚的表現

2. ゲームプレイの拡張:
   • より多くのレベルとシナリオ
   • 難易度設定
   • ハイスコアの保存
   • より多くのセキュリティツールと脅威タイプ

3. 教育コンテンツの充実:
   • より詳細なAWSセキュリティの説明
   • 実際のAWSコンソールに似たUI要素
   • より多くのクイズと学習コンテンツ

このゲームを通じて、プレイヤーはAWSセキュリティの基本概念を楽しく学ぶことができます。
Enter fullscreen mode Exit fullscreen mode

After that, I played the game and made small modifications to complete it.

Finished game

This game is called "AWS Security Defender Game".

Image description

Players become security officers in the AWS cloud environment and protect resources from various security threats.
Use the right security tools to defeat threats and get points.

Each level features a different threat that you need to deal with using the right security tools.
If you defeat the threat correctly, you get 100 points, and if you miss it, you lose 50 points.

The code is available on GitHub.

GitHub - AWS Security Defender Game

Summary

I was able to easily build a game using Amazon Q CLI.
It's amazing that I was able to build something that works just by interacting with Q without doing any coding.
Depending on how you devise the prompts, you may be able to build an even more amazing game.
Please take this campaign as an opportunity to try out Amazon Q CLI.

Top comments (0)

Some comments may only be visible to logged-in visitors. Sign in to view all comments.