django 错误调用DeleteObject操作时发生错误(拒绝访问):拒绝访问

hl0ma9xz  于 2023-11-20  发布在  Go
关注(0)|答案(1)|浏览(187)

从s3删除对象导致访问被拒绝错误
我的S3 IAM

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "s3:*",
                "s3-object-lambda:*"
            ],
            "Resource": "*"
        }
    ]
}

字符串
settings.py

INSTALLED_APPS = [
    'storages',
]

DEFAULT_FILE_STORAGE = "storages.backends.s3boto3.S3Boto3Storage"


django代码

def UpdateCompanyView(request):
    user = request.user
    company = user.company
    old_logo = company.logo
    if old_logo and 'logo' in serializer.validated_data and data_logo is not None:
        old_logo.delete()
    #old_logo.delete(save=False)#I've tried this also


其他所有操作工作放,添加,但删除发生此错误

zpqajqem

zpqajqem1#

你提供的代码是okey,我认为问题是与您的IAM用户我会建议您创建一个新的用户与新的密钥。并将此策略添加到您的桶

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "S3_POLICY",
            "Effect": "Allow",
            "Principal": {
                "AWS": "arn:aws:iam::AWS_USER_ID:user/USER_NAME"
            },
            "Action": [
                "s3:PutObject",
                "s3:GetObjectAcl",
                "s3:GetObject",
                "s3:ListBucket",
                "s3:DeleteObject",
                "s3:PutObjectAcl"
            ],
            "Resource": [
                "arn:aws:s3:::YOUR_BUCKET_NAME/*",
                "arn:aws:s3:::YOUR_BUCKET_NAME"
            ]
        }
    ]
}

字符串

相关问题