Skip to content

Instantly share code, notes, and snippets.

@jashmenn
Created September 27, 2018 17:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jashmenn/67ce7f5fb0b188f44f04510ae0fe1c01 to your computer and use it in GitHub Desktop.
Save jashmenn/67ce7f5fb0b188f44f04510ae0fe1c01 to your computer and use it in GitHub Desktop.
Use S3 as a url short-linker / redirection service
#!/bin/bash -x
if [[ $# -eq 0 ]] ; then
echo 'Usage: cmd <s3 path> <redirect-location>'
echo 'e.g.'
echo 'redirect-url-s3.sh www.fullstackreact.com/r/react-from-zero-satisfaction https://nate177.typeform.com/to/PTJ9ZI'
exit 0
fi
S3_PATH=$1
REDIRECT_URL=$2
cd ~/Desktop
rm index.html || :
touch index.html
s3cmd put --acl-public index.html s3://${S3_PATH}/index.html
s3cmd modify --add-header=x-amz-website-redirect-location:${REDIRECT_URL} s3://${S3_PATH}/index.html
s3cmd modify --add-header='Content-Type: text/html' s3://${S3_PATH}/index.html
open ${S3_PATH}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment