Error: can't pickle thread.lock objects typeerror boto3 python dynamodb

Answered by Rafal Wilinski
Last updated: October 23rd, 2026
Solution
“Can’t pickle thread lock objects” often occurs when multiprocessing or a task queue tries to serialize a boto3 client, resource, session, or an object that contains one. This is Python process-transfer behavior, not a DynamoDB serialization error. Create the client inside the worker instead.
from concurrent.futures import ProcessPoolExecutor
import boto3
def fetch_order(order_id):
session = boto3.session.Session(region_name="us-east-1")
db = session.client("dynamodb")
return db.get_item(TableName="Orders", Key={"id": {"S": order_id}}).get("Item")
if __name__ == "__main__":
with ProcessPoolExecutor() as pool:
items = list(pool.map(fetch_order, ["123", "456"]))Pass strings, numbers, and plain task dictionaries across the process boundary. A bound method can still capture self and its client, so inspect the whole object being submitted. For repeated tasks, a process initializer can create one client per worker.
Boto3 clients must not be shared across processes. Resources and sessions also have threading restrictions. Replacing a lock with a semaphore does not make the client safe to serialize; keep network clients local to the execution context that owns them.
See Python SDK usage and AWS documentation.
Other Common DynamoDB Errors (with Solutions)
- DynamoDB is missing the key id in the item
- dynamodb getItem() is not a function
- a socket operation was attempted to an unreachable network dynamodb
- why is the GSI dynamodb not showing item count
- dynamodb validation error detected
- DynamoDB TTL Not Working
- AWS CLI DynamoDB Error Parsing Parameter
- DynamoDB Contains not working
- aws.dynamodb.documentclient is not a constructor
- DynamoDB scan filter expression not working
- DynamoDB no attribute schema defined
- Conditional Update Error DynamoDB
- DynamoDB stream lambda error
- DynamoDB failedbatch retry
- dynamodb property projection cannot be empty
Dynobase is a Professional GUI Client for DynamoDB
Start your 7-day free trial today