Using a DynamoDB Table Basic IO

Get Started
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:

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 as 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"
    }
}
Add Records to `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:

  • In the AWS Management Console by editing the item
  • In the AWS CLI with the aws dynamodb update-item command
  • With the Boto3 SDK using the update_item method
Confirm Data Has Been Added and Updated Successfully

Manually confirm all data has been updated in the table correctly.

This can be done in one of the following ways:

  • In the AWS Management Console, review the table output in the interface.
  • In the AWS CLI, run aws dynamodb scan --table-name PetInventory.
Final Confirmation with Provided Scripts

Run the confirmlab.py and confirmlabfinal.py scripts:

python3 confirmlab.py

python3 confirmlabfinal.py

Ensure the output matches the output provided in the lab information.

Additional Resources

We have been hired for a contract with a consulting company to manually enter and manually verify test data in a DynamoDB table 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 had 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.

Get Started
Who’s going to be learning?

How many seats do you need?

  • $499 USD per seat per year
  • Billed Annually
  • Renews in 12 months

Ready to accelerate learning?

For over 25 licenses, a member of our sales team will walk you through a custom tailored solution for your business.


$2,495.00

Checkout
Sign In
Welcome Back!
Thanks for reaching out!

You’ll hear from us shortly. In the meantime, why not check out what our customers have to say about ACG?