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

[feat] S3ArtifactStorage custom boto3 client parameters #3258

Merged
merged 4 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions aim/storage/artifacts/s3_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,20 @@ def _get_s3_client(self):

client = boto3.client('s3')
return client


def S3ArtifactStorage_factory(**boto3_client_kwargs: dict):
class S3ArtifactStorageCustom(S3ArtifactStorage):
def _get_s3_client(self):
import boto3, botocore
if 'config' in boto3_client_kwargs and isinstance(boto3_client_kwargs['config'], dict):
config_kwargs = boto3_client_kwargs.pop('config')
boto3_client_kwargs['config'] = botocore.config.Config(**config_kwargs)
client = boto3.client('s3', **boto3_client_kwargs)
return client
return S3ArtifactStorageCustom


def S3ArtifactStorage_clientconfig(**boto3_client_kwargs: dict):
from aim.storage.artifacts import registry
registry.registry['s3'] = S3ArtifactStorage_factory(**boto3_client_kwargs)
16 changes: 14 additions & 2 deletions docs/source/using/artifacts.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,22 @@ Currently supported backends for artifacts storage are.

#### S3 Artifacts Storage Backend

Aim uses `boto3` Python package for accessing AWS resources. No additional credentials
validation os done on the Aim side. More details on how credentials configuration is done
Aim uses `boto3` Python package for accessing S3 resources. By default `boto3` targets AWS S3 resources. Connection and credential validation is handled by `boto3`. A typical way of supplying credentials for instance is by setting `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` environment variables. More details on how configuration is done
for `boto3` is available [here](https://boto3.amazonaws.com/v1/documentation/api/latest/guide/credentials.html).

If you require direct control of how the `boto3` client handles your s3 connection, you may use `aim.storage.artifacts.s3_storage.S3ArtifactStorage_clientconfig(...)`. `S3ArtifactStorage_clientconfig` accepts any keyword-arguments that the `boto3.client` accepts, overwriting other means of boto3 configuration. This allows for the setting of credentials and connection details such as `endpoint_url` and `botocore` [Config](https://boto3.amazonaws.com/v1/documentation/api/latest/guide/configuration.html) parameters.

```python
import aim
from aim.storage.artifacts.s3_storage import S3ArtifactStorage_clientconfig

S3ArtifactStorage_clientconfig(aws_access_key_id=..., aws_secret_access_key=...,
endpoint_url=..., config={'retries': {...}, },)
run = aim.Run(...)
run.set_artifacts_uri('s3://...')
run.log_artifact(..., name=...)
```

#### File-system Artifacts Storage Backend

Aim provides ability to use mounted FS as an artifact storage. Any kind of storage that provides a mounted FS
Expand Down
Loading