简体   繁体   English

为什么我会收到 botocore.exceptions.ClientError:调用 HeadObject 操作时发生错误 (403):禁止?

[英]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.

相关问题 Collectstatic 失败 - botocore.exceptions.ClientError:调用 HeadObject 操作时发生错误 (404):未找到 - Collectstatic failing - botocore.exceptions.ClientError: An error occurred (404) when calling the HeadObject operation: Not Found [Django][AWS S3] botocore.exceptions.clienterror 调用 PutObject 操作时发生错误(访问被拒绝) - [Django][AWS S3] botocore.exceptions.clienterror an error occurred (accessdenied) when calling the PutObject operation botocore.exceptions.ClientError:调用PutObject操作时发生错误(AccessDenied):访问被拒绝 - botocore.exceptions.ClientError: An error occurred (AccessDenied) when calling the PutObject operation: Access Denied Django/AWS - 调用 HeadObject 操作时发生错误(403):禁止 - Django/AWS - An error occurred (403) when calling the HeadObject operation: Forbidden 使用AJAX进行POST请求时,为什么在Django中出现403 Forbidden错误? - Why am I getting a 403 Forbidden error in Django when I do a POST request with AJAX? (DJANGO + S3) + ZAPPA 调用 HeadObject 操作时发生错误 (400): Bad Request - (DJANGO + S3) + ZAPPA An error occurred (400) when calling the HeadObject operation: Bad Request 在AJAX请求中使用@csrf_exempt时,为什么会出现403 Forbidden错误? - Why am I be getting a 403 Forbidden error when using @csrf_exempt in AJAX request? 运行Locust时为什么会出现403错误? - Why am I getting a 403 error when running Locust? 当我设置 CSRF_COOKIE_HTTPONLY = True 然后发生 403 (Forbidden) 错误 - When I set CSRF_COOKIE_HTTPONLY = True then 403 (Forbidden) error occurred 集体AWS S3时的ClientError HeadObject - ClientError HeadObject when collecstatic AWS S3
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM