我一直试图将EC2实例备份到S3存储桶,但是在运行文件时有争议地遇到了一些错误。最值得注意的错误是S3ResponceError:禁止403
仅供参考,我正在使用我的aws访问密钥ID,来自Rossetahub(由学校提供)的访问密钥秘密
下面是我编写的代码
SELECT
这是导致的错误
import boto
import boto.s3
import os.path
import sys
AWS_ACCESS_KEY_ID = ''
AWS_ACCESS_KEY_SECRET = ''
bucket_name = 'bucketpoly'
sourceDir = 'example_files/'
destDir = 'example_files1/'
conn = boto.connect_s3(AWS_ACCESS_KEY_ID, AWS_ACCESS_KEY_SECRET)
bucket= conn.get_bucket(bucket_name)
uploadFileNames = []
for (sourceDir, dirname, filename) in os.walk(sourceDir):
uploadFileNames.extend(filename)
break
def percent_cb(complete, total):
sys.stdout.write('.')
sys.stdout.flush()
for filename in uploadFileNames:
sourcepath = os.path.join(sourceDir + filename)
destpath = os.path.join(destDir, filename)
print ('Uploading %s to Amazon S3 bucket %s' %
(sourcepath, bucket_name))
print ("singlepart upload")
k = boto.s3.key.Key(bucket)
k.key = destpath
k.set_contents_from_filename(sourcepath, cb=percent_cb, num_cb=10)
您认为这可能是什么问题?
答案 0 :(得分:0)
403禁止,因为IAM权限不足。由于该错误,IAM用户没有Listobject和Listbucket权限。
这是可以用来获得S3权限的链接:
https://docs.aws.amazon.com/AmazonS3/latest/dev/s3-access-control.html