【问题标题】:AWS S3 403 access denied issue with nodeJSnodeJS的AWS S3 403访问被拒绝问题
【发布时间】:2020-04-02 18:35:47
【问题描述】:

以下是我的存储桶策略

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "AddCannedAcl",
            "Effect": "Allow",
            "Principal": {
                "AWS": "==mydetails=="
            },
            "Action": [
                "s3:PutObject",
                "s3:PutObjectAcl"
            ],
            "Resource": "arn:aws:s3:::etcetera-dev/*",
            "Condition": {
                "StringEquals": {
                    "s3:x-amz-acl": "public-read"
                }
            }
        }
    ]
}

这是我的 Iam 用户内联政策

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "s3:ListAllMyBuckets",
                "s3:PutObject",
                "s3:GetObject",
                "s3:PutObjectAcl"
            ],
            "Resource": [
                "arn:aws:s3:::*"
            ]
        }
    ]
}

现在我正在尝试使用 multer-s3 和 acl:'public-read' 上传文件,但我收到 403 访问被拒绝。如果我不在 multer 中使用 acl 属性,我可以毫无问题地上传。

【问题讨论】:

    标签: node.js amazon-web-services amazon-s3 multer multer-s3


    【解决方案1】:

    您现在可能已经解决了这个问题,但如果您还没有,还有许多不同的可能解决方法(请参阅:https://aws.amazon.com/premiumsupport/knowledge-center/s3-troubleshoot-403/)。

    但我遇到了同样的问题,为我解决的问题如下。 我想你在尝试上传文件时打电话给s3.upload()。我发现如果您的 upload() 选项中没有 Bucket 参数,您也会收到 403。

    即确保您的upload() 调用如下:

    await s3.upload({
      Bucket: // some s3Config.Bucket
      Body: // Stream or File,               
      Key: // Filename,  
      ContentType: // Mimetype 
    }).promise();      
    

    Bucket: // some s3Config.Bucket - 我在函数调用中遗漏了这个参数,因为我认为new AWS.S3(config) 处理了存储桶。事实证明,您应该始终将存储桶添加到您的上传参数中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-30
      • 1970-01-01
      • 2022-01-11
      • 2013-08-15
      • 2015-09-22
      • 2015-09-07
      • 2019-02-03
      • 2017-07-28
      相关资源
      最近更新 更多