Boto3 list AWS S3 bucket objectse
The Session Token seems to be needed now.
import boto3
s3 = boto3.client(
's3',
aws_access_key_id='you key id',
aws_secret_access_key='your key',
aws_session_token='you token'
)
# Replace 'YOUR_BUCKET_NAME' with the name of your S3 bucket
bucket_name = 'your bucket name'
# Example: List all objects in the bucket
response = s3.list_objects_v2(Bucket=bucket_name)
if 'Contents' in response:
print("Objects in the bucket:")
for obj in response['Contents']:
print(obj['Key'])
else:
print("No objects found in the bucket.")