- Open the DynamoDB console at https://console.aws.amazon.com/dynamodb/
- In the navigation pane on the left side of the console, choose Dashboard.
- On the right side of the console, choose Create Table.
- Enter the table details as follows:
- For the table name, enter a unique table name.
- For the partition key, enter
Artist. - Enter
SongTitleas the sort key. - Choose Customize settings.
- On Read/write capacity settings choose Provisioned mode with autoscale capacity with a minimum capacity of 1 and maximum of 10.
- Choose Create to create the table.
- On DynamoDB web console page, choose PartiQL editor on the left side menu.
- The following example creates several new items in the
<table-name>table. The PartiQL is a SQL-compatible query language for DynamoDB.
INSERT INTO "<table-name>" VALUE {'Artist':'No One You Know','SongTitle':'Call Me Today', 'AlbumTitle':'Somewhat Famous', 'Awards':'1'}
INSERT INTO "<table-name>" VALUE {'Artist':'No One You Know','SongTitle':'Howdy', 'AlbumTitle':'Somewhat Famous', 'Awards':'2'}
INSERT INTO "<table-name>" VALUE {'Artist':'Acme Band','SongTitle':'Happy Day', 'AlbumTitle':'Songs About Life', 'Awards':'10'}
INSERT INTO "<table-name>" VALUE {'Artist':'Acme Band','SongTitle':'PartiQL Rocks', 'AlbumTitle':'Another Album Title', 'Awards':'8'}Query the data by
SELECT * FROM "<table-name>" WHERE Artist='Acme Band' AND SongTitle='Happy Day'From your local machine, write some more items using the aws dynamodb put-item command.
Use the aws dynamodb get-item to get some item.
Write
aws dynamodb put-item --table-name Music --item '{"Artist": {"S": "No One You Know"}, "SongTitle": {"S": "Call Me Today"}, "AlbumTitle": {"S": "Somewhat Famous"}, "Awards": {"N": "1"}}'Get
aws dynamodb get-item --table-name Music --key '{ "Artist": {"S": "Acme Band"}, "SongTitle": {"S": "Happy Day"}}'-
In the navigation pane on the left side of the console, choose Tables.
-
Choose your table from the table list.
-
Choose the Indexes tab for your table.
-
Choose Create index.
-
For the Partition key, enter
AlbumTitle. -
For Index name, enter
AlbumTitle-index. -
Leave the other settings on their default values and choose Create index.
-
You query the global secondary index through PartiQL by using the Select statement and providing the index name
SELECT * FROM "<table-name>"."AlbumTitle-index" WHERE AlbumTitle='Somewhat Famous'Enter the interactive self-check page
Database migration is the process of transferring data and schema from one database to another, typically when transitioning to a new system or version.
Zero downtime database migration refers to the seamless migration of a database without any interruption or impact on the availability of the system. It involves careful planning, replication, and synchronization techniques to ensure continuous service while transitioning to the new database environment.
- Start
mongodocker container. - Start the script under
db_migration/init.py. The script should write new data to your running mongo every second. Keep this script running while you work on your next step. - Based in the script in
db_migration/init.py, create another script calledmirror_db.pysuch that every data that is written to mongo will be written to dynamoDB table (create this table withdataIdas a partition key). - (Optional) Use
try...exceptto catch and handle the case where the write operation for either mongo or dynamo is failed. - Stop the running script from step 2, keep the timestamp of the last document that was written to mongo.
- Start the
mirror_db.pyscript. From now on, every piece of data is being written to both mongo and dynamo. You only need to create to the data written before you started the mirror script. - Write a script that copies all the documents with timestamp smaller than or equal to the timestamp you kept from step 5. This script should be run only once.
After a while... stop the mirror_db.py script and check that the data stored in both DBs is identical (you may write some python script for that).
Restore your table to how it was looking like a few minutes ago.