AWS S3中的区域冲突

时间:2018-05-31 12:20:43

标签: amazon-web-services amazon-s3 ubuntu-14.04 s3cmd

我在S3的欧盟(伦敦)地区有一个桶。我试图通过命令行上传tar文件。最后,它会抛出错误说

A client error (PermanentRedirect) occurred when calling the PutObject operation: The bucket you are attempting to access must be addressed using the specified endpoint.Please send all future requests to this endpoint.

通过提供正确的访问密钥和Region,我已使用aws configure正确配置。有人能否解释这个问题

我创建了一个脚本来通过创建tar文件来上传数据库

HOST=abc.com
DBNAME=db
BUCKET=s3.eu-west-2.amazonaws.com/<bucketname>/
USER=<user>
stamp=`date +"%Y-%m-%d"`
filename="Mgdb_$stamp.tar.gz"
TIME=`/bin/date +%Y-%m-%d-%T`
DEST=/home/$USER/tmp
TAR=$DEST/../$TIME.tar.gz
/bin/mkdir -p $DEST
echo "Backing up $HOST/$DBNAME to s3://$BUCKET/ on $TIME";
/usr/bin/mongodump --host $HOST --port 1234 -u "user" -p "pass"    --authenticationDatabase "admin"  -o $DEST
/bin/tar czvf $TAR -C $DEST .
/usr/bin/aws s3 cp $TAR s3://$BUCKET/$stamp/$filename
/bin/rm -f $TAR
/bin/rm -rf $DEST

2 个答案:

答案 0 :(得分:1)

只需将区域附加到AWS Command-Line Interface (CLI)命令:

aws s3 cp file.txt s3://my-bucket/file.txt --region eu-west-2

答案 1 :(得分:0)

脚本中S3Uri的格式不正确。它应该是s3://<bucketname>/<prefix>/<filename>。然后添加--region选项以指定存储区域。

$BUCKET=<bucketname>
/usr/bin/aws s3 cp $TAR s3://$BUCKET/$stamp/$filename --region eu-west-2