curlを使用してS3にファイルをアップロードするシェル
以下を参考にした。
tuxfight3r/s3_upload.sh
#!/bin/bash
S3KEY="Your Acess Key"
S3SECRET="Your Access Secret"
S3BUCKET="Your Bucket Name"
S3STORAGETYPE="STANDARD"
AWSREGION="Your S3 Region"
# Macを使用している場合、以下の行を有効にする
#OS="mac"
function putS3
{
file_path=$1
aws_path=$2
bucket="${S3BUCKET}"
date=$(date -R -u)
acl="x-amz-acl:private"
content_type="text/plain"
storage_type="x-amz-storage-class:${S3STORAGETYPE}"
string="PUT\n\n$content_type\n$date\n$acl\n$storage_type\n/$bucket$aws_path${file_path##/*/}"
if [ $OS = "mac" ]; then
signature=$(printf "${string}" | openssl sha1 -hmac "${S3SECRET}" -binary | base64)
else
signature=$(echo -en "${string}" | openssl sha1 -hmac "${S3SECRET}" -binary | base64)
fi
curl -s --retry 3 --retry-delay 10 -X PUT -T "$file_path" \
-H "Host: $bucket.${AWSREGION}.amazonaws.com" \
-H "Date: $date" \
-H "Content-Type: $content_type" \
-H "$storage_type" \
-H "$acl" \
-H "Authorization: AWS ${S3KEY}:$signature" \
"https://$bucket.${AWSREGION}.amazonaws.com$aws_path${file_path##/*/}"
}
# カレントディレクトリの test.txt ファイルを、/test/ にアップロード.
putS3 test.txt /test/