Merge pull request #9 from asceresini/master

Support AWS IAM Roles.
This commit is contained in:
Aidan Feldman 2016-10-04 11:30:19 -04:00 committed by GitHub
commit 1aa3269274
4 changed files with 28 additions and 6 deletions

View file

@ -28,6 +28,10 @@ jobs:
- put: <resource name>
```
## AWS Credentials
The `access_key_id` and `secret_access_key` are optional and if not provided the EC2 Metadata service will be queried for role based credentials.
## Options
The `options` parameter is synonymous with the options that `aws cli` accepts for `sync`. Please see [S3 Sync Options](http://docs.aws.amazon.com/cli/latest/reference/s3/sync.html#options) and pay special attention to the [Use of Exclude and Include Filters](http://docs.aws.amazon.com/cli/latest/reference/s3/index.html#use-of-exclude-and-include-filters).

View file

@ -10,8 +10,14 @@ 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')
AWS_ACCESS_KEY_ID=$(echo "$payload" | jq -r '.source.access_key_id')
AWS_SECRET_ACCESS_KEY=$(echo "$payload" | jq -r '.source.secret_access_key')
# Due to precedence rules, must be unset to support AWS IAM Roles.
if [ -n "$AWS_ACCESS_KEY_ID" ] && [ -n "$AWS_SECRET_ACCESS_KEY" ]; then
export AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID
export AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY
fi
# Consider the most recent LastModified timestamp as the most recent version.
timestamps=$(aws s3api list-objects --bucket $bucket --prefix "$prefix" --query 'Contents[].{LastModified: LastModified}')

View file

@ -21,8 +21,14 @@ path=$(echo "$payload" | jq -r '.source.path // ""')
options=$(echo "$payload" | jq -r '.source.options // [] | join(" ")')
# 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')
AWS_ACCESS_KEY_ID=$(echo "$payload" | jq -r '.source.access_key_id')
AWS_SECRET_ACCESS_KEY=$(echo "$payload" | jq -r '.source.secret_access_key')
# Due to precedence rules, must be unset to support AWS IAM Roles.
if [ -n "$AWS_ACCESS_KEY_ID" ] && [ -n "$AWS_SECRET_ACCESS_KEY" ]; then
export AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID
export AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY
fi
echo "Downloading from S3..."
eval aws s3 sync "s3://$bucket/$path" $dest $options

View file

@ -21,8 +21,14 @@ path=$(echo "$payload" | jq -r '.source.path // ""')
options=$(echo "$payload" | jq -r '.source.options // [] | join(" ")')
# 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')
AWS_ACCESS_KEY_ID=$(echo "$payload" | jq -r '.source.access_key_id')
AWS_SECRET_ACCESS_KEY=$(echo "$payload" | jq -r '.source.secret_access_key')
# Due to precedence rules, must be unset to support AWS IAM Roles.
if [ -n "$AWS_ACCESS_KEY_ID" ] && [ -n "$AWS_SECRET_ACCESS_KEY" ]; then
export AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID
export AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY
fi
echo "Uploading to S3..."
eval aws s3 sync $source "s3://$bucket/$path" $options