Home Analytics Creating and Managing DynamoDB Tables using AWS CLI –

Creating and Managing DynamoDB Tables using AWS CLI –

by datatabloid_difmmk

This article data science blogthon.

prologue

The AWS Command Line Interface (CLI) is a centralized management tool for managing AWS services. Through the CLI, users can control the service manually or automate it with powerful scripts. This one tool can handle multiple services from the tcommand line. Utilization of some services. This post describes how to manage DynamoDB, an AWS NoSQL database, through the AWS CLI, including creating and managing DynamoDB tables.

Overview of

Amazon DynamoDB is a fully managed AWS NoSQL database service optimized for high-performance queries against large datasets. Deliver consistently fast performance to all your applications with no downtime or performance degradation.

Main features:

DynamoDB

Source: https://www.cloudinfonow.com/amazon-dynamodb-pricing/

Why DynamoDB?

  • Automatic partitioning and SSD-based storage.
  • You don’t have to worry about patching or updating your database.
  • Supports cross-region replication for global data access.
  • Offers on-demand backup capabilities with long-term retention and archiving.

Example of use:

  • analysis:
    Store metrics from multiple data sources such as IoT sensors, web applications, and more. Time to Live (TTL) functionality allows users to efficiently control their data.
  • Media and Entertainment:
    It processes and performs complex analytics and combines it with big data to identify customer likes and dislikes and the preferences of other users. It also scales throughput and concurrency for media and entertainment workloads such as real-time video streaming and interactive content.
  • online game:
    It helps you easily store and maintain analytics data, player data, leaderboards and player session records while improving performance.

Steps to create and manage DynamoDB tables using the AWS CLI

To create and manage tables in DynamoDB, users should follow these steps:

1. Install the AWS CLI

2. Configuring and Setting CLI Credentials

3. Create a table in the CLI using the cble command

4. Manage tables and attributes

Step 1: Install the AWS CLI

The AWS CLI can be installed on Windows, macOS, or Linux operating systems. The Amazon Linux AMI already includes the AWS CLI in the OS distribution, so you don’t need to manually install it.

Linux OS:

Install the latest version of the AWS CLI on Linux x86 (64-bit) with the following command.

curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install

Mac OS:

First, install Homebrew on macOS, then install the latest version of the AWS CLI using the following command.

brew install awscli

To check the credentials, the user can use the following command:

aws sts get-caller-identity

Windows:

The latest Windows installation package can be downloaded and installed from the following website:

Another way to install the CLI is to run the following command:

msiexec.exe /i https://awscli.amazonaws.com/AWSCLIV2.msi

To verify the CLI installation, the user can run the following command:

aws --version

Step 2: Configure and Set CLI Credentials

After installation, configure with your credentials using the following command:

aws configure

This command will prompt you for details such as access key, secret key, and region.

Step 3: Create a table with the CLI using the create-table command

To create a table in DynamoDB, use the create-table command with four arguments.

  • –table-name – Indicates the name of the table created by the user.
  • –attribute-definitions – Shows the list of attributes and their types that the user uses in tables and indexes.
  • –key-schema – indicates the attributes that make up the primary key of the table or index.
  • –billing-mode – Controls how users are billed for read and write throughput. Its value is either PROVISIONED or PAY_PER_REQUEST.

Let’s create a table with the following details:

  • Table name: Employee_Data
  • Attribute Names: Emp_Id, Name, Salary, Department, Job Title
  • Range Key: Department
  • Partition Key: Emp_Id
  • Billing Mode: PAY_PER_REQUEST

The CLI command to create the table based on the above details would be:

aws dynamodb create-table 
    --table-name Employee_Data 
    --attribute-definitions 
           AttributeName=Emp_Id,AttributeType=S 
           AttributeName=Name,AttributeType=S 
           AttributeName=Salary,AttributeType=N 
           AttributeName=Department,AttributeType=S 
           AttributeName=Position,AttributeType=S 
    --key-schema 
           AttributeName=Emp_Id,KeyType=HASH 
           AttributeName=Department,KeyType=RANGE 
    --billing-mode PAY_PER_REQUEST

To verify that the table was successfully created, in the AWS console[データベース]Click[DynamoDB]and finally[テーブル]Click to view the created table.

Step 4: Manage and Attributes

Tables and associated attributes can be managed using specific AWS CLI commands. Such commands and their functions include:

list table

To list all DynamoDB tables created using the CLI, use the following command.

aws dynamodb list-tables

table description

To describe a DynamoDB table using the CLI, use the aws dynamodb describe-table command. Returns detailed information about a table, including table key schema, provisioned WCUs, RCUs, and table status.

aws dynamodb describe-table 
    --table-name Employee_Data

delete table

To delete a DynamoDB table using the CLI, use the aws dynamodb delete-table command below.

aws dynamodb delete-table 
    --table-name Employee_Data

backup table

To back up all DynamoDB table data on demand, use the following command.

aws dynamodb create-backup 
    --table-name Employee_Data 
    --backup-name Employee_Data -backup-$(date +"%m-%d-%Y")

put the item

Use the following command to insert a new record into your DynamoDB table.

aws dynamodb put-item 
    --table-name Employee_Data 
    --item '{"Emp_Id": {"S": "110"}, "Name": {"S": "Teena"},"Salary": {"N": "65000"},"Department": {"S": "Sales"},"Position": {"S": "Manager"}}'

get item

To get a specific table item by key or key combination, use the following command:

aws dynamodb get-item 
    --table-name Employee_Data 
    --key '{"Emp_Id": {"S": "115"}}' 
    --consistent-read

Get/Scan All Items

To perform a scan operation using the CLI or retrieve all items from a DynamoDB table, use the following command.

aws dynamodb scan 
    --table-name Employee_Data

delete item

Deleting a table item can only be done using the primary key using the following command.

aws dynamodb delete-item 
    --table-name Employee_Data 
    --key '{"Emp_Id": {"S": "111"}}'

Conclusion

Users can manage AWS services using the AWS Management Console or AWS CLI. Developers prefer her AWS CLI over other techniques because it provides more precise control over other services and helps automate scripts. Therefore, creating and managing tables in DynamoDB is easy with a specific set of CLI commands.

Important points:

  • The AWS Command Line Interface (CLI) is a centralized management tool for managing AWS services.
  • Amazon DynamoDB is a fully managed AWS NoSQL database service optimized for high-performance queries against large datasets.
  • Creating a table is done using the aws dynamodb create-table command.
  • To get general information about a table, use the aws dynamodb describe-table command.
  • To insert a new record, use the aws dynamodb put-item command.
  • The aws dynamodb scan command retrieves an entire table item or performs a scan operation.
  • Table items can be deleted using the aws dynamodb delete-item command.

Media shown in this article are not owned by Analytics Vidhya and are used at the author’s discretion.

You may also like

Leave a Comment

Subscribe my Newsletter for new blog posts, tips & new photos. Let's stay updated!

About Us

We're a provider of Data IT News and we focus to provide best Data IT News and Tutorials for all its users, we are free and provide tutorials for free. We promise to tell you what's new in the parts of modern life Data professional and we will share lessons to improve knowledge in data science and data analysis field.

Facebook Twitter Youtube Linkedin Instagram

5 Strategies To Reduce IT Support Tickets – Ultimate Guide

Recent Articles

Redefining the Role of IT in a Modern BI World What (Really) Are Issues Faced by Data Scientist in 2022 How I start Data Science Projects | What to do when you're stuck

Featured

5 Strategies To Reduce IT Support Tickets – Ultimate Guide Redefining the Role of IT in a Modern BI World What (Really) Are Issues Faced by Data Scientist in 2022

Copyright ©️ All rights reserved. | Data Tabloid