无法使用Shell脚本将文件上传到AWS S3 [英] Not able to upload file to aws s3 using shell script

查看:175
本文介绍了无法使用Shell脚本将文件上传到AWS S3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试上传到s3时出现以下错误.下面的脚本似乎是正确的,但仍然出现上述错误.请有人可以帮助我解决此错误.我的秘密密钥和访问ID是正确的,因为我能够使用Java和ruby中的这些密钥连接到AWS.

I am getting following error while trying to upload to s3. The script below seems to be correct but still I get above error. Please can someone help me in solving this error. My secret key and access ID are correct as I am able to connect to AWS using these keys in java and ruby.

<?xml version="1.0" encoding="UTF-8"?>
<Error><Code>SignatureDoesNotMatch</Code><Message>The request signature we calculated does not match the signature you provided. Check your key and signing method.</Message><AWSAccessKeyId>AKIAJNODAIRHFUX3LHFQ</AWSAccessKeyId><StringToSign>PUT

application/x-compressed-tar
Sun, 20 Dec 2015 19:54:47 -0500
/test-pk-proj//home/rushi/pk.tar.gz</StringToSign><SignatureProvided>M1PcN+Umkq5WFtVVSerHRGNABb8=</SignatureProvided><StringToSignBytes>50 55 54 0a 0a 61 70 70 6c 69 63 61 74 69 6f 6e 2f 78 2d 63 6f 6d 70 72 65 73 73 65 64 2d 74 61 72 0a 53 75 6e 2c 20 32 30 20 44 65 63 20 32 30 31 35 20 31 39 3a 35 34 3a 34 37 20 2d 30 35 30 30 0a 2f 74 65 73 74 2d 70 6b 2d 70 72 6f 6a 2f 2f 68 6f 6d 65 2f 72 75 73 68 69 2f 70 6b 2e 74 61 72 2e 67 7a</StringToSignBytes><RequestId>5439C7C84533E7C6</RequestId><HostId>620896ul+wnRwCjWl1ZtNZQ5NEJMGl29FqESC3iJyvnWhYhOECLlPl0417RfF3eovKFb7ac2.amazonaws.com port 443: Connection timed out

下面是我用来将数据上传到s3的shell脚本

Below is my shell script which I am using to upload data to s3

file=/home/rushi/1.pdf
bucket=xxxxxxxxxxxxxxxxxxx
resource="/${bucket}/${file}"
contentType="application/x-compressed-tar"
dateValue=`date -R`
stringToSign="PUT\n\n${contentType}\n${dateValue}\n${resource}"
s3Key=xxxxxxxxxxxxxxxxxxxxxxxxxxx
s3Secret=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
signature=`echo -en ${stringToSign} | openssl sha1 -hmac ${s3Secret} -binary | base64`
curl -L -X PUT -T "${file}" \
  -H "Host: ${bucket}.s3-website-us-west-2.amazonaws.com" \
  -H "Date: ${dateValue}" \
  -H "Content-Type: ${contentType}" \
  -H "Authorization: AWS ${s3Key}:${signature}" \
  https://${bucket}.s3-website-us-west-2.amazonaws.com/${file}

推荐答案

从下面给出的链接安装AWS CLI

Install AWS CLI from link given below

通过aws configure命令配置AWS并输入密钥和区域

Configure AWS by aws configure command and enter keys and region

要将文件复制到S3,请在Shell脚本中使用此命令

To copy file to S3 use this command in shell script

aws s3 cp fileName s3://bucketName

链接: http://docs.aws.amazon.com/cli/latest/userguide/installing.html#install-bundle-other-os

p.s如果收到连接超时错误,请在安全组中打开端口443(HTTPS).

p.s If you receive connection timed out error open port 443 (HTTPS) in security group.

这篇关于无法使用Shell脚本将文件上传到AWS S3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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