首页 > 解决方案 > python sdk 中的 PutBucketWebsite 命令出错

问题描述

我正在使用下面显示的代码通过 python sdk 在 S3 存储桶中创建静态网站

website_configuration = {
     'ErrorDocument': {'Key': 'error.html'},
     'IndexDocument': {'Suffix': 'index.html'}
       }
s3_client.put_bucket_website(Bucket='bucket_name', 
            WebsiteConfiguration=website_configuration
               )

还尝试在方法参数中明确说明 WebsiteConfiguration。我收到以下错误(带有回溯)

Traceback (most recent call last):
  File "/home/ec2-user/environment/aws-modern-application-workshop/sdk_code.py", line 107, in <module>
    WebsiteConfiguration=website_configuration
  File "/home/ec2-user/.local/lib/python3.6/site-packages/botocore/client.py", line 357, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/home/ec2-user/.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 (AllAccessDisabled) when calling the PutBucketWebsite operation: All access to this object has been disabled

似乎是权限问题,但是相同的程序(代码未显示)用于创建存储桶、设置存储桶策略和上传 index.html 和 error.html 文件。此外,我可以在同一个 IDE 会话中通过 AWS CLI 命令创建静态网站(使用 Cloud9)。与 Cloud9 会话关联的 IAM 用户具有 ADMIN 权限,我检查了配置和凭证文件以确保它们分别包含区域和用户密钥。我需要有关如何解决此错误的建议。

标签: pythonwebamazon-s3sdk

解决方案


推荐阅读