Examples
All of these examples assume that the AWS library is required, credentials are loaded via environment
variables (
AWS_ACCESS_KEY_ID
and
AWS_SECRET_ACCESS_KEY
), and the region is set via
AWS.config.update({region: 'us-east-1'});
.
The common preamble code can be summarized as follows:
var AWS = require('aws-sdk');
AWS.config.update({region: 'us-east-1'});
Amazon Simple Storage Service (Amazon S3)
Amazon S3: List All of Your Buckets (listBuckets)
The following example lists all buckets associated with your AWS account:
var s3 = new AWS.S3();
s3.client.listBuckets(function(err, data) {
for (var index in data.Buckets) {
var bucket = data.Buckets[index];
console.log("Bucket: ", bucket.Name, ' : ', bucket.CreationDate);
}
});
Amazon S3: Create a New Bucket and Object
(createBucket, putObject)
The following example puts the string 'Hello!' inside the object 'myKey' of bucket 'myBucket':
var s3 = new AWS.S3();
Version 0.9.1-pre.2 : Preview
14
AWS SDK for Node.js Getting Started Guide
Amazon Simple Storage Service (Amazon S3)