Write python code to access s3 buckets using boto3.
Anonym
import boto3 # Initialize a session using your AWS credentials session = boto3.Session( aws_access_key_id='your_access_key_id', aws_secret_access_key='your_secret_access_key', region_name='your_region' ) # Create an S3 client s3 = session.client('s3') # List all buckets response = s3.list_buckets() # Print bucket names print('Existing buckets:') for bucket in response['Buckets']: print(f' {bucket["Name"]}') # Example: List objects in a specific bucket bucket_name = 'your_bucket_name' response = s3.list_objects_v2(Bucket=bucket_name) # Print object names print(f'Objects in bucket {bucket_name}:') for obj in response.get('Contents', []): print(f' {obj["Key"]}')