#!/bin/bash
set -e
set -u

S3_BUCKET='super-bucket'
S3_URL='storage.yandexcloud.net'
S3_KEY='SUPERSECRET'
S3_SECRET='SUPERSECRET'
LOG_FILE_PATH=$1
LOG_FILE=`basename $LOG_FILE_PATH`

S3_RESOURCE="/${S3_BUCKET}/${LOG_FILE}"
S3_CONTENT_TYPE="application/json"
S3_DATE_VALUE=`date -R`
S3_STRING_TO_SIGN="PUT\n\n${S3_CONTENT_TYPE}\n${S3_DATE_VALUE}\n${S3_RESOURCE}"
S3_SIGNATURE=`echo -en ${S3_STRING_TO_SIGN} | openssl sha1 -hmac ${S3_SECRET} -binary | base64`
echo "Uploading ${LOG_FILE_PATH} to https://${S3_BUCKET}.${S3_URL}/${LOG_FILE}"
curl -s -L -X PUT -T "${LOG_FILE_PATH}" \
  -H "Host: ${S3_BUCKET}.${S3_URL}" \
  -H "Date: ${S3_DATE_VALUE}" \
  -H "Content-Type: ${S3_CONTENT_TYPE}" \
  -H "Authorization: AWS ${S3_KEY}:${S3_SIGNATURE}" \
  https://${S3_BUCKET}.${S3_URL}/${LOG_FILE} > /dev/null 2>&1 || echo "Upload Failed !!!"
Enter your comment. Wiki syntax is allowed:
W M O W J
 
  • devops/aws_s3_upload_using_bash.txt
  • Last modified: 2022/06/21 13:17
  • by admin