无法从使用curl的查询字符串requestauthentication的amazon s3存储中获取文件 [英] Can't get a file from amazon s3 storage using curl with query string requestauthentication

查看:268
本文介绍了无法从使用curl的查询字符串requestauthentication的amazon s3存储中获取文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用我在互联网上找到的简单bash脚本从我的s3存储下载一个文件。

  !/ bash / sh 

bucket ='my_bucket_name'
file_path ='path_to_my_file'
resource =/ $ {bucket} / $ {file_path}
#设置url时间到期

expires = $(date +%s -d'4000 seconds')
stringtoSign =GET\\\
\\\
\\\
$ {expires} \\ n $ {resource}
s3Key ='s3Key_here'
s3Secret ='s3SecretKey_here'

signature =`echo -en $ {stringtoSign} | openssl sha1 -hmac $ {s3Key} -binary | base64`


curl -G https:// $ {bucket} .s3.amazonaws.com / $ {file_path} \
--data AWSAccessKeyId = $ {s3Key } \
--data Expires = $ {expires} \
--data-urlencode Signature = $ {signature}

在这里你可以看到没有什么特别的。我想使用带有查询字符串请求的variant。



但它总是发送回403 Forbidden错误与附加消息 - 我们计算的请求签名不匹配您提供的签名检查您的密钥和签名方法。



我在boto python库的帮助下检查过凭证,

  import boto 

from boto.s3.key import Key


KEY_ID ='key_id'
SECRET_KEY_ID ='secret_key'
SOURCE_FILE_NAME ='path_to_file'
DEST_FILE_NAME ='档案'
BUCKET_NAME ='my_bucket_name'

boto.set_stream_logger('boto')
conn = boto.connect_s3(KEY_ID,SECRET_KEY_ID)
bucket = conn.get_bucket(BUCKET_NAME)

#获取给定键的Key对象在桶中
k = Key(bucket,SOURCE_FILE_NAME)

#将密钥的内容写入文件
k.get_contents_to_filename(DEST_FILE_NAME)

刚才输入了两个密钥,bucket名称和文件路径,它为我工作。但这不是我正在寻找的。

当然,我读这个文档,并尝试关注它。我的'stringtoSing'变量以正确的方式形成。

解决方案

我将所有变量名称设置在正确的位置,并将openssl更新为OpenSSL 1.0 .2g 1 Mar 2016.现在它工作。


I'm trying to download a file from my s3 storage using simple bash script that I found on Internet.

#!/bash/sh

bucket='my_bucket_name'
file_path='path_to_my_file'
resource="/${bucket}/${file_path}"
# set url time to expire

expires=$(date +%s -d '4000 seconds')
stringtoSign="GET\n\n\n${expires}\n${resource}"
s3Key='s3Key_here'
s3Secret='s3SecretKey_here'

signature=`echo -en ${stringtoSign} | openssl sha1 -hmac ${s3Key} -binary | base64`


curl -G https://${bucket}.s3.amazonaws.com/${file_path} \
    --data AWSAccessKeyId=${s3Key} \
    --data Expires=${expires}\
    --data-urlencode Signature=${signature}

As you can see nothing special here. I want to use variant with a query string request.

But it always sends me back '403 Forbidden' error with additional message - "The request signature we calculated does not match the signature you provided. Check your key and signing method." Googling that error message didn't help me too.

I checked credentials with a help of boto python library,

import boto

from boto.s3.key import Key


KEY_ID = 'key_id'
SECRET_KEY_ID = 'secret_key'
SOURCE_FILE_NAME = 'path_to_file'
DEST_FILE_NAME = 'file'
BUCKET_NAME = 'my_bucket_name'

boto.set_stream_logger('boto')
conn = boto.connect_s3(KEY_ID, SECRET_KEY_ID)
bucket = conn.get_bucket(BUCKET_NAME)

# Get the Key object of the given key, in the bucket
k = Key(bucket, SOURCE_FILE_NAME)

# Get the contents of the key into a file
k.get_contents_to_filename(DEST_FILE_NAME)

just entered two secret keys I got, bucket name and path to file and it worked for me. But this is not what I'm looking for.

Of course, I read this docs and tried to follow it. My 'stringtoSing' variable is formed in right way. I just can't imagine where mistake is hidding.

解决方案

I set all variables names in right places and updated openssl to OpenSSL 1.0.2g 1 Mar 2016. Now it works.

这篇关于无法从使用curl的查询字符串requestauthentication的amazon s3存储中获取文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆