AWS S3 "Доступ запрещен" - PullRequest
       88

AWS S3 "Доступ запрещен"

0 голосов
/ 02 апреля 2020

Я использую Node.js и multer3s для связи с AWS S3. Я пробовал несколько разных установок, но все еще не могу сделать правильный вывод файла в мое ведро.

Для настройки S3 я следовал этому учебнику.

В моей службе IAM у меня есть пользователь myuser, у которого есть

политика разрешений

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

, тогда у меня есть корзина, которая установила Block all public access в off (я тоже пытался его включить).

Ковш имеет:

  • Политика ковша
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "AddCannedAcl",
            "Effect": "Allow",
            "Principal": {
                "AWS": "arn:aws:iam::228522121793:user/myuser"
            },
            "Action": [
                "s3:PutObject",
                "s3:PutObjectAcl"
            ],
            "Resource": [
                "arn:aws:s3:::mybucket/*",
                "arn:aws:s3:::mybucket"
            ],
            "Condition": {
                "StringEquals": {
                    "s3:x-amz-acl": "public-read"
                }
            }
        }
    ]
}
  • Конфигурация CORS
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
    <AllowedOrigin>*</AllowedOrigin>
    <AllowedMethod>GET</AllowedMethod>
    <AllowedMethod>POST</AllowedMethod>
    <AllowedMethod>PUT</AllowedMethod>
    <MaxAgeSeconds>3000</MaxAgeSeconds>
    <AllowedHeader>Authorization</AllowedHeader>
</CORSRule>
</CORSConfiguration>
  • в разделах Access points точки доступа не созданы.

в Node.js

aws.config.update({
    accessId: ACCESS_KEY,
    secretAccessKey: SECRET_KEY,
    region: 'eu-west-3'
})

const s3 = new aws.S3()

const upload = multer({
    storage: multerS3({
        s3: s3,
        bucket: BUCKET,
        acl: 'public-read',
        key(req, file, cb) {
            cb(null, Date.now() + shortid.generate())
        }
    }),
    limits: {
        files: 1,
        fileSize: 2580 * 1944
    },
    fileFilter(req, file, cb) {
        // filter
        cb(undefined, true)
    }
})

router.post('/test/img', upload.single('img'), async (req, res) => {
    console.log("success")
    console.log(req.file.location)
    res.send()
}, (error, req, res, next) => {
    res.status(400).send({
        error: error.message
    })
})

I Буду признателен за любые предложения относительно того, что я могу делать неправильно. Спасибо

...