搜索

首页  >  问答  >  正文

创建目录时,使用AWS S3和Flysystem出现"无法在指定位置写入文件... AccessDenied"错误

我在尝试在 AWS S3 上使用 Flysystem 创建目录时遇到了一些困难 - 我不断收到 AccessDenied 响应。我的存储桶具有所有公共访问权限 blocked,但存储桶策略允许发送请求的用户对其执行所有操作:

{
    "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/*"
        }
    ]
}

还有我的 local 用户策略:

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

我可以上传文件绝对没问题 - 只是目录,例如 images/blog 等,我收到 LeagueFlysystemUnableToWriteFile::atLocation 异常并抛出以下错误:

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>

知道是什么原因造成的吗?

P粉147045274P粉147045274312 天前580

全部回复(1)我来回复

  • P粉541796322

    P粉5417963222024-01-07 00:19:29

    经过几周的尝试寻找答案,我发现如果我在创建 s3 驱动程序时将 visibility 作为 private 并通过配置传递,那么它确实可以正常工作预计。

    回复
    0
  • 取消回复