I need to append to a json file on aws S3, python code is running on an EC2 instance.
In a local setting I can easily do this as follows:
import json
#example data
json_data = {"id": "123", "name": "XYZ", "transaction": [20.0, 30.0]}
# path
local_path = '/home/ubuntu/test.json'
with open(local_path, 'a', encoding='utf-8-sig') as file:
json.dump(json_data, file)
file.write('\n')
file.close()
On EC2 I can connect to S3 as follows:
import boto
s3_open = boto.connect_s3(host='s3.eu-central-1.amazonaws.com')
I define the path to S3:
s3_path = 's3://my-bucket/test.json'
How can I append to this file using the logic described above?