Skip to content

Notes on Amazon S3

Anthony Fok edited this page Jun 17, 2021 · 4 revisions

Getting started: Configure AWS credential environment variables for use in other GitHub Actions

Bucket policy

Owner access: bucket-owner-full-control

Miscellaneous links

IAM

Pricing

Cost-saving opportunities?

Verify checksum

Amazon's official method: Check the integrity of an object uploaded to Amazon S3 which verifies the object's integrity during the upload with the use of the low-level aws s3api put-object command.

But I want to use aws s3 sync.

Get the ETag:

Can be fetched by using ListObjectsV2 - Amazon Simple Storage Service:

$ aws s3api list-objects-v2 --bucket opendrr-api-prebuilt-cache-1 --profile opendrr-api-s3-reader

which returns the following JSON:

{
    "Contents": [
        {
            "Key": "boundaries/opendrr-boundaries.sql",
            "LastModified": "2021-06-17T06:05:14+00:00",
            "ETag": "\"20b8d16a40cbe5daf6f4d5dfd051840b-131\"",
            "Size": 1098382563,
            "StorageClass": "STANDARD"
        }
    ]
}

To extract ETag from this JSON output with jq:

$ aws s3api list-objects-v2 --bucket opendrr-api-prebuilt-cache-1 --profile opendrr-api-s3-reader \
    | jq -r '.Contents[] | select(.Key == "boundaries/opendrr-boundaries.sql").ETag'
"20b8d16a40cbe5daf6f4d5dfd051840b-131"

Calculate MD5 checksum

s3etag.sh: A Bash script to compute ETag values for S3 multipart uploads on OS X by @emersonf in Nov 2013, and revised for Linux by @skchronicles for Linux in Apr 2020. This works AWESOME!

$ ./s3etag.sh 
Usage: ./s3etag.sh file partSizeInMb
$ ./s3etag.sh opendrr-boundaries.sql 8
opendrr-boundaries.sql	20b8d16a40cbe5daf6f4d5dfd051840b-131

The s3etag.sh gist was referenced by a recent post (May 2020) How to get the md5sum of a file on Amazon's S3 - Stack Overflow

All about AWS S3 ETags - Teppen.io is another great write-up, but for some reasons, its Python implementation, Calculating the S3 ETag for a local file - Teppen.io, returns wrong checksum result for the file I tested.

Miscellaneous links