Join Joseph LeBlanc for an in-depth discussion in this video Listing buckets, part of Learning Cloud Storage APIs.
Amazon web services provides a Node software envelopment kit for all of their APIs. Using this kit we can connect to S3 and work with buckets. Let's connect to some of these buckets now. I'm going to pull up the exercise files, and in chapter two, I'm going to copy the server to the desktop. Now, I'm going to go to video two, and the start folder and then copy the app folder into the server folder.
Now let's edit the server. Let's add the keys we downloaded in the previous video. I saved the keys to the desktop. You can open these keys in Excel, or you can open them in a text editor. First, I'm going to copy the access key. And then next, I'm going to copy the secret access key. Now, I'm going to take a look at the server. Open up appindex.js. The first five lines are requiring Node modules that we'll be using for this application.
On line seven, we're declaring an new express application. Then on line nine, we're getting the path to auth.json file that we've just added the keys to. Line eleven is configuring Amazon web services software development kit with the authorization keys we've just added. Once Amazon's web services is configured, we could than start an Amazon S3 object. Now, that the Amazon S3 object is ready, let's list our buckets. I'm going to add a route. I'm typing app.get, and then the first argument I'm passing is slash buckets. The second argument I'm passing is the call back function. This callback function takes two arguments.
One for the request, and one for the response. Whenever someone loads the buckets route, we want to make a call to Amazon S3, so let's do that now. I'm going to call the list buckets method of the S3 object. This method takes a callback function. The callback function takes two arguments. Any error that occurred, and then the data from the API. For now, lets deliver the data back to the browser as json. Save the file and let's get this server started.
I'm going to the terminal and changing directory to desktop/server. And now I'm going to type npm install. If you see any warnings during the installation process, ignore them. Now, type node index.js. After hitting Return, go to the web browser, and load up localhost:3000/buckets. This json response lists all of the buckets as well as information about the owner. Once the SDK for Amazon web services is downloaded and installed, requests to S3 can be made using keys. S3 delivers the responses in json format.
- Why use cloud storage?
- Granting access to Amazon S3 buckets
- Displaying bucket contents
- Downloading files immediately
- Creating a Dropbox application
- Finding, downloading, and uploading files