3/15/2023

To save a JSON object (stored in a Python variable) to an Amazon S3 bucket

 

refer to code:

.

import boto3
import json

# Initialize the S3 client
s3 = boto3.client('s3')

# Specify the S3 bucket and JSON object key
bucket_name = 'your-bucket-name'
object_key = 'path/to/your/object.json'

# Your JSON data
json_data = {
"key1": "value1",
"key2": "value2",
"key3": "value3"
}

# Convert the JSON data to a string
json_content = json.dumps(json_data)

# Save the JSON content to the S3 bucket
s3.put_object(Bucket=bucket_name, Key=object_key, Body=json_content)

print(f"Saved JSON data to '{bucket_name}/{object_key}'")

..

This code will convert the JSON data to a string, and then save it to the specified S3 bucket and key.


Thank you.

πŸ™‡πŸ»‍♂️

www.marearts.com



No comments:

Post a Comment