DynamoDB is all about knowing your data access patterns

This because using the primary key will usually result in a much lower cost query and how do you do that?

Avoid the “table.scan” function at all cost, as it will scan all rows in your table, even if you eventually don’t need 99.9999% of them, and the count against your consumed RCUs.

import boto3 from boto3.dynamodb.conditions import Key

TABLE_NAME = "Songs"

# Create the DynamoDB Client
dynamodb_client = boto3.client('dynamodb', region_name="us-east-1")

# Creating the DynamoDB Table Resource
dynamodb = boto3.resource('dynamodb', region_name="us-east-1")
table = dynamodb.Table(TABLE_NAME)

# Use the Table resource to query for all songs by artist Arturus Ardvarkian
response = table.query(
  KeyConditionExpression=Key('artist').eq('James Douglas Morrison')
)
print(response['Items'])
#Extract the Results
    items = response['Items']
    for item in items:
        artistName = item['artist']
        songTitle = item['SongTitle']
        size = sys.getsizeof(item)
        print(str(queryCount) + ' - ' + artistName + ' - ' + songTitle + ' - ' + str(size))

Leave a Comment

Scroll to Top