Create a DynamoDB table using the Python library(boto3)

Manminder Singh
Nerd For Tech
Published in
3 min readAug 9, 2022
Using boto3 for dynamo DB operations!

This article aims at creating of DynamoDB table using the boto3 library. In order to achieve the target, we will do different tasks.

Prerequisites
1. AWS account, IAM user with permissions to Cloud9 and DynamoDB.
2. Cloud9 IDE, configured with AWS credentials.
3. Github account.

Task 1: Creating the DynamoDB table
We will create the DynamoDb table through python code using boto3 library. We want to create a table with 2 attributes which are the sort key and primary key respectively.

Output in the terminal

Task 2: Adding values to the DynamoDB table
Let's add the values to the attributes we created in the last task. We will use the below code to add values.

Output in the terminal after adding items to the table

An alternative way of adding the single value only to the DynamoDB table: We will use the code below for the same.

one item added

Task 3: Query the DynamoDB table
Since we have added the multiple values to the DynamoDB table, let's query some values via python code.

As a result of the query operation, the returned value will be GTA5.

GTA5 is the result of running the query on the table

Task 4: Deleting the values from the DynamoDB table
Let's delete a value from the DynamoDB table, we will use the code below to do the same.

Since we have deleted GTA5 from the DynamoDB table, let's go ahead and scan the table to verify if the delete code worked.

As a result, the entire values will be displayed except GTA5.

We have now achieved all the required tasks. Thanks for reading!☁️✌️

--

--