I'm using Javascript AWS SDK. I include it with this:
All I want to do is GET objects already stored in an s3 bucket.
The client code has access to a (working) URL for the object stored on s3. It looks like this:
https://s3.amazonaws.com/my-bucket-name/my-object-key
My client app currently has a bunch of these URLs. I download the files successfully by simulating clicks on links of these URLs.
What I'd like to do is get all the files together in my script so that I can bundle them into a zip file with nice folder structure using JSzip.
I'm trying to do the following (this includes all s3 related code in my codebase):
var bucketName = 'my-bucket-name';
var s3 = new AWS.S3( {
params: {
Bucket: bucketName
}
} );
var key = myFileUrl.split('my-bucket-name/')[1];
var params = {
Key: key
};
s3.getObject(params, function(err, data) {
if (err) console.log("error!" + err + err.stack); // an error occurred
else {
console.log("success getting file from S3:",data); // successful response
}
});
When I run this, I get a "CredentialsError: Missing credentials in config" error.
I shouldn't actually need any credentials for this, right? The file is public, I can get it just by following the link. I looked at the AWS documentation for using the Javascript (client) sdk, and they don't set up a config object of any kind.
Has anyone gotten this to work? What am I doing wrong?