Skip to main content

dynamodb-migrator

Build Status Coverage Status PyPI version

A library that helps you create and migrate DynamoDB databases.

As performant DynamoDB is, that does come with the trade-off of being inflexible. Changing column names or adding secondary indexes is impossible.
The recommended approach is to create a new table with the desired properties, and migrate the existing data.
This library will help you do just that.

Usage

  • Write a migration script
  • Execute the migration script as a step in the build pipeline
  • Add to the migration-script as required

Example Script

from migrator.dynamodb_migrator import Migrator
migrator = Migrator()
@migrator.version(1)
@migrator.create(AttributeDefinitions=[{'AttributeName': 'hash_key', 'AttributeType': 'N'}],
                 TableName='my_new_table',
                 KeySchema=[{'AttributeName': 'hash_key', 'KeyType': 'HASH'}],
                 BillingMode='PAY_PER_REQUEST')
def v1(created_table):
    print("Table created using the kwargs provided")
    print("Note that the keyword-args are passed onto boto as is")
    print(created_table)


@migrator.version(2)
@migrator.add_index(AttributeDefinitions=[{'AttributeName': 'postcode', 'AttributeType': 'S'}],
                    LocalSecondaryIndexes=[{'IndexName': 'string',
                                            'KeySchema': [{'AttributeName': 'customer_nr', 'KeyType': 'HASH'},
                                                          {'AttributeName': 'postcode', 'KeyType': 'RANGE'}],
                                            'Projection': {'ProjectionType': 'ALL'}}])
def v2(created_table):
    print("Created a new table with the new index")
    print("Created a DynamoDB stream that sends all updates to the old table to a custom Lambda-function")
    print("The custom Lambda-function sends all updates to the new table")
    print(created_table)


@NotYetImplemented
@migrator.version(3)
@migrator.delete_table("first_table")
def v3(migrate):
    print("About to delete table")
    print("Ensure that all upstream applications point to the new table, before adding this part to the pipeline!")
    migrate()
    print("Table deleted")


@NotYetImplemented
@migrator.version(4)
@migrator.convert(lambda item -> {'id': translate(item.id)})
def v4(migrate):
    print("About to:")
    print(" - Create new table (first_table_v4)")
    print(" - Create a AWS Lambda script that will execute the above lambda, and write the result int he new table")
    print(" - Create DynamoDB Stream on 'first_table' that triggers the new Lambda")
    print(" - Execute a script that automatically updates all existing data")
    print("   (This will trigger all data in 'first_table' to be converted and copied into the new table")
    migrate()
    print("Table with new data is ready to use")

Examples

See the examples-folder.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dynamodb-migrator-0.0.8.tar.gz (9.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dynamodb_migrator-0.0.8-py3-none-any.whl (16.1 kB view details)

Uploaded Python 3

File details

Details for the file dynamodb-migrator-0.0.8.tar.gz.

File metadata

  • Download URL: dynamodb-migrator-0.0.8.tar.gz
  • Upload date:
  • Size: 9.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.5

File hashes

Hashes for dynamodb-migrator-0.0.8.tar.gz
Algorithm Hash digest
SHA256 1c5d1470c7b58089d2356c930c4ce4da3ae9169fbdab9abd5c895f1c6365da8d
MD5 0e29b61477ea40c2a09cc583fbd65355
BLAKE2b-256 e996be752d01579455eab70bbc375b42d2e955fc52462204313551a6e0eca050

See more details on using hashes here.

File details

Details for the file dynamodb_migrator-0.0.8-py3-none-any.whl.

File metadata

  • Download URL: dynamodb_migrator-0.0.8-py3-none-any.whl
  • Upload date:
  • Size: 16.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.5

File hashes

Hashes for dynamodb_migrator-0.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 df91e6717fa7494c8362641e0168395911b4a543bb6c3ab839d6032a09f66b4b
MD5 69f827ef7f86e8d0538d5af07e9be902
BLAKE2b-256 7999b6c400cd54bed60181039723b17e467cd88cc25177da48f58070293d7d13

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.0.8 This release

2 files

0.0.7

2 files

0.0.6

2 files

0.0.5

2 files

0.0.4

2 files

0.0.3

2 files

0.0.2

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page