Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Handle boto3 clients more efficiently with lru_cache #361

Closed
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
c584ed7
move s3_client up
mattiamatrix Dec 19, 2023
70ba4b7
get s3 client
mattiamatrix Dec 19, 2023
2389cbe
add print for testing
mattiamatrix Dec 19, 2023
4a74401
revert changes
mattiamatrix Dec 19, 2023
362c97f
update client
mattiamatrix Dec 19, 2023
5feb200
remove print
mattiamatrix Dec 22, 2023
43fad43
add @lru_cache
mattiamatrix Dec 22, 2023
1df6cb3
Add docs
mattiamatrix Dec 22, 2023
e23c67b
update docs
mattiamatrix Dec 22, 2023
7428ae3
revert changes
mattiamatrix Dec 22, 2023
a1a8866
fix docs
mattiamatrix Dec 22, 2023
dd0cca4
Update CHANGELOG.md
mattiamatrix Dec 22, 2023
bcf2bed
Add maxsize and typed=True
mattiamatrix Dec 22, 2023
4ec6a1e
Merge branch 'main' into use-s3-client-more-efficiently
zzstoatzz Jan 3, 2024
ab03c45
add test
mattiamatrix Jan 3, 2024
92e5d72
Merge branch 'main' into use-s3-client-more-efficiently
mattiamatrix Jan 3, 2024
59e38d1
Test with cache_info
mattiamatrix Jan 3, 2024
3cd1eab
Update AwsCredentials
mattiamatrix Jan 3, 2024
e0a927b
Only S3
mattiamatrix Jan 3, 2024
0de61f8
Empty-Commit
mattiamatrix Jan 3, 2024
dd09cb1
Merge branch 'main' into use-s3-client-more-efficiently
zzstoatzz Jan 10, 2024
283050e
Update hash function
mattiamatrix Jan 18, 2024
3200967
Revert changes
mattiamatrix Jan 18, 2024
e8b61e0
Update hash
mattiamatrix Jan 18, 2024
56210f8
Test different hash
mattiamatrix Jan 18, 2024
865975c
avoid modifying default behavior
zzstoatzz Jan 18, 2024
9b6cd9b
run pre-commits
zzstoatzz Jan 18, 2024
1f9c3d0
no way
zzstoatzz Jan 18, 2024
7202545
test caching via s3
zzstoatzz Jan 18, 2024
5aad7ab
Update prefect_aws/s3.py
zzstoatzz Jan 18, 2024
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
9 changes: 8 additions & 1 deletion prefect_aws/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ class AwsCredentials(CredentialsBlock):
title="AWS Client Parameters",
)

_s3_client: Optional[S3Client] = None

def get_boto3_session(self) -> boto3.Session:
"""
Returns an authenticated boto3 session that can be used to create clients
Expand Down Expand Up @@ -132,7 +134,12 @@ def get_s3_client(self) -> S3Client:
Returns:
An authenticated S3 client.
"""
return self.get_client(client_type=ClientType.S3)
if self._s3_client is not None:
return self._s3_client

self._s3_client = self.get_client(client_type=ClientType.S3)

return self._s3_client

def get_secrets_manager_client(self) -> SecretsManagerClient:
"""
Expand Down
1 change: 1 addition & 0 deletions prefect_aws/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,7 @@ async def put_directory(
remote_file_path.as_posix(), content=local_file_content
)
uploaded_file_count += 1
print(uploaded_file_count) # TODO remove print
mattiamatrix marked this conversation as resolved.
Show resolved Hide resolved

return uploaded_file_count

Expand Down