从S3使用bash下载专用文件 [英] Download private file from S3 using bash
问题描述
我试图让下面的bash脚本的工作(从的 http://curl.haxx.se/mail/archive-2014-10/0006.html#replies ):
I am trying to get the following bash script to work (copied from http://curl.haxx.se/mail/archive-2014-10/0006.html#replies):
#!/bin/sh
file=path/to/file
bucket=your-bucket
resource="/${bucket}/${file}"
contentType="application/x-compressed-tar"
dateValue="`date +'%a, %d %b %Y %H:%M:%S %z'`"
stringToSign="GET
${contentType}
${dateValue}
${resource}"
s3Key=xxxxxxxxxxxxxxxxxxxx
s3Secret=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
signature=`/bin/echo -n "$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/${file}
我得到一个错误SignatureDoesNotMatch无论我做什么。
I am getting a SignatureDoesNotMatch error no matter what I do.
这是如何解决这一问题的任何想法将大大AP preciated。
Any ideas on how to fix this will be greatly appreciated.
推荐答案
花在这个我终于得到它的工作后太多时间:
After way too much time spent on this I finally got it to work:
这行:
signature=`/bin/echo -n "$stringToSign" | openssl sha1 -hmac ${s3Secret} -binary | base64`
缺少一个'e':
is missing an 'e':
signature=`/bin/echo -en "$stringToSign" | openssl sha1 -hmac ${s3Secret} -binary | base64`
在换句话说,人物没有被签署的字符串之前逃脱了。
In other words, characters weren't being escaped before the string was signed.
顺便说一句,我还了解到,GET请求,内容类型是毫无意义的。
As an aside, I also learned that for get requests, the content type is meaningless.
这篇关于从S3使用bash下载专用文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!