I have data in python as a=[{a:1,b:1},{a:3,b:3}]. How can I write these JSON in S3 (boto3) as file directly in Python?
-
What have you tried already to write JSON data to S3? Where will your python code run to write the data as you may need to consider access policies as well.st.huber– st.huber2021-09-27 10:23:42 +00:00Commented Sep 27, 2021 at 10:23
Add a comment
|
1 Answer
import json
import boto3
s3 = boto3.client('s3')
a=[{"a":1,"b":1},{"a":3,"b":3}]
s3.put_object(
Body=json.dumps(a),
Bucket='your_bucket_name',
Key='your_key_here'
)
3 Comments
Sundar
thanks, will the file contains only {a:1,b:1} {a3:,b3} not the array [{"a":1,"b":1},{"a":3,"b":3}]
Hamza usman ghani
You can read the json and pass to body without
json.dump() if it's already strSundar
I have tried this, it is writing as array of json values, but how to append json records in a file without array? can you help me ?