脚本以从Amazon S3存储桶下载文件 [英] script to download file from Amazon S3 bucket

查看:542
本文介绍了脚本以从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.

这篇关于脚本以从Amazon S3存储桶下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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