boto/boto3 · error · ValueError

Unknown keyword argument

Error message

Unknown keyword argument: {name}

What it means

Resource classes generated by boto3's factory accept only their declared identifiers as keyword arguments (plus 'client'). If a kwarg name is not in self.meta.identifiers and is not 'client', __init__ raises ValueError('Unknown keyword argument: {name}'), to surface typos and API/model mismatches at construction time rather than as a silent attribute error later.

Solutions

  1. Inspect the resource's identifiers via Resource.meta.identifiers to get the exact expected names.
  2. Use the canonical identifier name (commonly 'id' for single-id resources).
  3. Prefer loading resources through the service client or collection (e.g. ec2.Volume('v-123')) rather than guessing kwargs.

Example fix

# before
vol = ec2.Volume(volume_id='vol-123')
# after
vol = ec2.Volume('vol-123')
# or
vol = ec2.Volume(id='vol-123')  # if 'id' is the declared identifier
Defensive patterns

Strategy: validation

Validate before calling

def build_resource(cls, **kwargs):
    valid = set(cls.meta.identifiers) | {'client'}
    bad = set(kwargs) - valid
    assert not bad, f'Unknown kwargs for {cls.__name__}: {bad}; valid={valid}'
    return cls(**kwargs)

Type guard

def is_known_identifier(cls, name) -> bool:
    return name in set(cls.meta.identifiers) or name == 'client'

Try / catch

try:
    res = svc.Resource(**kwargs)
except ValueError as e:
    if 'Unknown keyword argument' in str(e):
        kwargs.pop(bad_name, None)
        res = svc.Resource(**kwargs)
    else:
        raise

Prevention

When it happens

Trigger: Constructing a resource like ec2.Volume(volume_id='v-123') where 'volume_id' is not the declared identifier name; using the wrong identifier name from a different AWS API version; typoing an identifier.

Common situations: Upgrade of boto3/botocore changes identifier names; using a copy-pasted example from a different resource; constructing resources manually instead of via collection methods.

Related errors


AI-assisted analysis of boto/boto3@6e10b029c1 (2026-08-11). Data as JSON: /api/errors/5a85c85ac0984b28. Report an issue: GitHub.

Appendix: 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 6e10b029c1)