Backtick Knowledge Base
  • Backtick Knowledge Base
  • 📊Statistics
    • Kernel Density Estimation
    • Tests
  • 🍂Machine Learning
    • Fit and predict
    • Encoding
    • Feature Scaling
    • Pipeline
    • Model Evaluation & Selection
      • The Bias-Variance Decomposition
      • Kullback–Leibler Divergence
      • AIC & BIC
      • Cross-Validation
    • Feature Selection
    • Dimensionality Reduction
    • Clustering
    • Pandas
  • 🧠Deep Learning
  • 🐍Python
    • Beautiful Data
    • S3
      • List bucket items
      • Delete bucket items
      • Get objects
      • Upload objects
      • Get files
      • Upload files
      • Read .csv-file to dataframe
      • Write dataframe to .csv-file
  • ☁️Cloud
    • GCP
    • AWS
      • Users & Policies
        • Basic setup
        • MFA
      • EKS
        • Setup
        • Kube Config
        • Dashboard
      • S3
        • Copying buckets
  • ❖ Distributed Computing
    • Map-Reduce
    • Spark
    • Dask
  • ⎈ Kubernetes
Powered by GitBook
On this page

Was this helpful?

  1. Python
  2. S3

List bucket items

List all items in an S3 bucket

The following function can be used to list all items in an S3 bucket

import boto3

def list_bucket(bucket):
    client = boto3.client('s3')
    bucket_content = client.list_objects(Bucket=bucket)
    # check if S3-bucket is empty
    if bucket_content.get('Contents') == None:
        print('This S3-bucket is empty')
    else:
        # list all items in the S3 bucket
        for entry in bucket_content.get('Contents'):
            print(entry.get('Key'))

When calling the function you need to pass

  • bucket - the name of the bucket

bucket = 'bucket_name'

# list bucket items
list_bucket(bucket=bucket)

PreviousS3NextDelete bucket items

Last updated 5 years ago

Was this helpful?

🐍