Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
636 B
3
Indexable
Never
import boto3

# Replace these values with your own AWS credentials and S3 bucket information
aws_access_key_id = 'YOUR_ACCESS_KEY'
aws_secret_access_key = 'YOUR_SECRET_KEY'
bucket_name = 'your-s3-bucket-name'
file_to_upload = 'path/to/your/local/file.txt'
s3_key = 'path/in/s3/file.txt'

# Create an S3 client
s3 = boto3.client('s3', aws_access_key_id=aws_access_key_id, aws_secret_access_key=aws_secret_access_key)

# Upload the file to S3
try:
    s3.upload_file(file_to_upload, bucket_name, s3_key)
    print(f"File {file_to_upload} uploaded to {bucket_name}/{s3_key}")
except Exception as e:
    print(f"Error uploading file: {e}")
Leave a Comment