Using a DynamoDB Table Basic I/O

1.5 hours
  • 5 Learning Objectives

About this Hands-on Lab

In this lab, we will explore the read and write processes available for a DynamoDB table. In the lab instructions, you will find a scenario that provides some sample data that will need to be entered into a DynamoDB table, as well as several ways to retrieve the data from the DynamoDB table. In the solution videos, we will walk through reading from and writing to a DynamoDB table with the AWS Management Console, AWS CLI, and the Python Boto3 SDK.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Add Records to the `PetInventory` Table

Add the records to the PetInventory DynamoDB table using the PutItem API call.

This can be accomplished in one of the following ways:

  • With the Create Item button in the AWS Management Console.
  • With the aws dynamodb put-item command in the AWS CLI.
  • With the Boto3 SDK put_item method for the Client or Table interfaces.
Update All Records in the Table

Update the records in the table with the UpdateItem API call to add the missing pet_available attribute.

This can be done in one of the following ways:

  • Editing the item in the AWS Management Console.
  • With the aws dynamodb update-item command in the AWS CLI.
  • With the Boto3 SDK update_item method.
Confirm Data Has Been Added and Updated Successfully

Manually confirm all data has been updated in the table correctly in one of the following ways:

  • Review the table output in the AWS Management Console.
  • Run aws dynamodb scan --table-name PetInventory in the AWS CLI.
Final Confirmation with Provided Scripts
  1. Run the confirmlab.py and confirmlabfinal.py scripts:
python3 confirmlab.py

python3 confirmlabfinal.py
  1. Ensure the output matches the output provided in the lab information.
Convert Provided CSV Data to DynamoDB JSON

Convert the following provided CSV records:

Monitor Lizard,319,Duncan,Moss,4,Male,Null,Spiky
Iguana,146,Jessica,Seaweed,10,Female,Null,Rough
Iguana,159,Paul,Basil,3,Male,Null,Rough
Chinchilla,631,Shadam,Stone,2,Male,Soft,Null
Chinchilla,805,Irulan,Snow,1,Female,Soft,Null
Red-tailed Boa,3,Vladimir,Abalone/Brick,18,Male,Null,Smooth
Red-tailed Boa,9,Feyd-Rautha,Ash/Caramel,8,Male,Null,Smooth

To make them, DynamoDB JSON syntax is shown below:

{
    "age": {
        "N": "4"
    },
    "color": {
        "S": "Moss"
    },
    "gender": {
        "S": "Male"
    },
    "name": {
        "S": "Duncan"
    },
    "pet_id": {
        "N": "319"
    },
    "pet_species": {
        "S": "Monitor Lizard"
    },
    "scale_texture": {
        "S": "Spiky"
    }
}

Additional Resources

We have been hired for a contract with a consulting company to manually enter and verify DynamoDB test data for an online exotic pet store the company has been hired to build. We have been provided with a DynamoDB table named PetInventory, as well as the data that follows to enter and confirm:

pet_species,pet_id,name,color,age,gender,fur_type,scale_texture
Monitor Lizard,319,Duncan,Moss,4,Male,Null,Spiky
Iguana,146,Jessica,Seaweed,10,Female,Null,Rough
Iguana,159,Paul,Basil,3,Male,Null,Rough
Chinchilla,631,Shadam,Stone,2,Male,Soft,Null
Chinchilla,805,Irulan,Snow,1,Female,Soft,Null
Red-tailed Boa,3,Vladimir,Abalone/Brick,18,Male,Null,Smooth
Red-tailed Boa,9,Feyd-Rautha,Ash/Caramel,8,Male,Null,Smooth

After we report that all data has been added to the table and we have confirmed the data is accessible as requested, our manager informs us the data architect forgot to include if the pets have been sold or not. We have been asked to add a pet_available attribute to each item with a Boolean data type, and all items should have pet_available set to true except for Monitor Lizard 319, which should be set to false. The administrator on the team has added a second Python script to confirm this data, which can be run from the provided EC2 instance as seen below:

python3 confirmlabfinal.py

It should provide the following output if all items have been updated succesfully.

      Species                ID                 Name               Color                Age                Gender           Fur Type/Scale Texture         Available
   Monitor Lizard           319                Duncan               Moss                 4                  Male                    Spiky                    False
       Iguana               146               Jessica             Seaweed                10                Female                   Rough                     True
       Iguana               159                 Paul               Basil                 3                  Male                    Rough                     True
     Chinchilla             631                Shadam              Stone                 2                  Male                     Soft                     True
     Chinchilla             805                Irulan               Snow                 1                 Female                    Soft                     True
   Red-tailed Boa            3                Vladimir         Abalone/Brick             18                 Male                    Smooth                    True
   Red-tailed Boa            9              Feyd-Rautha         Ash/Caramel              8                  Male                    Smooth                    True

Reference

Web Console

  • Write (Expand AWS Management Console section)
  • Read

AWS CLI

Write

Read

Python Boto3 SDK

Write

Client:

Table:

Read

Client:

Table:

AWS DynamoDB API

Write

Read

Capacity

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?