Reputation: 2387
Im a bit confused with the AWS SDK for JS in reference to its S3 utilization. The below is my code:
AWS.config.update({
accessKeyId: $rootScope.s3.akey,
secretAccessKey: $rootScope.s3.skey
});
s3=new AWS.S3({apiVersion: '2006-03-01'});
s3.listObjects({Bucket:$rootScope.s3.bucket}, function(err,data){
if(err) console.log(err);
else console.log(data);
})
This yields the error net::ERR_NAME_NOT_RESOLVED. The endpoint it is going to is similar to https://bucketName.undefined.us-east-1.amazonaws.com/
Obviously this wont resolve because of undefined being in the URL; however this doesn't even look like an s3 endpoint! It should follow a format like https://s3.amazonaws.com/bucketName/someFile.txt
Has anyone else been encountering issues similar to this or is there something elementary that I am doing wrong.
STR:
Any help please?
Upvotes: 1
Views: 4648
Reputation: 1462
I've debugged this a bit in the browser and found that it appears to be an issue with endpointPrefix being undefined. This effects selecting the url template to use as well hence the strange url.
If we look in the debug version of the aws js sdk code there's an area where
regionConfig.rules
is used to find a match from derivedKeys (which is based on your service/region). In mine I get:
"eu-west-1/*", "eu-*/*", "*/*"
The asterisks after the / indicate an undefined endpoint prefix. However the rule that we want matched in regionConfig.rules is:
eu-west-1/s3: "s3dash"
s3dash equates to the following template:
"{service}-{region}.amazonaws.com"
Which would work if service was s3 as you'd get:
s3-eu-west-1.amazonaws.com
However because this rule is not found instead / matches to:
"{service}.{region}.amazonaws.com"
Because service endpointPrefix is undefined (which is why we ended on this rule in the first place) you get 'undefined.eu-west-1.amazonaws.com'
If the CDN works are we suggesting there's a bug in the custom download?
Upvotes: 2