You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iceberg.apache.org by fo...@apache.org on 2022/10/20 22:25:13 UTC
[iceberg] branch master updated: Python: BOTO_STS_CLIENT lazy initialization (#5930)
This is an automated email from the ASF dual-hosted git repository.
fokko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iceberg.git
The following commit(s) were added to refs/heads/master by this push:
new 9f9046c3d9 Python: BOTO_STS_CLIENT lazy initialization (#5930)
9f9046c3d9 is described below
commit 9f9046c3d99318914de7eafcc5b909592d2ce7ab
Author: Pucheng Yang <80...@users.noreply.github.com>
AuthorDate: Thu Oct 20 15:25:06 2022 -0700
Python: BOTO_STS_CLIENT lazy initialization (#5930)
---
python_legacy/iceberg/core/filesystem/s3_filesystem.py | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/python_legacy/iceberg/core/filesystem/s3_filesystem.py b/python_legacy/iceberg/core/filesystem/s3_filesystem.py
index a8ac9d4cca..30da6baf85 100644
--- a/python_legacy/iceberg/core/filesystem/s3_filesystem.py
+++ b/python_legacy/iceberg/core/filesystem/s3_filesystem.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
+from functools import lru_cache
import io
import logging
import re
@@ -34,12 +35,16 @@ _logger = logging.getLogger(__name__)
S3_CLIENT = dict()
-BOTO_STS_CLIENT = boto3.client('sts')
CONF = None
ROLE_ARN = "default"
AUTOREFRESH_SESSION = None
+@lru_cache()
+def get_sts_client():
+ return boto3.client('sts')
+
+
@retry(wait_incrementing_start=100, wait_exponential_multiplier=4,
wait_exponential_max=5000, stop_max_delay=600000, stop_max_attempt_number=7)
def get_s3(obj="resource"):
@@ -71,7 +76,8 @@ def refresh_sts_session_keys():
params = {"RoleArn": ROLE_ARN,
"RoleSessionName": "iceberg_python_client_{}".format(int(time.time() * 1000.00))}
- sts_creds = BOTO_STS_CLIENT.assume_role(**params).get("Credentials")
+ boto_sts_client = get_sts_client()
+ sts_creds = boto_sts_client.assume_role(**params).get("Credentials")
credentials = {"access_key": sts_creds.get("AccessKeyId"),
"secret_key": sts_creds.get("SecretAccessKey"),
"token": sts_creds.get("SessionToken"),