Get files

Download files from an S3 bucket to disk

The following function can be used to download a file in an S3 bucket to disk

import boto3

def get_file(key, filepath, bucket):
    try:
        # download file from S3 to disk
        client = boto3.client('s3')
        client.download_file(
            Filename=filepath,
            Bucket=bucket,
            Key=key,
        )
    except:
        pass

When calling the function you need to pass

  • key - the key ("filepath") of the file you want to get from the S3 bucket

  • filepath - the path on disk where you want to save the file

  • bucket - the name of the bucket

key = 'key_name'
filepath = 'path'
bucket = 'bucket_name'

# download file from S3-bucket to disk 
get_file(key=key, filepath=filepath, bucket=bucket)

Last updated

Was this helpful?