Shubham Namdeo
Shubham Namdeo

Reputation: 1925

DynamoDB: Create Table with keytype for nested json using Boto3

I am trying to create a new table in DynamoDB using my data format from MongoDB. I know how to create basic tables and update data, however, for nested JSON body I am unable to create KeySchema as I am new to this.

My JSON example:

{
    'Name':"fresco"
    'Tags':{
        'Genre':'Jazz'
        'Albums':['aa','bb''cc']}
    'Year:'2009
}

I am using boto3 and I know how to connect with AWS, I just need some help with keyschema for this JSON body. Also, I've read about Map attribute from AWS docs but there was no implementation for that.

My Code:

import boto3
dynamodb =boto3.resource('dynamodb')
table = dynamodb.create_table(
    TableName = 'newTable'
    KeySchema = [
    {
        'AttributeName': 'Name',
        'KeyType': 'Hash'
    },
    {
        'AttributeName': 'Tags',
        'KeyType': 'Hash'
    },
    {
        'AttributeName': 'Year',
        'KeyType': 'Hash'
    }

    ],

    AttributeDefinitions=[
    {
        'AttributeName': 'Name',
        'AttributeType': 'S'
    },
    {
        'AttributeName': 'Tags',
        'AttributeType': #dont know what to put in here.
    },
    {
        'AttributeName': 'Year',
        'AttributeType': 'N'
    },


    ],

    ProvisionedThroughput ={
    'ReadCapacityUnits': 5,
    'WriteCapacityUnits': 5

    }

)

Upvotes: 2

Views: 2695

Answers (1)

smcstewart
smcstewart

Reputation: 2085

In DynamoDB you can only have one partition key or one partition key + one sort key. And you also have limits on the length of your key too - so tags may not be the best fit. Best to read the developer docs.

Upvotes: 2

Related Questions