Carlos Aguni

Highly motivated self-taught IT analyst. Always learning and ready to explore new skills. An eternal apprentice.


Lambda S3 Cheat Sheet

11 Jun 2020 » aws
def dels3object(bucket, key):
    s3 = boto3.client('s3')
    s3.delete_object(Bucket=bucket, Key=key)
    
def listbucketkeys(bucket):
    s3 = boto3.client('s3')
    try:
        return [
            obj['Key']
            for obj in s3.list_objects_v2(Bucket=bucket)['Contents']
        ]
    except:
        return []
img_data = io.BytesIO()
plt.savefig(img_data, format='png')
img_data.seek(0)

s3 = boto3.resource('s3')
bucket = s3.Bucket(BUCKET_NAME)
bucket.put_object(Body=img_data, ContentType='image/png', Key=KEY)