AWS S3

How will you create S3 Bucket through Boto3?
import boto3
client = boto3.client('s3')

response = client.create_bucket(
    ACL='private',
    Bucket='javahomecloud123',
    CreateBucketConfiguration={
        'LocationConstraint': 'ap-south-1'
    }
)

How will you upload file to S3 bucket?
import boto3
client = boto3.client('s3')

file_reader = open('create_bucket.py').read()
response = client.put_object(
    ACL='private',
    Body=file_reader,
    Bucket='javahomecloud123',
    Key='create_bucket.py'
)
How will you delete object from S3?
import boto3
client = boto3.client('s3')

response = client.delete_object(
    Bucket='javahomecloud123',
    Key='create_bucket.py'
)
How will you list objects from S3?
import boto3
client = boto3.client('s3')

response = client.list_objects(
    Bucket='javahomecloud123'
)

for content in response['Contents']:
    print(content['Key'])
How will you list out all S3 buckets?
import boto3
client = boto3.client('s3')
response = client.list_buckets()
for bucket in response['Buckets']:
    print(bucket['Name'])
How will you select specific rows , columns from json filestored in S3?
import boto3
client = boto3.client(’s3’)

resp = client.select_object_content (
Bucket=’javahome—9090’,
Key=’fites/employees.json’,
Expression=’Select s.name1 s.email. from S3Object s’,
ExpressionType=’SQL’, I
InputSerialization = {‘json’: {‘FileHeaderlnfo’: ‘Use’)),
OutputSerialization = {‘JSON’: {}}
)

for event in resp['Paylload']:
    if 'Records' in event:
    print(event[’Records'] [‘PayLoad’l .decodeo())