Change client config without creating a new client? #3725
-
Is there a way to change an option in an client config after creating a client? I would like to do something like this: kwargs = {}
client = boto3.client('s3', **kwargs)
# ...
supports_acceleration = bucket_supports_accelerated_transfer(bucket, client=client, **kwargs)
wanted_acceleration = False if not client.meta.config.s3 else client.meta.config.s3.get('use_accelerate_endpoint', False)
s3_config = getattr(client.meta.config, 's3', {})
if not supports_acceleration and wanted_acceleration:
s3_config["use_accelerate_endpoint"] = False
client.meta.config.s3 = s3_config Currently I create a client, check if the bucket supports acceleration and then create a new client if the original one asked for acceleration, but the bucket doesn't support it. If I use the above approach of just changing the value in the original client config it doesn't update the client object so it continues to use acceleration after I change the setting. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
You can't change the client after creating it but you create a Session to store configuration state and then create clients off of that. |
Beta Was this translation helpful? Give feedback.
You can't change the client after creating it but you create a Session to store configuration state and then create clients off of that.