Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 124 lines (90 sloc) 3.163 kB
d120626 @lsegal Add basic README, update package.json
lsegal authored
1 # AWS JavaScript SDK
2
3 The official JavaScript implementation of the AWS SDK for node.js.
4
5 ## Installing
6
7 npm install aws-sdk
8
9 ## Using
10
11 Require the AWS package in your node application via `require`:
12
13 ```js
3194a3f @trevorrowe Updated README (getting started guide).
trevorrowe authored
14 var AWS = require('aws-sdk');
d120626 @lsegal Add basic README, update package.json
lsegal authored
15 ```
3194a3f @trevorrowe Updated README (getting started guide).
trevorrowe authored
16 ### Configuration
d120626 @lsegal Add basic README, update package.json
lsegal authored
17
3194a3f @trevorrowe Updated README (getting started guide).
trevorrowe authored
18 The SDK will attempt also to load credentials from the environment. It will look in the following places:
d120626 @lsegal Add basic README, update package.json
lsegal authored
19
3194a3f @trevorrowe Updated README (getting started guide).
trevorrowe authored
20 AWS_ACCESS_KEY_ID
21 AWS_SECRET_ACCESS_KEY
22 AWS_SESSION_TOKEN # optional
d120626 @lsegal Add basic README, update package.json
lsegal authored
23
3194a3f @trevorrowe Updated README (getting started guide).
trevorrowe authored
24 AMAZON_ACCESS_KEY_ID
25 AMAZON_SECRET_ACCESS_KEY
26 AMAZON_SESSION_TOKEN # optional
27
28 You can also load configuration and credentials from disk using `AWS.loadConfig`:
d120626 @lsegal Add basic README, update package.json
lsegal authored
29
30 ```js
3194a3f @trevorrowe Updated README (getting started guide).
trevorrowe authored
31 AWS.loadConfig('./configuration.json')
d120626 @lsegal Add basic README, update package.json
lsegal authored
32 ```
33
3194a3f @trevorrowe Updated README (getting started guide).
trevorrowe authored
34 Example configuration file contents:
35
36 {
37 "accessKeyId": "akid",
38 "secretAccessKey": "secret",
39 "region": "us-east-1"
40 }
41
42 ### Making Requests
43
44 To make a request you should start by creating a service interface.
d120626 @lsegal Add basic README, update package.json
lsegal authored
45
46 ```js
3194a3f @trevorrowe Updated README (getting started guide).
trevorrowe authored
47 // uses configuration from AWS.config
48 var ddb = new AWS.DynamoDB();
49
50 // merges configuration with AWS.config
51 var ddbWest = new AWS.DynamoDB({region:'us-west-1'});
d120626 @lsegal Add basic README, update package.json
lsegal authored
52 ```
53
3194a3f @trevorrowe Updated README (getting started guide).
trevorrowe authored
54 Services interfaces provide one function for each API operation. These functions return an `AWSRequest` promise object. You can then register callbacks on the request object. The callbacks will receive an `AWSResponse` object.
d120626 @lsegal Add basic README, update package.json
lsegal authored
55
56 ```js
3194a3f @trevorrowe Updated README (getting started guide).
trevorrowe authored
57 var req = ddb.listTables();
58
59 // called when the request is successful
60 req.done(function (response) {
61 console.log(resp.data);
62 // prints: {TableNames: ["Table1", "Table2", ...]}
63 });
64
65 // called when the request generates an error
66 req.fail(function (response) {
67 console.log(resp.error);
68 // errors have code and message properties
69 });
70
71 // called for every request
72 req.always(function (response) {
73 if (resp.error) {
74 console.log(resp.error);
75 } else {
76 console.log(resp.data);
77 }
78 });
d120626 @lsegal Add basic README, update package.json
lsegal authored
79 ```
80
81 You can also **chain** callbacks:
82
83 ```js
84 req.done(function() { ... }).fail(function() { ... })
85 ```
3194a3f @trevorrowe Updated README (getting started guide).
trevorrowe authored
86 ### Example: Listing buckets in Amazon S3
87
88 In the example below, I will print the name and creation date of all of the buckets in my AWS account.
89
90 ```js
91 var AWS = require('aws-sdk');
92 AWS.loadConfig('./configuration.json');
93
94 var s3 = new AWS.S3();
95 s3.listBuckets().always(function (resp) {
96 if (resp.error) {
97 console.log(error.message);
98 } else {
99 AWS.util.arrayEach(resp.data.Buckets, function(bucket) {
100 console.log("Bucket: ", bucket.Name, ' : ', bucket.CreationDate);
101 });
102 }
103 });
104 ```
d120626 @lsegal Add basic README, update package.json
lsegal authored
105
106 # License
107
108 This SDK is distributed under the
109 [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0).
110
111 Copyright 2012 Amazon Web Services
112
113 Licensed under the Apache License, Version 2.0 (the "License");
114 you may not use this file except in compliance with the License.
115 You may obtain a copy of the License at
116
117 http://www.apache.org/licenses/LICENSE-2.0
118
119 Unless required by applicable law or agreed to in writing, software
120 distributed under the License is distributed on an "AS IS" BASIS,
121 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
122 See the License for the specific language governing permissions and
123 limitations under the License.
Something went wrong with that request. Please try again.