Skip to content

Instantly share code, notes, and snippets.

@spohnan
Created June 3, 2020 10:45
Show Gist options
  • Save spohnan/f90d9fed259686989a217108b9b776cb to your computer and use it in GitHub Desktop.
Save spohnan/f90d9fed259686989a217108b9b776cb to your computer and use it in GitHub Desktop.
S3 versioned bucket object diff
#!/bin/bash
# s3vd [bucket] [object] [v1 index] [v2 index]
bucket=${1:-bucket-name}
object=${2:-default-object}
get_object="aws s3api get-object --bucket $bucket --key $object"
v1=${3:-0}
v2=${4:-1}
version_list=$(aws s3api list-object-versions --bucket $bucket --prefix $object)
v1_obj=$(echo $version_list | jq -r --argjson v $v1 '.[] | nth($v)')
v2_obj=$(echo $version_list | jq -r --argjson v $v2 '.[] | nth($v)')
diff \
<($get_object --version-id $(echo $v1_obj | jq -r .VersionId) /dev/stdout) \
<($get_object --version-id $(echo $v2_obj | jq -r .VersionId) /dev/stdout)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment