DynamoDB and its Control Pane Operations - 2
Tags: dynamodb, cli, aws, crud
Published: 2022-12-07 02:53:04

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](https://dev.to/aws-builders/dynamodb-and-its-control-pane-operations-1-36bk), 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](https://github.com/awsmine/DynamoDB_projects)** on various topics being updated on constant basis.

# Pre-requisites:
- AWS user account with admin access, not a root account.
- Cloud9 IDE with AWS CLI.
- Create the DynamoDB table - **Movies** from the [previous article DynamoDB and its Control Pane Operations - 1](https://dev.to/aws-builders/dynamodb-and-its-control-pane-operations-1-36bk)



# Resources Used:
[Amazon DynamoDB Developer Guide](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Introduction.html)

[Update Table CLI](https://docs.aws.amazon.com/cli/latest/reference/dynamodb/update-table.html)

# 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](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.ReadWriteCapacityMode.html) 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
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fe6wyfvx6ihxrnwehazx.png)



- **Update the table** - Movies 
```
aws dynamodb update-table --table-name Movies \
    --provisioned-throughput ReadCapacityUnits=20,WriteCapacityUnits=10
```
- **After Updating the table** - Movies 

- To
--provisioned-throughput \
        ReadCapacityUnits=20,WriteCapacityUnits=10
```
aws dynamodb describe-table --table-name Movies
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bfaac8mbee3gj9zc42dv.png)


**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
```

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


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pvpx6ssly18wipjbg6fi.png)



**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"
            }
        }
    }
]
```
**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
```

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


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h80vlp5e50kob6otpetd.png)






**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
```


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rgtiui8ybujtpp2algb9.png)

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

**Stream status:** Enabled


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/boxlbv8fdoom1xq00mbz.png)




**Disable DynamoDB Streams**

```
aws dynamodb update-table \
    --table-name Movies \
    --stream-specification StreamEnabled=false 
```


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

**Stream status:** Disabled

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/knlvzbqtt779pkxi7yag.png)



**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
```


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7orwdp0mnjpxbpz6e2ow.png)




> 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
```


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pfk3sw16i9ov153auxc2.png)




## 2. Delete Table - Movies

```
aws dynamodb delete-table --table-name Movies
```

# 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**