Skip to content

Instantly share code, notes, and snippets.

@invisiblefunnel
Created July 31, 2020 19:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save invisiblefunnel/b719b199317916fe2816959a2cd7dfa0 to your computer and use it in GitHub Desktop.
Save invisiblefunnel/b719b199317916fe2816959a2cd7dfa0 to your computer and use it in GitHub Desktop.
commands:
# replaces `aws-cli/install`
aws_cli_install:
description: Install AWS CLI (from cache if possible)
steps:
- restore_cache:
key: awscliv2
paths:
- /tmp/aws
- run:
name: Install AWS CLI
command: |
# Skip downloading aws-cli bundle if cached
if [[ ! -f /tmp/aws/install ]]; then
curl https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip -o /tmp/awscliv2.zip
unzip -q /tmp/awscliv2.zip -d /tmp
fi
# Skip installing if command exists
if ! command -v aws &> /dev/null; then
sudo /tmp/aws/install -i ~/bin
fi
- save_cache:
key: awscliv2
paths:
- /tmp/aws
# replaces `aws-s3/copy`
aws_s3_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
steps:
- aws_cli_install
- run:
name: S3 Copy << parameters.from >> -> << parameters.to >>
command: "aws s3 cp << parameters.from >> << parameters.to >>"
# replaces `aws-s3/sync`
aws_s3_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
steps:
- aws_cli_install
- deploy:
name: S3 Sync
command: |
aws s3 sync \
<<parameters.from>> <<parameters.to>><<#parameters.overwrite>> --delete<</parameters.overwrite>><<#parameters.arguments>> \
<<parameters.arguments>><</parameters.arguments>>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment