Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is boto library thread-safe?

Specifically I'm interested in using a DynamoDB table object from multiple threads (puts, gets, updates, etc). If that's not safe, then is there a safe way (i.e., maybe one table object per thread)? Any other gotchas or tips about working with threads in boto appreciated.

like image 729
macsh Avatar asked Oct 22 '13 16:10

macsh


People also ask

What does Boto3 library do?

Boto3 makes it easy to integrate your Python application, library, or script with AWS services including Amazon S3, Amazon EC2, Amazon DynamoDB, and more.

Should I use client or resource Boto3?

To summarize, resources are higher-level abstractions of AWS services compared to clients. Resources are the recommended pattern to use boto3 as you don't have to worry about a lot of the underlying details when interacting with AWS services. As a result, code written with Resources tends to be simpler.

How long does Boto3 session last?

The maximum duration of the validity of the token is 12 hours (provided it is configured in the role).

What is the difference between Boto3 client and Boto3 resource?

Client simply exposes the underlying AWS APIs in a mildly Pythonic way whereas a given boto3 service implementation can expose multiple Resources (e.g. S3 exposes Bucket and Object). They're typically identified by name rather than ARN, in keeping with the high-level nature of the Resource API.


1 Answers

The boto library uses httplib which has never been, and to my knowledge still is not, thread-safe. The workaround is to make sure each thread creates its own connection to DynamoDB and you should be good.

like image 73
garnaat Avatar answered Sep 21 '22 11:09

garnaat