We help IT Professionals succeed at work.

Javascript to access contents of my bucket not working

dogsareit
dogsareit used Ask the Experts™
on
I am new to AWS - I am using  localhost and Win 10. I plan to use Javascript and Java within html for some it. This is my first attempt tying to access and list the content of my bucket programmatically. (I am using the freebie for learning), I found this code when reading thru the documentation and for the life of  me I cannot get it to execute. And I have no clue.
Could someone be as so kind as to set me on the right path to learning this ??  My eventual goal is getting objects, granting permissions etc.
But I thought a good starting point would be something simple as listing the bucket contents - HA ! The bucket is public and everyone has read rights. I have provided both the code from AWS SDK Example and underneath it, my html coding.
I have verified that my Java is installed correctly, have set my environment path and I am able to compile packages etc.
Below is the code from the AWS SDK example for javascript: I inserted my bucket name.
var params = {
Bucket:'elasticbeanstalk-us-west-2-768711936919.s3-us-west-2.amazonaws.com',
Delimiter: '/',
Prefix: 'foldername/'
};
s3Bucket.listObjects(params, function(err, data) {
            if (err) {
                return 'There was an error viewing your album: ' + err.message
            }else{
                console.log(data.Contents,"<<<all content");

                data.Contents.forEach(function(obj,index){
                    console.log(obj.Key,"<<<file path")
                })
            }
        })

Open in new window


And below is my html coding:
<!DOCTYPE html>
<html lang="en-US">
<head>Listing of Bucket</head> 

<script src="https://sdk.amazonaws.com/js/aws-sdk-2.594.0.min.js"></script>
<body>
<script type="text/javascript">
var params = {
Bucket:'elasticbeanstalk-us-west-2-768711936919.s3-us-west-2.amazonaws.com',
Delimiter: '/',
Prefix: 'foldername/'
};
s3Bucket.listObjects(params, function(err, data) {
            if (err) {
                return 'There was an error viewing your album: ' + err.message
            }else{
                console.log(data.Contents,"<<<all content");

                data.Contents.forEach(function(obj,index){
                    console.log(obj.Key,"<<<file path")
                })
            }
        })
</script>		
</body> 
</html>
		

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Let's starts by stating the obvious: This code has nothing to do with the Java installation on your PC. So your environment, path, and ability to compile packages is irrelevant.
The code you posted is pure Javascript embedded in HTML.

If you can post back the documentation page where you copied the code from, it will greatly help.
I can see 2 problems:
1. The bucket name should probably be without the region and AWS domain, ie elasticbeanstalk-us-west-2-768711936919
2. You don't have a folder called "folder", you do have one called "testfolder"

Author

Commented:
Thank you for responding. I apologize for taking so long - it's a mess time-wise with the holidays. I will change the folder name and my bucket name when I return home and report back to you - this Thursday. Again, apologizes over the delay of my responding...

Author

Commented:
Well, I made the changes - removing the AWS domain and region and replaced folder name with testfolder,
and nothing. :{ Trying to find the document page where this was listed...
I didn't really find the original place I had found the coding, can not get it work, so decided to try another approach
Thank you for helping and sorry for the long delay in responding.