added optional parameter path to sync to path in bucket, instead of root of bucket
This commit is contained in:
parent
5b10b59baf
commit
4f7323f211
4 changed files with 7 additions and 3 deletions
|
@ -19,6 +19,7 @@ resources:
|
|||
access_key_id: {{aws-access-key}}
|
||||
secret_access_key: {{aws-secret-key}}
|
||||
bucket: {{aws-bucket}}
|
||||
path: [<optional>, use to sync to a specific path of the bucket instead of root of bucket]
|
||||
options: [<optional, see note below>]
|
||||
jobs:
|
||||
- name: <job name>
|
||||
|
|
|
@ -7,12 +7,13 @@ set -e
|
|||
# parse incoming config data
|
||||
payload=`cat`
|
||||
bucket=$(echo "$payload" | jq -r '.source.bucket')
|
||||
prefix="$(echo "$payload" | jq -r '.source.path // ""')"
|
||||
|
||||
# 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}')"
|
||||
timestamps=$(aws s3api list-objects --bucket $bucket --prefix "$prefix" --query 'Contents[].{LastModified: LastModified}')
|
||||
recent="$(echo $timestamps | jq -r 'max_by(.LastModified)')"
|
||||
echo "[$recent]"
|
||||
|
|
|
@ -17,6 +17,7 @@ fi
|
|||
# parse incoming config data
|
||||
payload=`cat`
|
||||
bucket=$(echo "$payload" | jq -r '.source.bucket')
|
||||
path=$(echo "$payload" | jq -r '.source.path // ""')
|
||||
options=$(echo "$payload" | jq -r '.source.options // [] | join(" ")')
|
||||
|
||||
# export for `aws` cli
|
||||
|
@ -24,7 +25,7 @@ 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')
|
||||
|
||||
echo "Downloading from S3..."
|
||||
eval aws s3 sync "s3://$bucket" $dest $options
|
||||
eval aws s3 sync "s3://$bucket/$path" $dest $options
|
||||
echo "...done."
|
||||
|
||||
source "$(dirname $0)/emit.sh" >&3
|
||||
|
|
|
@ -17,6 +17,7 @@ fi
|
|||
# parse incoming config data
|
||||
payload=`cat`
|
||||
bucket=$(echo "$payload" | jq -r '.source.bucket')
|
||||
path=$(echo "$payload" | jq -r '.source.path // ""')
|
||||
options=$(echo "$payload" | jq -r '.source.options // [] | join(" ")')
|
||||
|
||||
# export for `aws` cli
|
||||
|
@ -24,7 +25,7 @@ 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')
|
||||
|
||||
echo "Uploading to S3..."
|
||||
eval aws s3 sync $source "s3://$bucket" $options
|
||||
eval aws s3 sync $source "s3://$bucket/$path" $options
|
||||
echo "...done."
|
||||
|
||||
source "$(dirname $0)/emit.sh" >&3
|
||||
|
|
Loading…
Reference in a new issue