
How I Built an AI-Powered Emoji Face-Mimic Game Using AWS Rekognition and Copilot
Building an AI Face-Mimic Emoji Game with AWS Rekognition, Node.js, and Copilot
GameFace: A simple game powered by AWS Rekognition Service
This game is inspired by an activity back then when I was studying in which I'm not able to deliver.
Game Requirement
- Browser
- Laptop with working camera
- Code Editor (Visual Studio Code)
- AWS Account
- AWS SDK
Game Mechanics
- The player must input the max round where each round is equal to one emoji.
- To start the game, the player must click the start button.
- The game will then show a random emoji; the player must mimic the emoji.
- The player must correctly mimic all the emoji to win the game. One mistake then Game Over.
- The user then can start over the game.
How I did the game?
Brief Flow:
Game Start -> Frontend acknowledge the camera is on -> Camera feed to Backend -> Frontend Process the Backend Response.
Tech Stack and Requirements
Tech Stack:
- JavaScript
- HTML
- CSS
- AWS Rekognition
- AWS CLI
- NodeJS
- Copilot Free Subscription
Requirement:
- Installed Node.JS (16+) as of creation of the game. Use v20 and up instead.
- AWS Account with Rekognition permission (or proper IAM role)
- AWS Access Key Id
- AWS Secret Access Key
- Environment where you can set environment variables (local shell or hosting provider)
Step 1: Setting Up AWS & CLI
- Open the code editor, in this guide, we will use Visual Studio Code.
- Open a terminal via selecting the ... in the menu -> Terminal -> New Terminal
- Navigate to your desired directory and create the project folder.
cd C://Users/mkdir GameFace
- Ensure you're inside the project directory. Initialize a local git by running the command.
git init
- Install AWS SDK Recognition for JavaScript
npm install @aws-sdk/client-rekognition
- Setup AWS Account
- Login to your AWS Account and Select your Region
- Go to IAM -> IAM users -> Create user -> Enter desired Username -> Attach policies directly -> Search and Select "AmazonRekognitionFullAccess" -> Click Create User to finalize the creation.
- Select the created user -> Create Access Key ->Select Local Code -> Ticked the Confirmation Box -> Add description -> Click Create access key.
- Install AWS CLI
- You can use PowerShell or Bash or the MSI Installer
- We will use MSI Installer
- Go to AWS Download Website download the MSI and install, follow the installation wizard.
- Go to Visual Studio code editor and verify the installation.
aws --version
- Link AWS CLI to your AWS Account, still in your terminal run the command:
aws configure
- You will be prompted to enter your AWS Access Key ID and Secret Access Key (which is the access created on step 5), followed by your default Region (e.g.,
us-east-1) and Output format (usuallyjson).
Step 2: Prompting Copilot & Generating the Code
- Create the game. Using copilot, prompt to create a simple game face:
- This is the exact prompt I use.
Act as nodejs developer. You will build a simple game using Amazon Rekognition Service.
Requirements:
1. A web page that click start and the video streaming using the device camera will pop up
2. A random emoji will appear on the live video and display every after 5 seconds.
3. The user will replicate the emoji and the application must identify if the emoji and the user face replication is match
If matched, the emoji name will display and a score will be granted.
Otherwise, display the emoji and the number of score and game over.
4. The user will need to a score of 5 out of 5 emoji.
5. If perfect, display "CONGRATULATION" and the score.
6. A restart button will show to be able the user to play again the game
7. An exit button along the restart button must be available to exit the game. The live video from the camera must be automatically off.
- After the initial prompt there are several prompts to refine the output to achieve the requirement.
- Run the code and enjoy the game.
Lessons Learned & Troubleshooting
- AWS CLI Access - you need to ensure that the account you use has the required permission.
- AWS Access Configuration - I use local environment configuration which is created during the "aws configuration" part. This became my issue due to multiple accounts being appended. You need to ensure that accounts and profile is unique.
- Code - there are bugs such as not able to identify and start the camera feed - I prompted this to copilot to fix the issue.
- Some code changes I don't want co-pilot to do - I manually update the code based on what I need.
Conclusion:
Overall, my experience here is great and learning is overflowing. Keep exploring.
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article