Skip to content

Instantly share code, notes, and snippets.

@magnetikonline
Last active October 26, 2023 05:10
Show Gist options
  • Save magnetikonline/77c2521acfdd8a2f7579 to your computer and use it in GitHub Desktop.
Save magnetikonline/77c2521acfdd8a2f7579 to your computer and use it in GitHub Desktop.
AWS CLI S3 usage examples.

AWS CLI S3 usage examples

Local dir to remote bucket sync

$ aws s3 sync \
  --dryrun \
  --region REGION_NAME \
  --delete \
    /path/to/files/ \
    s3://BUCKET_NAME/path/to/dest

Local dir to remote bucket copy with gzip content encoding header

$ aws s3 cp \
  --dryrun \
  --region REGION_NAME \
  --recursive \
  --content-encoding 'gzip' \
    /path/to/files/ \
    s3://BUCKET_NAME/path/to/dest

Remote to remote bucket copy

$ aws s3 cp \
  --dryrun \
  --region REGION_NAME \
  --recursive \
    s3://BUCKET_NAME_SOURCE/path/to/source \
    s3://BUCKET_NAME_TARGET/path/to/dest
@andy-shi88
Copy link

where are you specify access key and secret key ??

CMIIW I think it will take the access and secret key from your awscli credential config which you can look into in ~/.aws/credentials, if you have multiple profile you could add --profile YourProfileAlias

@magnetikonline
Copy link
Author

That's correct - credentials come from either ~/.aws/credentials (controlled by --profile) or environment variables are the other choice.

You never give these keys over the CLI itself, nor is it even possible - since these things could be captured by other processes way too easily.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment