Showing posts with label boto3. Show all posts
Showing posts with label boto3. Show all posts

3/15/2023

copy s3 object to another bucket

refer to code: 


.

import boto3

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

# Specify the source and destination S3 buckets and object keys
source_bucket = 'source-bucket-name'
source_key = 'path/to/source/object'

destination_bucket = 'destination-bucket-name'
destination_key = 'path/to/destination/object'

# Copy the object from the source bucket to the destination bucket
s3.copy_object(
CopySource={'Bucket': source_bucket, 'Key': source_key},
Bucket=destination_bucket,
Key=destination_key
)

print(f"Copied object from '{source_bucket}/{source_key}' to '{destination_bucket}/{destination_key}'")

..

Replace the placeholder values for source_bucket, source_key, destination_bucket, and destination_key with your actual bucket names and object keys. This code will copy the specified object from the source bucket to the destination bucket.


Thank you

🙇🏻‍♂️

www.marearts.com

load json file in memory form s3 bucket object (python example code)

 refer to code:

.

import boto3
import json

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

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

# Download the JSON file from the S3 bucket
response = s3.get_object(Bucket=bucket_name, Key=file_key)
content = response['Body'].read()

# Parse the JSON content
data = json.loads(content)

# Print the JSON data
print(data)

..


Thank you.

🙇🏻‍♂️

www.marearts.com