脚本以从Amazon S3存储桶下载文件
尝试编写脚本以从Amazon S3存储桶下载文件.
Trying to write script to download file from Amazon S3 bucket.
在cURL网站上的示例遇到了麻烦.下面的脚本产生:
Having trouble with the example on the cURL site. The script below produces:
我们计算出的请求签名与您的签名不匹配 假如.检查您的密钥和签名方法.
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}
避免自己签署请求,这可能会出错或很难做.例如,您应该检查日期是否设置为GMT或使用x-amz-date标头.
Avoid signing the request yourself, a lot can go wrong or be hard to do. For example, you should check that the date is set to GMT or use x-amz-date headers.
另一种方法是使用 AWS命令行界面,然后使用$ aws s3 cp
或$ aws s3 sync
.
Another approach is to use the AWS Command Line Interface and so use $ aws s3 cp
or $ aws s3 sync
.