Home > Blockchain >  Set Dynamodb tables replication with boto3 as soon as possible
Set Dynamodb tables replication with boto3 as soon as possible

Time:12-16

I'm creating dynamodb tables with boto3/python using the client.create_table() method, an asynchronous action. However, you cannot create a global table(replication) until "after" the table is in ACTIVE status. We would like the replication to happen as soon as possible, however, we need to return to the user ASAP and can't wait for the tables to be ready and run create_global_table() on them.

My first thoughts are to create an SQS message referencing the new tables that can then be processed by a lambda to monitor the status of said table until the status is ACTIVE and only then make the call to replicate the table, and only then delete the message.

I suppose I could also create a lambda that runs every minute and scans for tables that don't have global tables enabled then run create_global_table() on them. This seems in efficient these tables are not created very often.

Can anyone think of a better way of doing this?

CodePudding user response:

If the client doesn't need to wait until the table is created, just set up a SQS Queue with a Lambda function behind it.

When a client requests a new table to be created, you send a message to the queue and respond to the client with something along the lines of the HTTP 202 status code.

You can then write the Lambda function that listens to the queue in a way to create the table, wait for it to become active and then create a global table.


Another option would be a Step Function that creates the table, then you loop until it becomes active and afterwards create the global table. Then you'd have no long running lambdas. You could trigger the step function from the initial lambda that accepts the request.

  • Related