Using aws session to create clients results in "TypeError: client() missing 1 required positional argument: 'self'"
See original GitHub issueHi I’m trying to use the boto3 session in a container to create new boto3 clients. I’m running into the error "TypeError: client() missing 1 required positional argument: 'self'"
. Am I setting this up correctly?
import boto3.session
class Boto3ContainerWorking(containers.DeclarativeContainer):
config = providers.Configuration()
session = providers.Singleton(
boto3.session.Session,
aws_access_key_id=config.aws_access_key_id,
aws_secret_access_key=config.aws_secret_access_key,
aws_session_token=config.aws_session_token
)
s3_client = providers.Singleton(
session().client, # <------ this works
service_name='s3'
)
class Boto3ContainerNotWorking(containers.DeclarativeContainer):
config = providers.Configuration()
session = providers.Singleton(
boto3.session.Session,
aws_access_key_id=config.aws_access_key_id,
aws_secret_access_key=config.aws_secret_access_key,
aws_session_token=config.aws_session_token
)
s3_client = providers.Singleton(
session.provides.client, # <------ this doesn't work
service_name='s3'
)
def main_not_working():
container = Boto3ContainerNotWorking()
container.init_resources()
container.wire(modules=[sys.modules[__name__]])
s3_client = container.s3_client() # breaks here with "TypeError: client() missing 1 required positional argument: 'self'"
def main_working():
container = Boto3ContainerWorking()
container.init_resources()
container.wire(modules=[sys.modules[__name__]])
s3_client = container.s3_client() # This passes
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (6 by maintainers)
Top Results From Across the Web
TypeError: Missing 1 required positional argument: 'self'
You need to instantiate a class instance here. Use p = Pump() p.getPumps(). Small example - >>> class TestClass: def __init__(self): print("in init")...
Read more >TypeError: missing 1 required positional argument: 'self'
The Python "TypeError: missing 1 required positional argument: 'self'" occurs when we call a method on the class instead of on an instance...
Read more >Python missing 1 required positional argument: 'self' Solution
The “missing 1 required positional argument: 'self'” error is raised when you do not instantiate an object of a class before calling a...
Read more >Feature Store methods are broken · Issue #3090 - GitHub
Describe the bug When calling FeatureGroup.create (and other) method the SDK fails with ... missing 1 required positional argument: 'self'.
Read more >TypeError: load() missing 1 required positional argument - Odoo
I go this following error when I click a button on my custom addons: Error: Odoo Server Error Traceback (most recent call last):...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thank you! This helped me a lot!
@ecs-jnguyen here is a working code sample:
Dependency Injector can call provided object methods and fetch attributes. You can read more about this feature here: https://python-dependency-injector.ets-labs.org/providers/provided_instance.html
I also added an example to the docs with similar example.
PS: A note on
service2
. Session returns singleton object for the same clientsession.client(service_name='s3') is session.client(service_name='s3')
. It’s a reason why last two asserts work.