Hands-On Lab861 words

Hands-On Lab: Designing Cost-Optimized Database Solutions on AWS

Design cost-optimized database solutions

Hands-On Lab: Designing Cost-Optimized Database Solutions on AWS

Welcome to this Hands-On Lab focused on Domain 4 of the AWS Certified Solutions Architect - Associate (SAA-C03) exam. In this lab, we will explore database capacity planning by provisioning an Amazon DynamoDB table, adding cost-allocation tags for the AWS Cost Explorer, and migrating the table to a serverless, pay-per-request billing model to optimize costs for unpredictable workloads.

Prerequisites

Before starting this lab, ensure you have the following:

  • AWS Account: An active AWS account with Administrator access.
  • AWS CLI: Installed and configured (aws configure) with valid access keys.
  • IAM Permissions: Policies allowing dynamodb:* actions.
  • Prior Knowledge: Basic understanding of NoSQL databases and AWS pricing models (Provisioned vs. Serverless/On-Demand).

Learning Objectives

Upon completing this lab, you will be able to:

  1. Provision an Amazon DynamoDB table with defined Read/Write Capacity Units (RCUs and WCUs).
  2. Apply Cost Allocation Tags to AWS database resources for detailed billing visibility.
  3. Transition a database from provisioned capacity to On-Demand (Serverless) to optimize costs for spiky or unpredictable workloads.

Architecture Overview

The following flowchart illustrates the resource lifecycle we will build and modify in this lab:

Loading Diagram...

Mathematical Concept: Capacity Cost Formula

When using Provisioned Capacity, your monthly cost is fixed regardless of usage. The baseline cost is calculated using this formula:

\mboxMonthlyCost=(\mboxRCU×\mboxRateRCU×730\mboxhours)+(\mboxWCU×\mboxRateWCU×730\mboxhours)+\mboxStorageCost\mbox{Monthly Cost} = (\mbox{RCU} \times \mbox{Rate}_{RCU} \times 730 \mbox{ hours}) + (\mbox{WCU} \times \mbox{Rate}_{WCU} \times 730 \mbox{ hours}) + \mbox{Storage Cost}

[!NOTE] In contrast, On-Demand pricing is calculated strictly as: \mboxCost=\mboxReadRequestUnits(RRU)×\mboxRateRRU+\mboxWriteRequestUnits(WRU)×\mboxRateWRU\mbox{Cost} = \mbox{Read Request Units (RRU)} \times \mbox{Rate}_{RRU} + \mbox{Write Request Units (WRU)} \times \mbox{Rate}_{WRU}

Below is a visual representation of how cost scales between the two models:

Compiling TikZ diagram…
Running TeX engine…
This may take a few seconds

Step-by-Step Instructions

Step 1: Provision a DynamoDB Table with Provisioned Capacity

First, we will create a DynamoDB table named brainybee-lab-orders using a provisioned capacity model. This represents a traditional, fixed-cost database architecture.

bash
aws dynamodb create-table \ --table-name brainybee-lab-orders \ --attribute-definitions AttributeName=OrderID,AttributeType=S \ --key-schema AttributeName=OrderID,KeyType=HASH \ --provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5 \ --region us-east-1

[!TIP] Provisioned throughput is measured in Capacity Units. 5 RCUs and 5 WCUs fit well within the AWS Free Tier, ensuring this step does not incur immediate charges.

Console alternative
  1. Navigate to the DynamoDB Console.
  2. Click Create table.
  3. Enter Table name: brainybee-lab-orders.
  4. Enter Partition key: OrderID (Type: String).
  5. Under Table settings, select Customize settings.
  6. Under Read/write capacity settings, select Provisioned and set Read and Write capacity to 5.
  7. Click Create table.

📸 Screenshot: Customize settings showing 5 RCU and 5 WCU.

Step 2: Apply Cost Allocation Tags

To effectively monitor cost optimization (a critical skill for Task 4.3 of the SAA-C03 exam), resources must be tagged so they can be filtered in AWS Cost Explorer and AWS Budgets.

Note: Retrieve your table's ARN from the output of Step 1, or replace <YOUR_ACCOUNT_ID> appropriately below.

bash
aws dynamodb tag-resource \ --resource-arn arn:aws:dynamodb:us-east-1:<YOUR_ACCOUNT_ID>:table/brainybee-lab-orders \ --tags Key=Environment,Value=Lab Key=CostCenter,Value=DB-Optimization \ --region us-east-1

[!IMPORTANT] For tags to appear in AWS Billing, an Administrator must explicitly activate them in the Cost Allocation Tags section of the Billing Console.

Console alternative
  1. In the DynamoDB Console, select the brainybee-lab-orders table.
  2. Go to the Additional settings tab.
  3. Scroll down to Tags and click Manage tags.
  4. Click Add new tag.
  5. Enter Key: Environment, Value: Lab.
  6. Enter Key: CostCenter, Value: DB-Optimization.
  7. Click Save changes.

Step 3: Optimize Costs by Switching to On-Demand Capacity

Assume the brainybee-lab-orders database experiences highly unpredictable, spiky traffic. Paying a flat hourly rate for provisioned capacity wastes money during idle hours. We will migrate the database to On-Demand (Serverless) mode to optimize costs.

bash
aws dynamodb update-table \ --table-name brainybee-lab-orders \ --billing-mode PAY_PER_REQUEST \ --region us-east-1

[!TIP] Changing the billing mode to PAY_PER_REQUEST involves zero downtime. AWS handles the seamless transition of the underlying partition management.

Console alternative
  1. In the DynamoDB Console, select the brainybee-lab-orders table.
  2. Navigate to the Capacity tab (or Additional settings depending on console version).
  3. In the Capacity mode section, click Edit.
  4. Change the selection from Provisioned to On-demand.
  5. Click Save changes.

📸 Screenshot: Radio button toggled from Provisioned to On-demand.

Checkpoints

Let's verify that our table successfully transitioned to On-Demand capacity and that our cost tags are applied.

1. Verify Billing Mode:

bash
aws dynamodb describe-table --table-name brainybee-lab-orders --query "Table.BillingModeSummary.BillingMode" --output text

Expected Output: PAY_PER_REQUEST

2. Verify Tags:

bash
aws dynamodb list-tags-of-resource --resource-arn arn:aws:dynamodb:us-east-1:<YOUR_ACCOUNT_ID>:table/brainybee-lab-orders

Expected Output: A JSON array containing your Environment and CostCenter tags.

Clean-Up / Teardown

[!WARNING] Remember to run the teardown commands to avoid ongoing charges. Even though On-Demand charges per request, the table consumes storage space which incurs a tiny monthly cost.

To clean up the resources deployed in this lab, run the following command to delete the table:

bash
aws dynamodb delete-table \ --table-name brainybee-lab-orders \ --region us-east-1
Console alternative
  1. In the DynamoDB Console, select the brainybee-lab-orders table.
  2. Click the Delete button at the top right.
  3. Type confirm in the text box to validate the deletion.
  4. Click Delete table.

Troubleshooting

Common ErrorCauseSolution
ResourceNotFoundExceptionThe specified table name or ARN does not exist.Verify your spelling of brainybee-lab-orders, ensure you are in the correct --region, and verify your <YOUR_ACCOUNT_ID> in the ARN.
ValidationExceptionTrying to change billing mode too frequently.AWS limits how often you can switch between Provisioned and On-Demand (once every 24 hours). Wait if you recently switched it.
UnrecognizedClientExceptionInvalid or expired AWS credentials.Run aws configure to provide valid Access Key ID and Secret Access Key.
AccessDeniedExceptionThe IAM user lacks permissions for DynamoDB.Ensure your IAM user has AmazonDynamoDBFullAccess or equivalent inline policy.

Ready to study AWS Certified Solutions Architect - Associate (SAA-C03)?

Practice tests, flashcards, and all study notes — free, no sign-up needed.

Start Studying — Free