当我在Docker容器中运行它时,这是失败的,但是当我在OS X中的virtualenv中运行它时,它工作得很好。知道会出什么问题吗?Docker+boto有什么已知的问题吗?
>>> import boto3
>>> s3 = boto3.client('s3')
>>> s3.download_file("mybucket", "myfile.txt", "myfile2.txt")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/opt/conda/lib/python2.7/site-packages/boto3/s3/inject.py", line 104, in download_file
extra_args=ExtraArgs, callback=Callback)
File "/opt/conda/lib/python2.7/site-packages/boto3/s3/transfer.py", line 666, in download_file
object_size = self._object_size(bucket, key, extra_args)
File "/opt/conda/lib/python2.7/site-packages/boto3/s3/transfer.py", line 729, in _object_size
Bucket=bucket, Key=key, **extra_args)['ContentLength']
File "/opt/conda/lib/python2.7/site-packages/botocore/client.py", line 258, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/opt/conda/lib/python2.7/site-packages/botocore/client.py", line 548, in _make_api_call
raise ClientError(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (403) when calling the HeadObject operation: Forbidden
我想您没有设置正确的环境变量。使用
env
检查主机上设置的内容,并在容器中设置类似的变量,或者使用-e
将它们传递到docker run
。编辑:由于您在注释中指定要使用凭据文件,请使用
-v ~/.aws/credentials:/root/.aws/credentials
将其传递到容器中。假设设置了正确的HOME
,并且您使用的是root
用户。有些图像没有这样做,您可能需要将其放入根文件夹/.aws/credentials
。 如果你有一个特定的用户,路径需要在他的主文件夹中。修复问题的方法是在容器上安装awscli并更新boto3>;1.4
看看错误:
An error occurred (403) when calling the HeadObject operation: Forbidden
它找到了凭据,但没有访问存储桶的权限。底线:更新您的IAM权限,使其包含bucket的
s3:ListBucket
权限:arn:aws:s3:::mybucket/*
,或者将策略AmazonS3ReadOnlyAccess
附加到您的IAM用户/角色。您可以尝试此操作并看到它打印正确的凭据:
相关问题 更多 >
编程相关推荐