boto/boto3 · error · ValueError
Unknown keyword argument: {name}
Error message
Unknown keyword argument: {name} What it means
Raised by ServiceResource.__init__ when a keyword argument is passed that is not in the resource's declared identifier list (meta.identifiers) and is not 'client'. Resource constructors only accept their defined identifiers (e.g. a Bucket accepts 'name', an Object accepts 'bucket' and 'key'); any other kwarg is rejected to fail fast on typos and mismatches.
Source
Thrown at boto3/resources/base.py:116
# Create a default client if none was passed
if kwargs.get('client') is not None:
self.meta.client = kwargs.get('client')
else:
self.meta.client = boto3.client(self.meta.service_name)
# Allow setting identifiers as positional arguments in the order
# in which they were defined in the ResourceJSON.
for i, value in enumerate(args):
setattr(self, f"_{self.meta.identifiers[i]}", value)
# Allow setting identifiers via keyword arguments. Here we need
# extra logic to ignore other keyword arguments like ``client``.
for name, value in kwargs.items():
if name == 'client':
continue
if name not in self.meta.identifiers:
raise ValueError(f'Unknown keyword argument: {name}')
setattr(self, f"_{name}", value)
# Validate that all identifiers have been set.
for identifier in self.meta.identifiers:
if getattr(self, identifier) is None:
raise ValueError(f'Required parameter {identifier} not set')
def __repr__(self):
identifiers = [
f'{identifier}={repr(getattr(self, identifier))}'
for identifier in self.meta.identifiers
]
return f"{self.__class__.__name__}({', '.join(identifiers)})"
def __eq__(self, other):
# Should be instances of the same resource class
if other.__class__.__name__ != self.__class__.__name__:View on GitHub (pinned to c7b4afac23)
Solutions
- Check resource.meta.identifiers for the accepted keyword names.
- Pass identifiers positionally to avoid name mismatches.
- Use the parent resource's accessors (e.g. bucket.Object(key='k')) which fill identifiers automatically.
Example fix
# before
bucket = s3.Bucket(bucket_name='mybucket')
# after
bucket = s3.Bucket('mybucket')
# or
bucket = s3.Bucket(name='mybucket') Defensive patterns
Strategy: validation
Validate before calling
def safe_resource(resource_cls, **kwargs):
allowed = set(resource_cls.meta.identifiers) | {'client'}
bad = set(kwargs) - allowed
if bad:
raise ValueError(f'Unknown kwargs for {resource_cls.__name__}: {bad}. Allowed: {allowed}')
return resource_cls(**kwargs) Type guard
def accepted_identifiers(resource_cls) -> set:
return set(resource_cls.meta.identifiers) Prevention
- Inspect resource.meta.identifiers before constructing resources programmatically.
- Prefer positional args or parent-resource accessors (bucket.Object(...)) over guessing kwarg names.
- Keep a reference of identifier names per service when building resource factories.
When it happens
Trigger: s3.Bucket(bucket_name='mybucket') — should be s3.Bucket('mybucket') or s3.Bucket(name='mybucket'). Also s3.Object(bucket='b', key='k', extra='x') where 'extra' is not an identifier.
Common situations: Guessing constructor parameter names instead of checking the resource model; passing client-creation kwargs (like region_name) into a resource constructor; version differences where identifier names changed.
Related errors
- Required parameter {identifier} not set
- The following transfer config options are invalid when prefe
- {self.__class__.__name__} has no load method
- {parent.__class__.__name__} has no load method!
- Unsupported source type: {source}
AI-assisted analysis of boto/boto3@c7b4afac23 (2026-08-04).
Data as JSON: /data/errors/5a85c85ac0984b28.json.
Report an issue: GitHub.