Snippets Collections
import boto3

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

# Set the name of the S3 bucket and the file key
bucket_name = 'my-bucket'
file_key = 'path/to/file.txt'

# Use the S3 client to get the object
response = s3.get_object(Bucket=bucket_name, Key=file_key)

# Extract the file content from the response
file_content = response['Body'].read()

# Print the file content
print(file_content)
import boto3

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

# Set the name of the S3 bucket and the folder prefix
bucket_name = 'my-bucket'
folder_prefix = 'path/to/folder/'

# Use the S3 client to list the objects in the bucket
result = s3.list_objects_v2(Bucket=bucket_name, Prefix=folder_prefix)

# Extract the list of files from the response
files = [content['Key'] for content in result.get('Contents', [])]

# Print the list of files
print(files)
import logging
 
from botocore.exceptions import ClientError
import boto3
 
 
def create_bucket(bucket_name, region=None):
    """Create an S3 bucket in a specified region
    If a region is not specified, the bucket is created in the S3 default
    region (us-east-1).
    :param bucket_name: Bucket to create
    :param region: String region to create bucket in, e.g., 'us-west-2'
    :return: True if bucket created, else False
    """
 
    # Create bucket
    try:
        if region is None:
            s3_client = boto3.client('s3')
            s3_client.create_bucket(Bucket=bucket_name)
        else:
            s3_client = boto3.client('s3', region_name=region)
            location = {'LocationConstraint': region}
            s3_client.create_bucket(Bucket=bucket_name,
                                    CreateBucketConfiguration=location)
    except ClientError as e:
        logging.error(e)
        return False
    return True
import boto3
import pandas as pd
from sagemaker import get_execution_role

role = get_execution_role()
bucket='my-bucket'
data_key = 'train.csv'
data_location = 's3://{}/{}'.format(bucket, data_key)

pd.read_csv(data_location)
star

Thu Jan 26 2023 15:50:57 GMT+0000 (Coordinated Universal Time)

#s3 #aws
star

Thu Jan 26 2023 15:39:27 GMT+0000 (Coordinated Universal Time)

#s3 #aws
star

Tue Oct 25 2022 07:30:09 GMT+0000 (Coordinated Universal Time) https://kuchbhilearning.blogspot.com/2022/09/static-website-hosting-using-s3.html

#aws #s3
star

Tue Oct 04 2022 11:27:49 GMT+0000 (Coordinated Universal Time) https://kuchbhilearning.blogspot.com/2022/09/add-policy-to-existing-bucket-aws-cdk.html

#aws-cdk #aws #s3 #iam #policy
star

Mon Jan 31 2022 02:14:11 GMT+0000 (Coordinated Universal Time)

#python #aws #s3
star

Fri Jan 28 2022 03:38:30 GMT+0000 (Coordinated Universal Time)

#s3 #sagemaker

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension