Amazon DynamoDB
Developer Guide (API Version 2012-08-10)

Step 1: Deploy and Test Locally

In this step you download, deploy, and test the Tic-Tac-Toe game application on your local computer. Instead of using the Amazon DynamoDB web service, you will download DynamoDB to your computer, and create the required table there.

1.1: Download and Install Required Packages

You will need the following to test this application locally:

  • Python

  • Flask (a microframework for Python)

  • AWS SDK for Python (Boto)

  • DynamoDB running on your computer

  • Git

To get these tools, do the following:

  1. Install Python. For step-by-step instructions, go to Download Python.

    The Tic-Tac-Toe application has been tested using Python version 2.7.

  2. Install Flask and AWS SDK for Python (Boto) using the Python Package Installer (PIP):

    • Install PIP.

      For instructions, go to Install PIP. On the installation page, choose the link, and then save the file. Then open a command terminal as an administrator, and type the following at the command prompt:


      On Linux, you don't specify the .exe extension. You only specify python

    • Using PIP, install the Flask and Boto packages using the following code:

      pip install Flask
      pip install boto

  3. Download DynamoDB to your computer. For instructions on how to run it, see Running DynamoDB on Your Computer.

  4. Download the Tic-Tac-Toe application:

    1. Install Git. For instructions, go to git Downloads.

    2. Execute the following code to download the application:

      git clone

1.2: Test the Game Application

To test the Tic-Tac-Toe application, you need to run DynamoDB locally on your computer.

To run the Tic-Tac-Toe application

  1. Start DynamoDB.

  2. Start the web server for the Tic-Tac-Toe application.

    To do so, open a command terminal, navigate to the folder where you downloaded the Tic-Tac-Toe application, and run the application locally using the following code:

    python.exe --mode local --serverPort 5000 --port 8000  

    On Linux, you don't specify the .exe extension.

  3. Open your web browser, and type the following:


    The browser shows the home page:

  4. Type user1 in the Log in box to log in as user1.


    This example application does not perform any user authentication. The user ID is only used to identify players. If two players log in with the same alias, the application works as if you are playing in two different browsers.

  5. If this is your first time playing the game, a page appears requesting you to create the required table (Games) in DynamoDB. Choose CREATE TABLE.

  6. Choose CREATE to create the first tic-tac-toe game.

  7. Type user2 in the Choose an Opponent box, and choose Create Game!

    Doing this creates the game by adding an item in the Games table. It sets the game status to PENDING.

  8. Open another browser window, and type the following.


    The browser passes information through cookies, so you should use incognito mode or private browsing so that your cookies don't carry over.

  9. Log in as user2.

    A page appears that shows a pending invitation from user1.

  10. Choose accept to accept the invitation.

    The game page appears with an empty tic-tac-toe grid. The page also shows relevant game information such as the game ID, whose turn it is, and game status.

  11. Play the game.

For each user move, the web service sends a request to DynamoDB to conditionally update the game item in the Games table. For example, the conditions ensure the move is valid, the square the user chose is available, and it was the turn of the user who made the move. For a valid move, the update operation adds a new attribute corresponding to the selection on the board. The update operation also sets the value of the existing attribute to the user who can make the next move.

On the game page, the application makes asynchronous JavaScript calls every second, for up to five minutes, to check if the game state in DynamoDB has changed. If it has, the application updates the page with new information. After five minutes, the application stops making the requests and you need to refresh the page to get updated information.