简体   繁体   中英

AWS S3 with Flysystem "Unable to write file at location... AccessDenied" when creating directory

I'm a bit stuck trying to create directory using Flysystem on AWS S3 - I keep getting AccessDenied response. My bucket has all public access blocked , but bucket policy allows all actions on it to the user that sends the request:

{
    "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 fine - it's just directories such as for instance images/blog etc. that I'm getting the League\Flysystem\UnableToWriteFile::atLocation exception thrown with 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>

Any idea what might be causing this?

After weeks of trying to find the answer I've found out that if I pass the visibility as private with configuration when creating the s3 driver then it does work as expected.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM