The purpose of this work is to develop and deploy a leaderboard for your game using the following AWS resources: S3, APIGateway, Lambda, IAM, and DynamoDB. The choice of a highly available, scalable, and secure serverless environment with massive economies of scale will have several benefits to the end user, including:
- low product pricing
- fast response time, and
- reliable uptime
- python_3 Folder: This folder contains all python scripts that are used to build AWS infrastructure on the backend.
- resources Folder: This folder contains the initial setup script as well as the infrastructure for the frontend.
- website Folder: This folder contains all the images and code necessary to build a functional game with leaderboard. Click the image below to see a live demo of what will be created.
- AWS CLI: See the Getting started guide in the AWS CLI User Guide for more information.
- AWS Credentials: Your AWS credentials need to have administrative privileges to IAM, S3, Lambda, API Gateway and DynamoDB. If you haven’t setup AWS credentials before, this resource from AWS is helpful.
- AWS SDK for Python: You will need to be running the latest Boto3 release. See the Boto3 Quickstart for more information.
git clone https://github.com/coursecoder/leaderboard-aws.git
- Set permissions on the script so that you can run it, and then run it:
chmod +x ./resources/setup.sh && ./resources/setup.sh
- You will be asked to name your S3 bucket. Your bucket name must be appended with -leaderboard for the script to work. If you are not familiar with naming S3 buckets, see Bucket Naming Rules.
The setup script creates the following resources:
- An S3 bucket with an associated bucket policy. The bucket contains the game website code.
- An Amazon DynamoDB table populated with leaderboard data. The leaderboard is already pre-seeded with 25 users (json file is resources/website/all_gamers.json). The leaderboard avatars are generated using the 3rd party API DiceBear Avatars.
- A REST API configured using Amazon API Gateway.
- All game data is exposed at /leaderboard (GET)
- Data for the top six players is exposed at /leaderboard/top_players (GET)
- Score submission endpoint is exposed at /score/submit (POST).
- Two Lambda functions are created
- get_all_leaderboard function is used by the two GET endpoints to retrieve data from DynamoDB when invoked. There is a policy that gives the Lambda function permission to read data from DynamoDB.
- submit_score function is used by the POST endpoint to put data to DynamoDB. The policy gives the Lambda function permission to update the DynamoDB data.