Bootstrap FreeKB - Amazon Web Services (AWS) - Upload files to an S3 Bucket using AWS CLI
Amazon Web Services (AWS) - Upload files to 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 put-object command can be used to add a file to your S3 Bucket. In this example, foo.txt will be uploaded to the base directory of the S3 Bucket.

~]$ aws s3api put-object --bucket my-bucket-abcdefg --key foo.txt --body foo.txt
{
    "ETag": "\"b1946ac92492d2347c6235b4d2611184\"",
    "ServerSideEncryption": "AES256"
}

 

In this example foo.txt will be upload to the my-directory folder in the S3 Bucket. The my-directory folder will be created if it does not exist.

~]$ aws s3api put-object --bucket my-bucket-abcdefg --key my-directory/foo.txt --body foo.txt
{
    "ETag": "\"b1946ac92492d2347c6235b4d2611184\"",
    "ServerSideEncryption": "AES256"
}

 

If you have created a Server Side Encryption Customer (sse-c) key, the --sse-customer-algorithm and --sse-customer-key and --sse-customer-key-md5 options can be included so that the object (file) is encrypted using your own key. Check out my article Create Server Side Encryption Key Customer (sse-c) key using AWS CLI

~]$ aws s3api put-object --bucket my-bucket-abc123 --key foo.txt --body foo.txt --sse-customer-algorithm AES256 --sse-customer-key $key --sse-customer-key-md5 $keymd5
{
    "ETag": "\"f62d7764d48743f8b59e0652b5f35d81\"",
    "SSECustomerAlgorithm": "AES256",
    "SSECustomerKeyMD5": "tAasKToBgkFA3Sy43tQjSA=="
}

 

Be aware that if you upload a file to an S3 Bucket with an sse-c, you'll most likely see the following when viewing the object in the S3 console, which is probably OK since you manage your own sse-c keys.

 




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 d28c72 in the box below so that we can be sure you are a human.