Python 上载图像时出错。botocore.exceptions.ClientError:调用PutObject操作时发生错误(AccessDenied)

Python 上载图像时出错。botocore.exceptions.ClientError:调用PutObject操作时发生错误(AccessDenied),python,amazon-web-services,amazon-s3,Python,Amazon Web Services,Amazon S3,我正在AWS S3中存储应用程序的配置文件图片。我让它在本地主机上运行,但在生产环境中运行时,会出现以下错误: [Wed Nov 04 00:34:53.554807 2020] [:error] [pid 14967] [remote 172.31.2.3:112] botocore.exceptions.ClientError: An error occurred (AccessDenied) when calling the PutObject operation: Access Deni

我正在AWS S3中存储应用程序的配置文件图片。我让它在本地主机上运行,但在生产环境中运行时,会出现以下错误:

[Wed Nov 04 00:34:53.554807 2020] [:error] [pid 14967] [remote 172.31.2.3:112] botocore.exceptions.ClientError: An error occurred (AccessDenied) when calling the PutObject operation: Access Denied
以下是我的bucket策略中与PutObject相关的部分:

    "Version": "2008-10-17",
    "Statement": [
        {
            "Sid": "*****",
            "Effect": "Allow",
            "Principal": {
                "AWS": "arn:aws:iam:::******role/aws-elasticbeanstalk-ec2-role"
            },
            "Action": [
                "s3:PutObject",
                "s3:PutObjectAcl"
            ],
            "Resource": "arn:aws:s3:::******/resources/environments/logs/*"
        },

我不确定为什么这会在我的本地主机上起作用,但在我部署它时就不行了。任何帮助都将不胜感激。

我终于能够让它工作了。它要求我为bucket策略中使用的角色制定新的角色策略。以下是我的自定义角色策略:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "VisualEditor0",
            "Effect": "Allow",
            "Action": [
                "s3:PutObject",
                "s3:PutObjectTagging",
                "s3:PutObjectAcl"
            ],
            "Resource": [
                "arn:aws:s3:::elasticbeanstalk-us-east-2-*****/profile-pictures/*",
                "arn:aws:s3:::elasticbeanstalk-us-east-2-*****"
            ]
        },
        {
            "Sid": "VisualEditor1",
            "Effect": "Allow",
            "Action": [
                "s3:GetAccessPoint",
                "s3:GetAccountPublicAccessBlock",
                "s3:ListAllMyBuckets",
                "s3:ListAccessPoints",
                "s3:ListJobs"
            ],
            "Resource": "*"
        }
    ]
}

我不知道我为什么要制定这个政策。在我的bucket策略中,我已经允许此角色执行这些操作。可能是因为我必须明确指定配置文件图片资源文件夹,但我不确定。

您是从EC2实例运行此文件的吗?你确定你没有使用任何其他AWS凭证、角色,除了策略中列出的那个吗?@Marcin我正在通过Elastic Beanstalk从EC2实例运行这个。我很确定我没有使用任何其他AWS用户或角色,但我对AWS还是相当陌生的。看看我的IAM控制台,我只有一个用户。至于角色,我在IAM上为各种AWS服务列出了8个不同的角色,但我不确定如何检查我是否不正确地使用了角色。