The Wayback Machine - https://web.archive.org/web/20240826230323/https://www.geeksforgeeks.org/aws-dynamodb-working-with-indexes/
Open In App

AWS DynamoDB – Working with Indexes

Last Updated : 28 Mar, 2023
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

An index is a data structure that enables us to perform fast queries on different columns in a table. After creating an index, the database handles it for us. Whenever data is modified in the table, the index is automatically modified to reflect changes in the table. We can create and use a secondary index to query faster. While creating a secondary index, we must specify its key attributes—a partition key and a sort key. After the secondary index is created, we can perform operations such as Query or Scan just as we do on the table. DynamoDB doesn’t have any query optimizer, so a secondary index is used while you Query it or Scan it. DynamoDB supports two types of indexes which have been discussed below in detail:

Global Secondary Index:

A Global Secondary Index (GSI) is an index with a partition key and a sort key that can be different from keys in the base table. A global secondary index is said t be “global” because queries on the index can cover all the data in the base table, across all partitions. A global secondary index has no size limitations like that of the base table and has its own provisioned read and write throughput settings that are separate from those of the table. Therefore, for fast retrieval of results on non-key attributes, we use Secondary Global Indexes. See the below example:

BoardExams

A table named BoardExams has been created with partition key as StudentID and sort key as Stream. The data stored in the above table will be represented as shown in the below image:

Representation of Base table

Now, suppose we need to know the maths marks scored in each stream. Thus, we create a GSI named Stream-index with partition key as Stream and sort key as Maths. See the below image:

Note: The partition key of the base table will also be projected into the index. 

Stream-index

Local Secondary Index:

A Local Secondary Index has the same partition key as the base table but a different sort key. It is “local” in the sense that every partition of a local secondary index is scoped to a base table partition that has the same partition key value. It is created when a table is created. See the below image:



Similar Reads

AWS DynamoDB - Introduction to DynamoDB Accelerator (DAX)
DynamoDB is a fast NoSQL Database that is managed by Amazon Web Services (AWS). It was developed by Amazon Web Services (AWB). DynamoDB is sometimes referred to as a key-value store, but it also has Streams, Global and Local Secondary Indexes, Multi-region and Multimaster replication with enterprise-grade security, and in-memory caching for large s
4 min read
AWS DynamoDB - PartiQL Delete Statements For DynamoDB
PartiQL is a SQL-compatible query language that supports querying, modifying, and inserting data. It makes it easier to interact with DynamoDB and run queries in AWS Management Console. Delete data in DynamoDB Table using PartiQL: Syntax: DELETE FROM table-name WHERE condition; Parameters: Table name: Required – Name of the table in which you want
2 min read
AWS DynamoDB - Insert Data Using AWS Lambda
In this article, we will look into the process of inserting data into a DynamoDB table using AWS Lambda. Amazon DynamoDB is a completely owned NoSQL proprietary provider that helps key-value and textual statistics systems and is supplied via way of means of Amazon.com as a part of Amazon Web Services. AWS Lambda is an event-driven, serverless compu
3 min read
AWS DynamoDB - Working with Streams
DynamoDB Streams is a DynamoDB feature that allows users to keep track of any changes made to the data in DynamoDB. It is an "ordered flow of data" that contains information about changes made to the data in the DynamoDB table. Let us talk of a use case. Consider a "users" table in DynamoDB and your application demands to do some pre-processing/ver
3 min read
AWS DynamoDB - Working with Scans
Amazon DynamoDB is NoSQL managed database that stores semi-structured data like key-value pairs and document data. When creating tables in DynamoDB, no schema structure is required but only a partition key (primary key) is required. DynamoDB tables stores data in form of items and each item consists of attributes that are nothing but key-value pair
3 min read
AWS DynamoDB - Working with Items & Attributes
AWS DynamoDB is a NoSQL managed database that stores semi-structured data i.e. key-value and document data. It stores data in form of an item. An item consists of attributes. Upon table creation in DynamoDB, it only requires a primary key to differentiate between items and no schema is to be defined. Each item can have a different number of attribu
3 min read
AWS DynamoDB - Working with Tables
In this article, we will work on DynamoDB tables. DynamoDB is a NoSQL database that stores document data or key-value pairs. A Dynamodb table consists of items and each item is made up of attributes. Different items can have different attributes. See the below example: Example 1: { "MovieID": 123, "Name": "Godfather", "Rating": 9.1, "Year": 1972 }
3 min read
AWS DynamoDB - Working with Queries
Amazon DynamoDB is a NoSQL managed database service provided by Amazon that stores semi-structured data like key-value pairs. A DynamoDB table consists of items. Each item consists of one partition key and one or more attributes. An example of an item is given below: Example: { "MovieID": 101, "Name": "The Shawshank Redemption", "Rating": 9.2, "Yea
5 min read
AWS DynamoDB - Working with Backups
Amazon DynamoDB supports on-demand backup and restores features. Those features are available to the user independent of whether the user uses AWS Backup or not. Users can use the DynamoDB on-demand backup capability to create full backups of its tables for a long-term period and archival for regulatory observation needs. DynamoDB also removes the
3 min read
Amazon DynamoDB - Logging & Monitoring DynamoDB
Logging is the collection of all the data from cloud services, infrastructure, and applications. It helps in identifying issues, measure performance, and configurations. Whereas monitoring is helpful to detect possible breaches, security gaps and secure the network well before the attack happens. If any suspected things happen in our account then w
2 min read
Amazon DynamoDB - Ways of Protecting Data in DynamoDB
Amazon DynamoDB is a totally managed (“serverless”) and NoSQL (nonrelational) database provider, available on Amazon Web Services. DynamoDB is surprisingly scalable, which means you can start actually small and grow very big while not having to re-installation or re-architect. It additionally offers a bendy model which uses computerized scaling of
10 min read
AWS DynamoDB - Web Based Setup
To use the Web-based services of AWS- DynamoDB the following steps need to be followed: Create an AWS account by navigating to the following link:- https://portal.aws.amazon.com/billing/signup#/startGet the AWS access Key (used to access DynamoDB programmatically).Configure your credentials (used to access DynamoDB programmatically). Creating AWS a
2 min read
DynamoDB - Setup the AWS CLI on macOS
We can use the AWS Command Line Interface (AWS CLI) to control multiple AWS services from the command line and automate them through scripts. We can use the AWS CLI for ad hoc operations, such as creating a table. We can also use it to embed Amazon DynamoDB operations within utility scripts. Before you can use the AWS CLI with DynamoDB, you must ge
3 min read
DynamoDB - Setup the AWS CLI on Linux
We can use the AWS Command Line Interface (AWS CLI) to control multiple AWS services from the command line and automate them through scripts. We can use the AWS CLI for ad hoc operations, such as creating a table. We can also use it to embed Amazon DynamoDB operations within utility scripts. Before you can use the AWS CLI with DynamoDB, you must ge
4 min read
DynamoDB - Setup the AWS CLI on Windows
We can use the AWS Command Line Interface (AWS CLI) to control multiple AWS services from the command line and automate them through scripts. We can use the AWS CLI for ad hoc operations, such as creating a table. We can also use it to embed Amazon DynamoDB operations within utility scripts. Before you can use the AWS CLI with DynamoDB, you must ge
2 min read
How to Mock AWS DynamoDB Services for Unit Testing?
In this article, we will be understanding how to mock out DynamoDB resources with the help of short examples. But before this, first, we have to make out why we use mocking for testing purposes? Mocking is something where we try to make a copy or replica of some resources that are required for testing purposes. Sounds confusing right? In simple ter
3 min read
AWS DynamoDB - Read Data from a Table
AWS DynamoDB is a NoSQL managed database that stores semi-structured data i.e. key-value and document data. It stores data in form of an item. An item consists of attributes. Upon table creation in DynamoDB, it only requires a primary key to differentiate between items and no schema is to be defined. Each item can have a different number of attribu
3 min read
AWS DynamoDB - Query Data in a Table
Amazon DynamoDB is a NoSQL managed database that stores semi-structured data i.e. key-value pair and document data. A table in DynamoDB stores data in form of an item and each item has a primary key. Example: { "Color": true, "Director": "Christopher Nolan", "MovieID": 1, "Name": "Inception", "Rating": 8.7, "Year": 2010 } The Query operation in Ama
2 min read
AWS DynamoDB - Write Data to a Table
In this article, we will write data to a table in DynamoDB. DynamoDB is a NoSQL database that supports semi-structured data i.e. key-value and document data structures. A DynamoDB table contains items. An item is a collection of attributes and each item has a primary key that should be not null. Also, each item can have a different number of attrib
2 min read
AWS DynamoDB - Update Data in a Table
Amazon DynamoDB is a NoSQL managed database that supports semi-structured data i.e. key-value and document data. A DynamoDB table stores data in the form of an item. While creating a table in DynamoDB, a partition key needs to be defined which acts as the primary key for the table and no schema. Each item consists of attributes. By default, every i
2 min read
AWS DynamoDB - Query the Global Secondary Index
Global Secondary Index is an index with a partition key and a sort key that can be different from keys in the base table. A global secondary index is said to be "global" because queries on the index can cover all the data in the base table, across all partitions. A global secondary index has no size limitations like that of the base table and has i
2 min read
AWS DynamoDB - Create a Global Secondary Index
Amazon DynamoDB is a NoSQL-managed database that stores data in the form of key-value pairs and document data. A Dynamodb table stores items which are nothing but key-value pairs. By default, each item will have a partition key to differentiate between the items. When need to perform many kinds of queries, taking different attributes as query crite
2 min read
AWS DynamoDB - Introduction to NoSQL Workbench
This article intends to introduce you to the basics of NoSQL Workbench. NoSQL is basically a nonrelational database, with numerous other extra advantages too. NoSQL Workbench is nothing but a virtual development as well as a testing environment for developers anywhere in the world. It allows its users to test their data models over a large number o
2 min read
AWS DynamoDB - PartiQL Insert Statement
PartiQL is a SQL-compatible query language that supports querying, modifying, and inserting data. It makes it easier to interact with DynamoDB and run queries in AWS Management Console. Insert data into DynamoDB Table using PartiQL: Syntax: INSERT INTO table-name VALUE item;Table name: Required – Name of the table in which you want to insert dataIt
1 min read
AWS DynamoDB - Creating a Table
DynamoDB allows users to create databases capable of storing and retrieving any amount of data and comes in handy while serving any amount of traffic. It dynamically manages each customer’s request and provides high performance by automatically distributing data and traffic over servers. It is a fully managed NoSQL database service that is fast, pr
2 min read
AWS Lambda and Amazon DynamoDB for Serverless Authentication
Serverless Authentication is a method of authenticating users in a cloud-based application without the need for traditional server management. It leverages services like AWS Lambda and Amazon DynamoDB to handle user authentication processes in a cost-effective and efficient manner. By using these serverless components, developers can create secure
14 min read
Creating AWS DynamoDB Table Using Terraform
I'm going to show how to use Terraform to create a DynamoDB table in AWS. Terraform lets you define infrastructure like databases as code. This makes it easy to version control and share with others. In this article, I'll walk through the steps to set up a Terraform file and define a DynamoDB table in it. Then I'll apply the plan to create the real
15+ min read
DynamoDB Dynamo: AWS CLI Commands for NoSQL Database
As we know, there are three main ways to access and manage AWS services, AWS CLI (command line interface), the AWS Management Console, and the AWS SDK(Software (software kit). Here we are working with the first tool, which is AWS CLI (command line interface) which is basically used for interacting with AWS Resources through scripting and automation
7 min read
Difference between AWS Cloudwatch and AWS Cloudtrail
1. AWS Cloudwatch: It is a monitoring tool used for real-time monitoring of AWS resources and applications. It provides a report on the basis of monitoring which can be used to analyze the performance of the system. CloudWatch also detect irregular behavior in your environments. It also sets the alarm. It monitors various AWS resources like Amazon
2 min read
AWS Educate and AWS Emerging Talent Community
If you want to make your career in cloud computing but don’t know how to get started, you must register for AWS Educate. AWS Educate helps in learning cloud skills in more superficial ways that too at your own pace. For that, you only require an email address, not an Amazon account or any credit card. Cloud learners as young as 13 years old can als
2 min read