Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# This code is licensed from CircleCI to the user under the MIT license. See
# https://circleci.com/orbs/registry/licensing for details.
version: 2.1
description: |
A set of tools for working with Amazon S3. Requirements: bash
Source: https://github.com/circleci-public/circleci-orbs
examples:
basic_commands:
description: "Examples uses aws s3 commands"
usage:
version: 2.1
orbs:
aws-s3: circleci/aws-s3@1.0.0
jobs:
build:
docker:
- image: circleci/python:2.7
steps:
- checkout
- run: mkdir bucket && echo "lorem ipsum" > bucket/build_asset.txt
- aws-s3/sync:
from: bucket
to: "s3://my-s3-bucket-name/prefix"
arguments: |
--acl public-read \
--cache-control "max-age=86400"
overwrite: true
- aws-s3/copy:
from: bucket/build_asset.txt
to: "s3://my-s3-bucket-name"
arguments: --dryrun
override_credentials:
description: "Examples uses aws s3 commands with credentials overriding"
usage:
version: 2.1
orbs:
aws-s3: circleci/aws-s3@1.0.0
jobs:
build:
docker:
- image: circleci/python:2.7
steps:
- checkout
- run: mkdir bucket && echo "lorem ipsum" > bucket/build_asset.txt
- aws-s3/sync:
from: bucket
to: "s3://my-s3-bucket-name/prefix"
aws-access-key-id: AWS_ACCESS_KEY_ID_BLUE
aws-secret-access-key: AWS_SECRET_ACCESS_KEY_BLUE
aws-region: AWS_REGION_BLUE
arguments: |
--acl public-read \
--cache-control "max-age=86400"
overwrite: true
- aws-s3/copy:
from: bucket/build_asset.txt
to: "s3://my-s3-bucket-name"
arguments: --dryrun
orbs:
aws-cli: circleci/aws-cli@0.1.13
commands:
sync:
description: "Syncs directories and S3 prefixes. https://docs.aws.amazon.com/cli/latest/reference/s3/sync.html"
parameters:
from:
type: string
description: A local *directory* path to sync with S3
to:
type: string
description: A URI to an S3 bucket, i.e. 's3://the-name-my-bucket'
arguments:
type: string
default: ""
description: >
Optional additional arguments to pass to the `aws sync` command
(e.g., `--acl public-read`). Note: if passing a multi-line value
to this parameter, include `\` characters after each line, so the
Bash shell can correctly interpret the entire command.
overwrite:
default: false
type: boolean
aws-access-key-id:
type: env_var_name
description: aws access key id override
default: AWS_ACCESS_KEY_ID
aws-secret-access-key:
type: env_var_name
description: aws secret access key override
default: AWS_SECRET_ACCESS_KEY
aws-region:
type: env_var_name
description: aws region override
default: AWS_REGION
steps:
- aws-cli/install
- aws-cli/configure:
aws-access-key-id: << parameters.aws-access-key-id >>
aws-secret-access-key: << parameters.aws-secret-access-key >>
aws-region: << parameters.aws-region >>
- deploy:
name: S3 Sync
command: |
aws s3 sync \
<<parameters.from>> <<parameters.to>><<#parameters.overwrite>> --delete<</parameters.overwrite>><<#parameters.arguments>> \
<<parameters.arguments>><</parameters.arguments>>
copy:
description: "Copies a local file or S3 object to another location locally or in S3. https://docs.aws.amazon.com/cli/latest/reference/s3/cp.html"
parameters:
from:
type: string
description: A local file or source s3 object
to:
type: string
description: A local target or s3 destination
arguments:
description: If you wish to pass any additional arguments to the aws copy command (i.e. -sse)
default: ''
type: string
aws-access-key-id:
type: env_var_name
description: aws access key id override
default: AWS_ACCESS_KEY_ID
aws-secret-access-key:
type: env_var_name
description: aws secret access key override
default: AWS_SECRET_ACCESS_KEY
aws-region:
type: env_var_name
description: aws region override
default: AWS_REGION
steps:
- aws-cli/install
- aws-cli/configure:
aws-access-key-id: << parameters.aws-access-key-id >>
aws-secret-access-key: << parameters.aws-secret-access-key >>
aws-region: << parameters.aws-region >>
- run:
name: S3 Copy << parameters.from >> -> << parameters.to >>
command: "aws s3 cp << parameters.from >> << parameters.to >><<# parameters.arguments >> << parameters.arguments >><</ parameters.arguments >>"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.