In the example below I want to set a timestamp metadata attribute when created an S3 object. How do I do that? The documentation is not clear.
import uuuid
import json
import boto3
import botocore
import time
from boto3.session import Session
session = Session(aws_access_key_id='XXX',
aws_secret_access_key='XXX')
s3 = session.resource('s3')
bucket = s3.Bucket('blah')
for filename in glob.glob('json/*.json'):
with open(filename, 'rb') as f:
data = f.read().decode('utf-8')
timestamp = str(round(time.time(),10))
my_s3obj = s3.Object('blah', str(uuid.uuid4())).put(Body=json.dumps(data))
Guess you've figured it out. For the sake of helping others, I'm providing a feedback anyway. The Metadata is defined as a dictionary of string-to-string mapping (see documentation). You can use the following code snippet to set it. You can find more information about the Metadata in AWS web console.
import boto3
s3 = boto3.resource('s3')
s3.Object('mybucket', 'myfile.txt').put(Body='hello world', Metadata={'foo': 'bar'})
how to add the log into the end of the file ?
s3.Object('xxx', 'xxxx').put(Body = message) overwrite the first line.
Is there any attribute I missed?
Can you help me?
Most helpful comment
Guess you've figured it out. For the sake of helping others, I'm providing a feedback anyway. The Metadata is defined as a dictionary of string-to-string mapping (see documentation). You can use the following code snippet to set it. You can find more information about the Metadata in AWS web console.