[英]Why am I getting botocore.exceptions.ClientError: An error occurred (403) when calling the HeadObject operation: Forbidden?
I'm getting this traceback when trying run run manage.py collectstatic
as part of an AWS ElasticbeanStalk deploy using an S3 bucket.我在尝试运行 run
manage.py collectstatic
作为使用 S3 存储桶的 AWS ElasticbeanStalk 部署的一部分时收到此回溯。
File "./src/manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/opt/python/run/venv/local/lib64/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/opt/python/run/venv/local/lib64/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/opt/python/run/venv/local/lib64/python3.6/site-packages/django/core/management/base.py", line 316, in run_from_argv
self.execute(*args, **cmd_options)
File "/opt/python/run/venv/local/lib64/python3.6/site-packages/django/core/management/base.py", line 353, in execute
output = self.handle(*args, **options)
File "/opt/python/run/venv/local/lib64/python3.6/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 162, in handle
if self.is_local_storage() and self.storage.location:
File "/opt/python/run/venv/local/lib64/python3.6/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 216, in is_local_storage
return isinstance(self.storage, FileSystemStorage)
File "/opt/python/run/venv/local/lib64/python3.6/site-packages/django/utils/functional.py", line 213, in inner
self._setup()
File "/opt/python/run/venv/local/lib64/python3.6/site-packages/django/contrib/staticfiles/storage.py", line 491, in _setup
self._wrapped = get_storage_class(settings.STATICFILES_STORAGE)()
File "/opt/python/bundle/3/app/src/core/storage.py", line 64, in __init__
super(StaticStorage, self).__init__(*args, **kwargs)
File "/opt/python/run/venv/local/lib64/python3.6/site-packages/django/contrib/staticfiles/storage.py", line 376, in __init__
self.hashed_files = self.load_manifest()
File "/opt/python/run/venv/local/lib64/python3.6/site-packages/django/contrib/staticfiles/storage.py", line 386, in load_manifest
content = self.read_manifest()
File "/opt/python/run/venv/local/lib64/python3.6/site-packages/django/contrib/staticfiles/storage.py", line 380, in read_manifest
with self.open(self.manifest_name) as manifest:
File "/opt/python/run/venv/local/lib64/python3.6/site-packages/django/core/files/storage.py", line 33, in open
return self._open(name, mode)
File "/opt/python/run/venv/local/lib/python3.6/site-packages/storages/backends/s3boto3.py", line 464, in _open
f = S3Boto3StorageFile(name, mode, self)
File "/opt/python/run/venv/local/lib/python3.6/site-packages/storages/backends/s3boto3.py", line 72, in __init__
self.obj.load()
File "/opt/python/run/venv/local/lib/python3.6/site-packages/boto3/resources/factory.py", line 505, in do_action
response = action(self, *args, **kwargs)
File "/opt/python/run/venv/local/lib/python3.6/site-packages/boto3/resources/action.py", line 83, in __call__
response = getattr(parent.meta.client, operation_name)(**params)
File "/opt/python/run/venv/local/lib/python3.6/site-packages/botocore/client.py", line 357, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/opt/python/run/venv/local/lib/python3.6/site-packages/botocore/client.py", line 661, in _make_api_call
raise error_class(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (403) when calling the HeadObject operation: Forbidden
(ElasticBeanstalk::ExternalInvocationError)
I have permissions on the bucket set to Public read write (just trying to get it working) so I do not understand the error.我将存储桶的权限设置为公共读写(只是想让它工作),所以我不明白这个错误。
Any help much appreciated非常感谢任何帮助
EDIT编辑
I've added the following bucket policy which I think should give access.我添加了以下我认为应该授予访问权限的存储桶策略。 Same error:
同样的错误:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "ListObjectsInBucket",
"Effect": "Allow",
"Action": [
"s3:ListBucket"
],
"Principal": "*",
"Resource": [
"arn:aws:s3:::my-bucket-name"
]
},
{
"Sid": "AllObjectActions",
"Effect": "Allow",
"Action": "s3:*Object",
"Principal": "*",
"Resource": [
"arn:aws:s3:::my-bucket-name/*"
]
}, ,
{
"Sid": "PublicWrite",
"Effect": "Allow",
"Principal": "*",
"Action": [
"s3:PutObject"
],
"Resource": [
"arn:aws:s3:::my-bucket-name/*"
]
}
] }
确保在部署之前已将代码提交到代码存储库
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.