Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Client Doesn't Honor Region when used as documented. #30

Closed
josephpohlmann opened this issue Jul 20, 2021 · 1 comment
Closed

Client Doesn't Honor Region when used as documented. #30

josephpohlmann opened this issue Jul 20, 2021 · 1 comment

Comments

@josephpohlmann
Copy link
Contributor

Simply stated, this doesn't work (as it always assumes region of 'us-east-1'):

import localstack_client.session as boto3
lambda_client = boto3.client('lambda', region_name='us-west-2')
lambda_client.invoke(...)

But this works:

from localstack_client.session import Session
sess = Session(region_name='us-west-2')
lambda_client = sess.client('lambda')

This is because, if you look at the code,

def client(*args, **kwargs):
return _get_default_session().client(*args, **kwargs)

_get_default_session() always returns a defaulted Session item, not allowing you to modify it. Creating the client() from that doesn't honor the kwargs either.

This all appears to be designed to use a single global Session, but I must admit, I don't see a benefit to that. We should be able to create multiple sessions, into multiple regions, within a given "account".

I believe that, assuming you want to use the global space, would be to allow for multiple global sessions, specified by the kwargs passed in. Alternatively, could you just only support the global entry for a client/resourse request with no kwargs?

def client(*args, **kwargs):
if not kwargs:
return _get_default_session().client(*args, **kwargs)
else:
return Session(**kwargs).client(*args, **kwargs)

With the change above:

import localstack_client.session as boto3
c = boto3.client('lambda', region_name='us-west-2')
c._client_config.region_name
'us-west-2'
c2 = boto3.client('lambda')
c2._client_config.region_name
'us-east-1'

josephpohlmann added a commit to josephpohlmann/localstack-python-client that referenced this issue Jul 20, 2021
@whummer
Copy link
Member

whummer commented Aug 30, 2021

Fixed in #31 . Thanks!

@whummer whummer closed this as completed Aug 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants