Last active
March 26, 2019 07:25
-
-
Save monkut/adf9e75d6461fc236bee096b5cc7c35c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Get the latest model assets key from resulting sagemaker training session | |
""" | |
import boto3 | |
S3 = boto3.client('s3') | |
def get_latest_model_assets_key(bucket: str, prefix: str): | |
model_assets = [] | |
paginator = S3.get_paginator('list_objects') | |
for page in paginator.paginate(Bucket=bucket, Prefix=prefix): | |
for item in page['Contents']: | |
key = item['Key'] | |
modified_datetime = item['LastModified'] | |
model_assets.append((modified_datetime, key)) | |
latest_model_assets_key = sorted(model_assets, reverse=True)[0][1] | |
return latest_model_assets_key | |
bucket = 'my-models-data' | |
prefix = 'training/assets' | |
latest_models_asset_key = get_latest_model_assets_key(bucket=bucket, prefix=prefix) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment