boto3: KeyError: 'endpoint_resolver'
Hi,
I sometimes get that error trying to call a lambda function boto3==1.3.1
def lambda_execute(payload):
import boto3
client = boto3.client('lambda', aws_access_key_id=KEY, aws_secret_access_key=SECRET region_name=REGION)
client.invoke(**payload)
payload is in this format:
{'FunctionName': fct, 'InvocationType': 'Event', 'LogType': 'None', 'Payload': simplejson.dumps(payload, default=encode_model)}
error seems to be coming from get_component in botocore/session.py

Can you help ?
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 17
- Comments: 31 (3 by maintainers)
Commits related to this issue
- Client creation is not thread safe See: https://github.com/boto/boto3/issues/801 — committed to camptocamp/tilecloud by sbrunner 3 years ago
- Client creation is not thread safe See: https://github.com/boto/boto3/issues/801 — committed to camptocamp/tilecloud by sbrunner 3 years ago
- Client creation is not thread safe See: https://github.com/boto/boto3/issues/801 — committed to camptocamp/tilecloud by sbrunner 3 years ago
- Client creation is not thread safe See: https://github.com/boto/boto3/issues/801 — committed to camptocamp/tilecloud by sbrunner 3 years ago
- Client creation is not thread safe See: https://github.com/boto/boto3/issues/801 — committed to camptocamp/tilecloud by sbrunner 3 years ago
- Boto client creation is not thread-safe See https://github.com/boto/boto3/issues/801 — committed to hasgeek/imgee by jace 3 years ago
- Modify method of creating session https://github.com/boto/boto3/issues/801 — committed to cjsrkd3321/aws-security-architectures by cjsrkd3321 2 years ago
- Modify method of creating session https://github.com/boto/boto3/issues/801 — committed to cjsrkd3321/aws-security-architectures by cjsrkd3321 2 years ago
- Always use boto3 session when creating different objects. As suggested here https://github.com/boto/boto3/issues/801#issuecomment-875140699, The occasional error we get `KeyError: 'endpoint_resolve... — committed to opengisch/qfieldcloud by suricactus a year ago
- Use boto3 session instead of boto3 client boto3 client has known issues for multithreading. https://github.com/boto/boto3/issues/801 One solution is to use session instead. — committed to superpilot/django-iam-dbauth by superpilot a year ago
Hi James, Yes it is - weird it hasn’t been raised before. would you recommend this as a solution? https://geekpete.com/blog/multithreading-boto3/
I changed s3 = boto3.resource(‘s3’) to below and it work for me
Is this function being called in multiple threads? The only way I see that happening is if
boto3.clientis being invoked in multiple threads (client creation is not thread safe).@cpury: I ran into the same issue as well. I wasn’t comfortable creating a global client due to this documentation, so I tried until I get a client, e.g.
This seems to work.
Thanks for your answer, it works for me 😃
Ideal fix would be
(note that its not using sesion.resource() which is only applicable for small number of resources)
All the clients created using boto3.client()/boto3.resource() share default global session and thus aren’t thread safe. https://github.com/boto/boto3/blob/c9399569448890ea78f5ba8e8ae8a55b8fddc3ce/boto3/__init__.py#L85-L100
I observe similar behavior on v1.9.16, but the error is
KeyError: 'credential_provider'and it depends on the number of workers in a ThreadPool. For me the error seems to happen only when the number of threads is more than half (n/2+1) of tasks.Making client global also “fixes” the error.
#1592 seems to be relevant.
A simple solution based on what I read above, if you want to use threads and not multiprocessing, - works fine.
Wow, super weird! Inspired by your code, I changed mine to use a global lambda client object that’s shared among all threads. AKA, do exactly the opposite of what’s recommended here in this ticket. And that fixes it!
So for anyone running into the same issue: Just use a global lambda object. And if anyone of the boto3 team wants to explain how this makes sense, please do, I’m curious 😃
I’m using uWSGI
lazy-apps=trueand still getting this issue. Running single process, multiple threads enabled, but not explicitly invoked in Django 2.2, Python 3.8.@vinczente Yes, each thread should have its own session.
I’m running into this now. I have a Flask application sitting behind Apache. When multiple clients are accessing a resource in the Flask app, that request triggers a boto3.client(‘s3’).list_objects call, where this error comes up. My app is using “boto3”:“1.7.4” and “botocore”:“1.10.6”.