Home > Software design >  Create Global Secondary Index (GSI) for DynamoDB using Boto3 in Python
Create Global Secondary Index (GSI) for DynamoDB using Boto3 in Python

Time:05-07

I'm creating a DynamoDB table using the Python boto3 package:

import boto3
ddb = boto3.resource('dynamodb')
table = ddb.create_table(
    TableName = "MyTable",
    KeySchema = [
        {
            'AttributeName': 'key1',
            'KeyType': 'HASH'
        },
        {
            'AttributeName': 'key2',
            'KeyType': 'RANGE'
        }
    ],
    AttributeDefinitions = [
        {
            'AttributeName': 'key1',
            'AttributeType': 'S'
        },
        {
            'AttributeName': 'key2',
            'AttributeType': 'S'
        }
    ],
    ProvisionedThroughput = {
        'ReadCapacityUnits': 1,
        'WriteCapacityUnits': 1
    }
)

I want to know if it is possible to create a global secondary key (GSI) when creating the table using this package, and how to do it. I see that it is possible to update a table to contain a GSI, though (GSI on MyTable

  • Related