Cloud Storage: Introduction to cloud-based data storage solutions
Cloud storage has revolutionized the way organizations store and manage their data. With cloud-based data storage solutions, businesses can securely store, access, and analyze their data without having to maintain their own physical infrastructure.
Amazon S3 (Simple Storage Service) is one of the most popular cloud storage solutions. It provides highly scalable and durable object storage that can be used to store and retrieve any amount of data from anywhere on the web. Let's take a closer look at how to use Amazon S3 for cloud-based data storage.
PYTHON
1def upload_file_to_s3(file_path, bucket_name, object_key):
2 import boto3
3
4 # Create a new S3 client
5 s3 = boto3.client('s3')
6
7 # Upload the file to the S3 bucket
8 s3.upload_file(file_path, bucket_name, object_key)
9
10# Example usage
11file_path = 'data.csv'
12bucket_name = 'my-data-bucket'
13object_key = 'data.csv'
14
15upload_file_to_s3(file_path, bucket_name, object_key)
xxxxxxxxxx
18
import boto3
# Create a new S3 client
s3 = boto3.client('s3')
# Create a new S3 bucket
bucket_name = 'my-data-bucket'
s3.create_bucket(Bucket=bucket_name)
# Upload a file to the S3 bucket
file_name = 'data.csv'
with open(file_name, 'rb') as file:
s3.upload_fileobj(file, bucket_name, file_name)
# Download a file from the S3 bucket
download_file_name = 'downloaded_data.csv'
s3.download_file(bucket_name, file_name, download_file_name)
print(f'{file_name} downloaded successfully')
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment