This is my working script that generates a plot, saves it locally to disk, uploads to S3 and deletes the file:
plt.figure(figsize=(6,6))
plt.plot(x, y, 'bo')
plt.savefig('file_location')
conn = boto.s3.connect_to_region(
region_name=AWS_REGION,
aws_access_key_id=AWS_ACCESS_KEY_ID,
aws_secret_access_key=AWS_SECRET_ACCESS_KEY,
calling_format=boto.s3.connection.OrdinaryCallingFormat()
)
bucket = conn.get_bucket('bucket_name')
k = Key(bucket)
k.key = 'file_name'
k.set_contents_from_filename('file_location')
os.remove(file_location)
What I want is to skip the disk writing and upload the plot directly from memory.
Any suggestions how to achieve that?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…