Skip to content

Instantly share code, notes, and snippets.

@TomDunn
Created April 26, 2017 07:34
Show Gist options
  • Save TomDunn/d964c509ea7a5e568dbd0e36603876e2 to your computer and use it in GitHub Desktop.
Save TomDunn/d964c509ea7a5e568dbd0e36603876e2 to your computer and use it in GitHub Desktop.
Upload zip to S3 from Bitbucket pipelines
BUCKET="!!!!!!!!YOUR_AMAZON_S3_BUCKET_NAME_HERE!!!!!!!!!!"
CONTENT_TYPE="application/zip"
DATE=`date -R`
IN_FILE="revision.zip"
KEY="demo/revision.zip"
RESOURCE="/${BUCKET}/${KEY}"
HMAC="PUT\n\n${CONTENT_TYPE}\n${DATE}\n${RESOURCE}"
zip -r --exclude=*.git* "$IN_FILE" .
SIGNATURE=`echo -en ${HMAC} | openssl sha1 -hmac ${API_SECRET} -binary | base64`
curl -X PUT -T "${IN_FILE}" \
-H "Host: ${BUCKET}.s3.amazonaws.com" \
-H "Date: ${DATE}" \
-H "Content-Type: ${CONTENT_TYPE}" \
-H "Authorization: AWS ${API_KEY}:${SIGNATURE}" \
https://${BUCKET}.s3.amazonaws.com/${KEY}
pipelines:
default:
- step:
script: # Modify the commands below to build your repository.
- apt-get update
- apt-get install zip openssl curl
- bash ./.upload.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment