DEV Community

Revathi Joshi for AWS Community Builders

Posted on • Updated on

 

DynamoDB and its Control Pane Operations - 2

This is the 2nd blog, in the continuation of the article on DynamoDB and its Control Pane Operations - 1.

Please check the 1st article - DynamoDB and its Control Pane Operations - 1, where I have shown you how to create, describe and list the DynamoDB tables.

In this article, I am going to show you the remaining 2 operations

UpdateTable – Modifies the settings of a table.
DeleteTable – Removes a table and all of its dependent objects from DynamoDB.

Let’s get started!

Please visit my GitHub Repository for DynamoDB articles on various topics being updated on constant basis.

Pre-requisites:

Resources Used:

Amazon DynamoDB Developer Guide

Update Table CLI

Objectives:

1. Update the Table - Movies

2. Delete the Table - Movies

Steps for implementation to this project:

1. Update Table - Movies

update-table - Is self-explanatory. It modifies the table.

Upon issuing the update-table request, the status of the table changes from UPDATING to AVAILABLE.

I am going to show you some of the operations on the update-table command, such as

1. Modifies the provisioned throughput settings
2. Changes the table's read/write capacity mode.
3. Creates, updates and deletes the global secondary indexes
4. To enable / disable DynamoDB Streams
5. To enable server-side encryption

1. Modifies the provisioned throughput settings

Operations in DynamoDB consume capacity from the table. When the table is using Provisioned Capacity, read operations will consume Read Capacity Units (RCUs) and write operations will consume Write Capacity Units (WCUs). For more information please see the Read/Write Capacity Mode in the DynamoDB Developer Guide.

  • ReadCapacityUnits The maximum number of strongly consistent reads consumed per second before DynamoDB returns a ThrottlingException.
  • WriteCapacityUnits The maximum number of writes consumed per second before DynamoDB returns a ThrottlingException.
  • Before Updating table - Movies

  • From
    --provisioned-throughput \
    ReadCapacityUnits=10,WriteCapacityUnits=5

aws dynamodb describe-table --table-name Movies
Enter fullscreen mode Exit fullscreen mode

Image description

  • Update the table - Movies
aws dynamodb update-table --table-name Movies \
    --provisioned-throughput ReadCapacityUnits=20,WriteCapacityUnits=10
Enter fullscreen mode Exit fullscreen mode
  • After Updating the table - Movies

  • To
    --provisioned-throughput \
    ReadCapacityUnits=20,WriteCapacityUnits=10

aws dynamodb describe-table --table-name Movies
Enter fullscreen mode Exit fullscreen mode

Image description

2. Changes the table's read/write capacity mode

Modify a table's read/write capacity mode to on-demand mode.

On-demand mode Is a flexible billing option which offers

pay-per-request for read and write requests so that you pay only for what you use.

  • Specify throughput capacity in terms of read request units (RRUs) and write request units (WRUs).
aws dynamodb update-table --table-name Movies \
    --billing-mode PAY_PER_REQUEST
Enter fullscreen mode Exit fullscreen mode

You have to wait 4-5 min in order to get this updated.

Image description

3. Creates, updates and deletes the global secondary indexes

Global secondary indexes are used to query different attributes of a table

  • The maximum limit is 20

Create a json file gsi-updates.json

[
    {
        "Create": {
            "IndexName": "MoviesList-index",
            "KeySchema": [
                {
                    "AttributeName": "MoviesList",
                    "KeyType": "HASH"
                }
            ],
            "ProvisionedThroughput": {
                "ReadCapacityUnits": 10,
                "WriteCapacityUnits": 10
            },
            "Projection": {
                "ProjectionType": "ALL"
            }
        }
    }
]
Enter fullscreen mode Exit fullscreen mode

Creates a global secondary index, using gsi-updates.json

aws dynamodb update-table \
    --table-name Movies \
    --attribute-definitions AttributeName=MoviesList,AttributeType=S \
    --global-secondary-index-updates file://gsi-updates.json
Enter fullscreen mode Exit fullscreen mode

You have to wait 4-5 min in order to get this updated.

Image description

4. To enable / disable DynamoDB Streams

**DynamoDB Streams is an optional feature that captures data modification events in DynamoDB tables, such as adding, updating and deleting data.

  • Each event is represented by a stream record.

Enable DynamoDB Streams

aws dynamodb update-table \
    --table-name Movies \
    --stream-specification StreamEnabled=true,StreamViewType=NEW_IMAGE
Enter fullscreen mode Exit fullscreen mode

Image description

From Amazon DynamoDB Dashboard / Tables / Choose Movies / Explore table items / Exports and streams / DynamoDB stream details

Stream status: Enabled

Image description

Disable DynamoDB Streams

aws dynamodb update-table \
    --table-name Movies \
    --stream-specification StreamEnabled=false 
Enter fullscreen mode Exit fullscreen mode

From Amazon DynamoDB Dashboard / Tables / Choose Movies / Explore table items / Exports and streams / DynamoDB stream details

Stream status: Disabled

Image description

5. To enable server-side encryption

Server-side encryption that uses Key Management Service.

If enabled (true), The key is stored in your account and is managed by KMS (KMS charges apply).

  • server-side encryption type is set to KMS and an Amazon Web Services managed key is used
aws dynamodb update-table \
    --table-name Movies \
    --sse-specification Enabled=true,SSEType=KMS
Enter fullscreen mode Exit fullscreen mode

Image description

If disabled (false) or not specified, server-side encryption is set to Amazon Web Services owned key.

  • server-side encryption - not specified
aws dynamodb update-table \
    --table-name Movies \
    --sse-specification Enabled=false
Enter fullscreen mode Exit fullscreen mode

Image description

2. Delete Table - Movies

aws dynamodb delete-table --table-name Movies
Enter fullscreen mode Exit fullscreen mode

Cleanup

  • Nothing to Cleanup
  • The table - Movies is already deleted

What we have done so far

Successfully performed update and delete operations on the DynamoDB table - Movies

Top comments (0)

Here is a post you might want to check out:

Regex for lazy developers

regex for lazy devs

Sorry for the callout 😆