By using AWS re:Post, you agree to the Terms of Use

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!

asked 2 years ago160 views
1 Answer
0

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

answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions