documents/dev/snippets/aws/S3.md
Table of Contents
AWS S3
Sync Script
#!/bin/sh
#
# Usage: joysync [options]
# joysync watch watch for changes, auto rsync
# joysync s3 syncs to gerenuk-static bucket
#
# to skip password, copy your ssh public key to remote authorized_keys
# cat ~/.ssh/id_rsa.pub | ssh pi@10.0.0.10 'cat >> /home/pi/.ssh/authorized_keys'
#
# to configure AWS:
# aws configure
LOCAL_DIR='./'
REMOTE_DIR='Reading/ReflowableText'
EXCLUDE=(
'static/src/*'
'config.js'
'joysync'
'package*.json'
'*.MD'
'node_modules/*'
'.*' # dotfiles: .git, .babelrc, .DS_Store, etc.
)
CURRENT_DIR=$(pwd)
LOCAL_PATH="$CURRENT_DIR/$LOCAL_DIR"
GERENUK_PATH="pi@10.0.0.10:/var/www/joy/html/prototypes/$REMOTE_DIR"
S3_PATH="s3://gerenuk-static/$REMOTE_DIR"
EXCLUDE_STR=""
for i in "${EXCLUDE[@]}"
do
EXCLUDE_STR="$EXCLUDE_STR --exclude=\"$i\""
done
RSYNC_CMD="rsync -i $EXCLUDE_STR $LOCAL_PATH $GERENUK_PATH -r --delete"
alias sync="${RSYNC_CMD}"
CYAN='\033[0;36m'
GREEN='\033[0;32m'
NC='\033[0m'
GERENUK_LOG_INFO="FROM: ${CYAN}${LOCAL_PATH}${NC} \nTO: ${GREEN}${GERENUK_PATH}${NC}\n"
S3_LOG_INFO="FROM: ${CYAN}${LOCAL_PATH}${NC} \nTO: ${GREEN}${S3_PATH}${NC}\n"
if [ "$1" = "s3" ]; then
S3SYNC_CMD="aws s3 sync $LOCAL_PATH $S3_PATH $EXCLUDE_STR --delete"
printf "$S3_LOG_INFO"
eval "$S3SYNC_CMD"
elif [ "$1" = "watch" ]; then
echo "Watching"
printf "$GERENUK_LOG_INFO"
sync
fswatch -r -l 1 $LOCAL_PATH | while read f; do sync; done
else
echo "Syncing"
printf "$GERENUK_LOG_INFO"
sync
fi
sync folder
create IAM user with Programmatic access: https://console.aws.amazon.com/iam/home?#/users$new?step=details
aws configure set aws_access_key_id AKIAJVK2L5JRJYZDVA5A
aws configure set aws_secret_access_key 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
aws configure set default.region us-west-2
aws s3 sync s3://rive-data/tracking_dashboard/videos .