How to download an object from Amazon S3 using AWS CLI

This post explains how to download objects from AWS S3 bucket using aws s3api get-object command.

To run the below commands you need to have AWS CLI installed and configured, if AWS CLI is not installed or not configured follow below posts to complete the setup.

[On Windows]
1. How to install AWS CLI on windows
2. How to configure AWS CLI

[On Ubuntu]
1. How to install AWS CLI on Ubuntu
2. How to configure AWS CLI

Command to download an object from S3 using AWS CLI.
         

aws s3api get-object --bucket "BUCKET_NAME" --key "OBJECT_KEY" "NAME_OF_OUTPUT_FILE"

    
    

Download S3 Object

The following example downloads an object with name sample_object1.txt from folder dir in S3 bucket test-bucket-001 and saves the output to the local file sample_object1.txt.

        
    
aws s3api get-object --bucket test-bucket-001 --key dir/sample_object1.txt sample_object1.txt
    
    
    

Download specific byte range from a S3 Object

Following example command downloads first 500 bytes of an object with name sample_object1.txt from folder dir in S3 bucket test-bucket-001 and saves the output to the local file sample_bytes.txt.

        
    
aws s3api get-object --bucket test-bucket-001 --key dir/sample_object1.txt --range bytes=1-500 sample_bytes.txt
            
    
            

Categories: AWS

Similar Articles