Skip to content

Instantly share code, notes, and snippets.

@awaiskaleem

awaiskaleem/set_run_s3.py

Last active Jul 14, 2020
Embed
What would you like to do?
def set_run(proj_id):
'''
+ This creates a file called "active_run" in S3 and writes current run_id into it.
+ If a file named "live_run" does not exist, it creates one and throws active_run into it
'''
s3_client = boto3.Session(profile_name=None).client('s3')
s3_resource = boto3.resource('s3')
artifact_bucket = 'YOUR ARTIFACT BUCKET ON S3'
active_run_id = mlflow.active_run().info.run_id
object = s3_resource.Object(artifact_bucket, 'mlflow/'+proj_id+'/active_model_run')
object.put(Body=active_run_id)
try:
s3_object = s3_client.get_object(Bucket=artifact_bucket, Key='mlflow/'+proj_id+'/live_model_run')
except botocore.exceptions.ClientError as e:
print('NO LIVE RUN FOUND, CREATING...')
object = s3_resource.Object(artifact_bucket, 'mlflow/'+proj_id+'/live_model_run')
object.put(Body=active_run_id)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment