"Cannot write file at specified location... AccessDenied" error when creating directory using AWS S3 and Flysystem
P粉147045274
P粉147045274 2024-01-06 11:44:49
0
1
574

I'm having some difficulty trying to create a directory on AWS S3 using Flysystem - I keep getting an AccessDenied response. My bucket has all public access blocked, but the bucket policy allows the user making the request to do all actions on it:

{
    "Version": "2008-10-17",
    "Id": "PolicyForCloudFrontPrivateContent",
    "Statement": [
        {
            "Sid": "AllowCloudFrontServicePrincipal",
            "Effect": "Allow",
            "Principal": {
                "Service": "cloudfront.amazonaws.com"
            },
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::my-local-bucket/*",
            "Condition": {
                "StringEquals": {
                    "AWS:SourceArn": "arn:aws:cloudfront::***:distribution/***"
                }
            }
        },
        {
            "Sid": "2",
            "Effect": "Allow",
            "Principal": {
                "AWS": "arn:aws:iam::***:user/local"
            },
            "Action": "s3:*",
            "Resource": "arn:aws:s3:::my-local-bucket/*"
        }
    ]
}

And my local user policy:

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

I can upload files absolutely no problem - just directories such as images/blog etc., I get a LeagueFlysystemUnableToWriteFile::atLocation exception and throws the following error:

Error executing "PutObject" on "https://s3.eu-west-2.amazonaws.com/my-local-bucket/images/blog/"; AWS HTTP error: Client error: `PUT https://s3.eu-west-2.amazonaws.com/my-local-bucket/images/blog/` resulted in a `403 Forbidden` response: <?xml version="1.0" encoding="UTF-8"?> <Error><Code>AccessDenied</Code><Message>Access Denied</Message><RequestId>***(truncated...)  AccessDenied (client): Access Denied - <?xml version="1.0" encoding="UTF-8"?> <Error><Code>AccessDenied</Code><Message>Access Denied</Message><RequestId>***</RequestId><HostId>***</HostId></Error>

Do you know what caused it?

P粉147045274
P粉147045274

reply all(1)
P粉541796322

After a few weeks of trying to find the answer, I found that if I pass visibility as private when creating the s3 driver and pass it through the configuration, then it does work as expected.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!