s3-resource-simple/assets/check
ctro 5badf04978 check returns the most recent LastModified timestamp
This allows us to version a whole bucket.
Closes #5
2016-03-23 10:22:47 -06:00

18 lines
626 B
Bash
Executable file

#!/bin/sh
# http://concourse.ci/implementing-resources.html#resource-check
set -e
# parse incoming config data
payload=`cat`
bucket=$(echo "$payload" | jq -r '.source.bucket')
# export for `aws` cli
export AWS_ACCESS_KEY_ID=$(echo "$payload" | jq -r '.source.access_key_id')
export AWS_SECRET_ACCESS_KEY=$(echo "$payload" | jq -r '.source.secret_access_key')
# Consider the most recent LastModified timestamp as the most recent version.
timestamps="$(aws s3api list-objects --bucket $bucket --query 'Contents[].{LastModified: LastModified}')"
recent="$(echo $timestamps | jq -r 'max_by(.LastModified)')"
echo "[$recent]"