2

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

    }

)

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Okay, I got that, So there is any way to provide nested json via python?
Yes. Look at [maps (M) in here][1]. And use the DynamoDB console to paste in JSON and get a feel for what special JSON DynamoDB expects. [1]: boto3.readthedocs.io/en/latest/reference/services/…
Thanks, found it now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.