Last active
September 29, 2020 19:26
-
-
Save jfeilbach/e56d19886dc8fb9929d314a3cfe0c7ed to your computer and use it in GitHub Desktop.
Copy a directory structure from STDIN to AWS S3 bucket using aws s3 cp command AWS CLI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$#/bin/bash | |
# --acl bucket-owner-full-control is on by default | |
SECONDS=0 | |
src=$1 # the path of the source directory | |
dest=$2 # the s3 bucket destination path | |
echo -e "Copying from ${src} to ${dest}\n" | |
for entry in "$src"/*; do | |
# getting the name of the file or directory | |
name=`echo $entry | sed 's/.*\///'` | |
# if it is a directory | |
if [[ -d $entry ]]; then | |
aws s3 cp --acl bucket-owner-full-control --recursive "$name" "$dest/$name/" | |
# if it is a file | |
else | |
aws s3 cp --acl bucket-owner-full-control "$name" "$dest/" | |
fi | |
done | |
echo $SECONDS | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example
/path/to/s3cp.sh </source path> < S3 bucket path>
~/s3cp.sh /tmp/files s3:///my-s3-bucket/folder/
or
~/s3cp.sh s3://mybucket/ s3://mybucket2/