Python


Setting up a Python environment for AWS cloud

(my_env) ➜  ~ cat s3ls.py
import boto3

def list_s3_objects(bucket_name):
  """Lists all objects in the specified S3 bucket."""

  s3 = boto3.client('s3')
  response = s3.list_objects_v2(Bucket=bucket_name)

  if 'Contents' in response:
    for obj in response['Contents']:
      print(obj['Key'])
  else:
    print(f"No objects found in bucket {bucket_name}")

if __name__ == "__main__":
  bucket_name = "Test_Bucket"  
  list_s3_objects(bucket_name)

(my_env) ➜  ~ python s3ls.py
1.jpg
2.jpg
3.jpg
Icon-572x.png