Using JavaScript and AWS SDK to access S3 Bucket without Credentials

0

I am attempting to use the AWS SDK to conveniently retrieve data from an S3 bucket without having to provide credentials.
I have a directory of files and I want to be able to add files/remove files/rename files within that directory without having to update my code.
Right now I have just been trying to make sure that I can retrieve the ListObjects, at which point I can parse the response to get the Keys.

<script src="https://sdk.amazonaws.com/js/aws-sdk-2.669.0.min.js"></script>
<reference types="aws-sdk" />
<script>
window.onload = function loadFilenames() {
        var s3 = new AWS.S3();
        var params = {  
            Bucket: "bucketname",
            Prefix: "fileslocation/"
        };
        s3.listObjectsV2(params, function(err, data){
            if (err) console.log(err, err.stack);
            else console.log(data);
        });
}

When I do this I get the error: CredentialsError: Missing credentials in config...
Because I want a visitor to the website to be able to see this data, I don't want to have to create an IAM user and pass the credentials. Is there a way to do this, or am I barking up the wrong tree? Thanks!

gefragt vor 4 Jahren725 Aufrufe
1 Antwort
0

I ended up being able to accomplish the same thing by making an Ajax request and parsing the XML response.

beantwortet vor 4 Jahren

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen