Bootstrap FreeKB - Amazon Web Services (AWS) - Download files from an S3 Bucket using AWS CLI
Amazon Web Services (AWS) - Download files from an S3 Bucket using AWS CLI


This assumes you have already configured the aws command line tool. If not, check out my article on Getting Started with the AWS CLI.

An S3 Bucket is similar to an NFS share in that it is a mountable storage volume.

The aws s3api list-buckets command can be used to list your S3 buckets.

~]$ aws s3api list-buckets
{
    "Buckets": [
        {
            "Name": "my-bucket-abcdefg",
            "CreationDate": "2023-06-02T02:22:19+00:00"
        }
    ],
    "Owner": {
        "DisplayName": "john.doe",
        "ID": "ab0e0a411234d5103a77c82240d5abcdc41ff11cc325c65b5c777a5123443743"
    }
}

 

The following commands can be used to upload or download files to an S3 Bucket.

The aws s3api get-object command can be used to download a file from your S3 Bucket. In this example, foo.txt in the S3 Bucket will be downloaded to /tmp.

aws s3api get-object --bucket my-bucket-abcdefg --key path/to/foo.txt /tmp/foo.txt

 

If the S3 Bucket has Versioning enabled, the --version-id option can be used to download a specific version of the object (file). If you are not familiar with S3 Bucket Versioning, check out my article Amazon Web Services (AWS) - Getting Started with S3 Bucket Versioning. Let's say foo.txt has two versions, iDiTq7DSitz0gKIFgYoquloPHFPlcPdJ (the original version) and y8FEbLKsj4z2Kk_1Ru.EfkdRiMdtdIMH (the current version).

 

If the --version option is not used, the current version of the object will be downloaded. Notice in this example that the output has VersionId y8FEbLKsj4z2Kk_1Ru.EfkdRiMdtdIMH, which is the current version of the file.

~]# aws s3api get-object --bucket my-bucket-abc123 --key foo.txt foo.txt
{
    "AcceptRanges": "bytes",
    "LastModified": "2024-04-16T01:32:17+00:00",
    "ContentLength": 17,
    "ETag": "\"e65c918c98865ac528e2f2d0df0d8918\"",
    "VersionId": "y8FEbLKsj4z2Kk_1Ru.EfkdRiMdtdIMH",
    "ContentType": "text/plain",
    "ServerSideEncryption": "AES256",
    "Metadata": {}
}

 

Or, the --version-id option can be used to download a specific version of the object.

~]$ aws s3api get-object --bucket my-bucket-abc123 --key foo.txt foo.txt --version-id iDiTq7DSitz0gKIFgYoquloPHFPlcPdJ
{
    "AcceptRanges": "bytes",
    "LastModified": "2024-04-16T01:29:36+00:00",
    "ContentLength": 15,
    "ETag": "\"1f0f0df3b16f202e5b1c35132848d3e2\"",
    "VersionId": "iDiTq7DSitz0gKIFgYoquloPHFPlcPdJ",
    "ContentType": "text/plain",
    "ServerSideEncryption": "AES256",
    "Metadata": {}
}

 

 

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 2758ed in the box below so that we can be sure you are a human.