Reputation: 33
I am using batch_execute_statement
to update the data in dynamodb in AWS Lambda. To do so, I am getting the boto3 client from a resource like this:
boto3.resource('dynamodb').meta.client.batch_execute_statement(Statements=statements)
As batch_execute_statement
has a limitation to take 25 statements at a time, I want to use multi-treading to make this faster.
[What I have tried]
batch_execute_statement
with a batch of 25 statements at a time. It is working as expected and updating the data in dynamodb.dynamodb_resource_object = boto3.resource('dynamodb')
concurrent.futures.ThreadPoolExecutor
, submit batches to call batch_execute_statement
like:dynamodb_resource_object.meta.client.batch_execute_statement(Statements=statements)
[QUE]
I followed these references:
Upvotes: 3
Views: 825
Reputation: 19893
DynamoDB boto3 resource client is not thread safe. You should create a new client for each process.
DynamoDB does not provide an official way to do BatchUpdate. I would suggest to use the UpdateItem API and perhaps an async client, such as boto3aio
Upvotes: 1