Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Im running the below code whenever i need to upload files to S3:

client = boto3.session.Session().client(self.client_type, use_ssl=True)
# use the client to upload

However this mean i do a request to auth to S3 for every time i need to upload a file. In my case there are alot of files i want to share if session is still open for the same client, but i could not find a way to detect via boto3 if the session is still valid, is there a way ?

Currently im tracking 1H time in my app wise to do this:

class ArchiveStorage(object):

    client = None
    session_duration_seconds = 60 * 60  # One Hour
    client_type = "s3"
    last_session = None

    def __init__(self):
        if ArchiveStorage.client is None or not self._is_session_valid():
            ArchiveStorage.client = self._create_new_s3_session()
        self.client = ArchiveStorage.client

    def _create_new_s3_session(self):
        return boto3.session.Session().client(self.client_type, use_ssl=True)

    def _is_session_valid(self):
        if not self.last_session:
            return False
        now = get_logical_timestamp()
        if now - ArchiveStorage.last_session > self.session_duration_seconds:
            return False
        return True

Is there a way to validate a S3 session without needing to calculate the session time in app side ?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
689 views
Welcome To Ask or Share your Answers For Others

1 Answer

等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...