bash - 从 Amazon S3 存储桶下载文件的脚本

标签 bash curl amazon-web-services amazon-s3

尝试编写脚本从 Amazon S3 存储桶下载文件。

cURL 站点上的示例有问题。下面的脚本产生:

The request signature we calculated does not match the signature you provided. Check your key and signing method.

感谢任何帮助。

#!/bin/sh 
file="filename.php"
bucket="my-bucket"
resource="/${bucket}/${file}"
contentType="text/html"
dateValue="`date +'%a, %d %b %Y %H:%M:%S %z'`"
stringToSign="GET\n\n${contentType}\n${dateValue}\n${resource}"
s3Key='ABCABCABCABCABCABCAB'
s3Secret='xyzxyzyxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzx'
signature=`/bin/echo -en "$stringToSign" | openssl sha1 -hmac ${s3Secret} -      binary | base64`

curl -v -H "Host:lssngen-updates-east.s3.amazonaws.com" \
        -H "Date:${dateValue}" \
        -H "Content-Type:${contentType}" \
        -H "Authorization: AWS ${s3Key}:${signature}" \
        https://${bucket}.s3.amazonaws.com/${file}

最佳答案

我写这个bash脚本从s3下载文件(我下载压缩文件,你可以改变contentType来下载其他类型的文件)

#!/bin/sh 
outputFile="Your_PATH"
amzFile="AMAZON_FILE_PATH"
bucket="YOUR_BUCKET"
resource="/${bucket}/${amzFile}"
contentType="application/x-compressed-tar"
dateValue=`date -R`
stringToSign="GET\n\n${contentType}\n${dateValue}\n${resource}"
s3Key="YOUR_S3_KEY"
s3Secret="YOUR_S3SECRET"
signature=`echo -en ${stringToSign} | openssl sha1 -hmac ${s3Secret} -binary | base64`

curl  -H "Host: ${bucket}.s3.amazonaws.com" \
     -H "Date: ${dateValue}" \
     -H "Content-Type: ${contentType}" \
     -H "Authorization: AWS ${s3Key}:${signature}" \
     https://${bucket}.s3.amazonaws.com/${amzFile} -o $outputFile

关于bash - 从 Amazon S3 存储桶下载文件的脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30876123/

相关文章:

amazon-web-services - 暂时禁用 DynamoDB Lambda 触发器/流

arrays - bash:将大括号处的文本文件拆分为数组

linux - 仅保存使用 curl 下载的最后 x MB 音频流

macos - 使用 exit 在预提交 Hook 中停止 git commit

javascript - XMLHTTPRequest 错误响应 header

python - cURL (pycurl) 通过 HTTP 代理的 FTP

java - 谷歌CP : can one VM be on different networks with the same address?

amazon-web-services - PMU x86-64 性能计数器未显示在 AWS 下的性能中

bash - 查找 x 和 y 轴上的坐标对。

python - 使用 awk 从多个文件计算文件中的平均值