dvonlehman / s3-proxy

4front plugin to proxy read calls to S3

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

S3 Missing Key

silverbuggy opened this issue · comments

Persistently getting S3 Missing Key despite correct credentials. Any help would be appreciated:

import express from "express";
import s3Proxy from "s3-proxy";
const app = express();
app.get("/*", s3Proxy({
bucket: "ymw",
accessKeyId: "XXX",
secretAccessKey: "YYY",
overrideCacheControl: "max-age=100000",
defaultKey: "earth.jpg"
}));
app.listen(80, () => {
console.log("App listening on port 80")
})

commented

@silverbuggy the "Missing Key" error indicates that the object can't be found in the bucket.. I would double check the path of the content.

When testing locally I also ran into this error as well. After stepping through the GetObject method in s3-proxy I noticed that my Express route was being added to the S3 path as such:

app.get('/serve/*', s3Proxy({ ... prefix: 'MyDirectory' ... }));

localhost:3000/serve/index.html

This path was being rendered as: s3://MyDirectory/serve/index.html

To work around this I did the following:

app.get('/serve/*', (req, res, next) =>{
  req.baseUrl = '/serve';
  
  s3Proxy({
    bucket: 'MyBucket',
    prefix: 'MyDirectory',
  })(req, res, next);
});

I hope this helps - not totally sure if we are experiencing the same issue 😄