aws-sdk 2.0.1 → 2.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc +20 -0
- package/.gitignore +10 -0
- package/.travis.yml +20 -0
- package/.yardopts +20 -0
- package/.yardopts_guide +21 -0
- package/Gemfile +16 -0
- package/Gemfile.lock +34 -0
- package/README.md +5 -6
- package/Rakefile +14 -0
- package/UPGRADING.md +9 -4
- package/configuration.sample +5 -0
- package/dist/BUNDLE_LICENSE.txt +96 -0
- package/dist/aws-sdk.js +9594 -0
- package/dist/aws-sdk.min.js +21 -0
- package/dist-tools/.eslintrc +10 -0
- package/dist-tools/browser-builder.js +142 -0
- package/dist-tools/strategies/cache.js +68 -0
- package/dist-tools/strategies/default.js +165 -0
- package/dist-tools/test/browser-builder.mocha.spec.coffee +182 -0
- package/dist-tools/test/helpers.coffee +16 -0
- package/doc-src/guide/browser-building.md +93 -0
- package/doc-src/guide/browser-configuring-wif.md +287 -0
- package/doc-src/guide/browser-configuring.md +218 -0
- package/doc-src/guide/browser-examples.md +220 -0
- package/doc-src/guide/browser-intro.md +46 -0
- package/doc-src/guide/browser-making-requests.md +279 -0
- package/doc-src/guide/browser-services.md +75 -0
- package/doc-src/guide/index.md +41 -0
- package/doc-src/guide/node-configuring.md +272 -0
- package/doc-src/guide/node-examples.md +341 -0
- package/doc-src/guide/node-intro.md +32 -0
- package/doc-src/guide/node-making-requests.md +309 -0
- package/doc-src/guide/node-services.md +159 -0
- package/doc-src/templates/api-versions/model_documentor.rb +366 -0
- package/doc-src/templates/api-versions/plugin.rb +230 -0
- package/doc-src/templates/api-versions/templates/default/class/html/setup.rb +9 -0
- package/doc-src/templates/api-versions/templates/default/class/html/waiter_details_list.erb +7 -0
- package/doc-src/templates/api-versions/templates/default/class/html/waiter_summary.erb +7 -0
- package/doc-src/templates/api-versions/templates/default/docstring/html/experimental.erb +4 -0
- package/doc-src/templates/api-versions/templates/default/docstring/setup.rb +9 -0
- package/doc-src/templates/api-versions/templates/default/fulldoc/html/css/common.css +6 -0
- package/doc-src/templates/api-versions/templates/default/fulldoc/html/setup.rb +62 -0
- package/doc-src/templates/api-versions/templates/default/layout/html/services.erb +10 -0
- package/doc-src/templates/api-versions/templates/default/layout/html/setup.rb +28 -0
- package/doc-src/templates/api-versions/templates/default/module/html/box_info.erb +45 -0
- package/doc-src/templates/api-versions/templates/default/module/html/children.erb +8 -0
- package/doc-src/templates/api-versions/templates/default/tags/setup.rb +3 -0
- package/doc-src/templates/api-versions/templates/default/waiter_details/html/method_signature.erb +3 -0
- package/doc-src/templates/api-versions/templates/default/waiter_details/html/setup.rb +5 -0
- package/doc-src/templates/default/layout/html/footer.erb +31 -0
- package/doc-src/templates/default/layout/html/layout.erb +23 -0
- package/doc-src/templates/flasky_sphinx_guide/fulldoc/html/css/highlight.github.css +127 -0
- package/doc-src/templates/flasky_sphinx_guide/fulldoc/html/css/style.css +1192 -0
- package/doc-src/templates/flasky_sphinx_guide/fulldoc/html/img/logo.png +0 -0
- package/doc-src/templates/flasky_sphinx_guide/fulldoc/html/js/app.js +33 -0
- package/doc-src/templates/flasky_sphinx_guide/fulldoc/html/js/highlight.pack.js +27 -0
- package/doc-src/templates/flasky_sphinx_guide/fulldoc/html/js/sphinx/AUTHORS +55 -0
- package/doc-src/templates/flasky_sphinx_guide/fulldoc/html/js/sphinx/LICENSE +25 -0
- package/doc-src/templates/flasky_sphinx_guide/fulldoc/html/js/sphinx/doctools.js +247 -0
- package/doc-src/templates/flasky_sphinx_guide/fulldoc/html/js/sphinx/file.png +0 -0
- package/doc-src/templates/flasky_sphinx_guide/fulldoc/html/js/sphinx/searchtools.js +568 -0
- package/doc-src/templates/flasky_sphinx_guide/fulldoc/html/js/underscore.js +23 -0
- package/doc-src/templates/flasky_sphinx_guide/fulldoc/html/search.erb +29 -0
- package/doc-src/templates/flasky_sphinx_guide/fulldoc/html/search_index.erb +1 -0
- package/doc-src/templates/flasky_sphinx_guide/fulldoc/html/setup.rb +75 -0
- package/doc-src/templates/flasky_sphinx_guide/layout/html/layout.erb +93 -0
- package/doc-src/templates/flasky_sphinx_guide/layout/html/setup.rb +9 -0
- package/doc-src/templates/flasky_sphinx_guide/layout/html/sidebar.erb +45 -0
- package/doc-src/templates/flasky_sphinx_guide/onefile/html/layout.erb +51 -0
- package/doc-src/templates/flasky_sphinx_guide/onefile/html/setup.rb +1 -0
- package/eslint-rules/no-require-in-service.js +10 -0
- package/features/autoscaling/autoscaling.feature +21 -0
- package/features/autoscaling/step_definitions/autoscaling.js +49 -0
- package/features/cloudformation/cloudformation.feature +22 -0
- package/features/cloudformation/step_definitions/cloudformation.js +26 -0
- package/features/cloudfront/cloudfront.feature +28 -0
- package/features/cloudfront/step_definitions/cloudfront-latest.js +54 -0
- package/features/cloudfront/step_definitions/cloudfront.js +21 -0
- package/features/cloudsearch/cloudsearch.feature +34 -0
- package/features/cloudsearch/step_definitions/cloudsearch.js +42 -0
- package/features/cloudtrail/cloudtrail.feature +17 -0
- package/features/cloudtrail/step_definitions/cloudtrail.js +14 -0
- package/features/cloudwatch/cloudwatch.feature +15 -0
- package/features/cloudwatch/step_definitions/cloudwatch.js +48 -0
- package/features/datapipeline/datapipeline.feature +23 -0
- package/features/datapipeline/step_definitions/datapipeline.js +79 -0
- package/features/directconnect/directconnect.feature +20 -0
- package/features/directconnect/step_definitions/directconnect.js +44 -0
- package/features/dynamodb/crc32.feature +18 -0
- package/features/dynamodb/step_definitions/dynamodb.js +154 -0
- package/features/dynamodb/tables.feature +50 -0
- package/features/ec2/ec2.feature +28 -0
- package/features/ec2/step_definitions/ec2.js +65 -0
- package/features/elasticache/elasticache.feature +20 -0
- package/features/elasticache/step_definitions/elasticache.js +34 -0
- package/features/elasticbeanstalk/elasticbeanstalk.feature +22 -0
- package/features/elasticbeanstalk/step_definitions/elasticbeanstalk.js +38 -0
- package/features/elastictranscoder/elastictranscoder.feature +24 -0
- package/features/elastictranscoder/step_definitions/elastictranscoder.js +56 -0
- package/features/elb/elb.feature +19 -0
- package/features/elb/step_definitions/elb.js +37 -0
- package/features/emr/emr.feature +16 -0
- package/features/emr/step_definitions/emr.js +45 -0
- package/features/extra/assertions.js +29 -0
- package/features/extra/dummy.feature +0 -0
- package/features/extra/fixtures/testfile.txt +1 -0
- package/features/extra/helpers.js +113 -0
- package/features/extra/hooks.js +107 -0
- package/features/extra/world.js +12 -0
- package/features/glacier/glacier.feature +47 -0
- package/features/glacier/step_definitions/glacier.js +112 -0
- package/features/iam/iam.feature +24 -0
- package/features/iam/step_definitions/iam.js +66 -0
- package/features/importexport/importexport.feature +53 -0
- package/features/importexport/step_definitions/importexport.js +42 -0
- package/features/kinesis/kinesis.feature +9 -0
- package/features/kinesis/step_definitions/kinesis.js +10 -0
- package/features/opsworks/opsworks.feature +26 -0
- package/features/opsworks/step_definitions/opsworks.js +42 -0
- package/features/rds/rds.feature +32 -0
- package/features/rds/step_definitions/rds.js +72 -0
- package/features/redshift/redshift.feature +20 -0
- package/features/redshift/step_definitions/redshift.js +33 -0
- package/features/route53/route53.feature +41 -0
- package/features/route53/step_definitions/route53.js +97 -0
- package/features/s3/buckets.feature +40 -0
- package/features/s3/objects.feature +122 -0
- package/features/s3/step_definitions/buckets.js +136 -0
- package/features/s3/step_definitions/hooks.js +39 -0
- package/features/s3/step_definitions/objects.js +204 -0
- package/features/s3/step_definitions/proxy.js +44 -0
- package/features/ses/ses.feature +20 -0
- package/features/ses/step_definitions/ses.js +22 -0
- package/features/simpledb/simpledb.feature +29 -0
- package/features/simpledb/step_definitions/simpledb.js +46 -0
- package/features/sns/sns.feature +15 -0
- package/features/sns/step_definitions/sns.js +33 -0
- package/features/sqs/messages.feature +21 -0
- package/features/sqs/queues.feature +18 -0
- package/features/sqs/step_definitions/messages.js +46 -0
- package/features/sqs/step_definitions/queues.js +33 -0
- package/features/sqs/step_definitions/sqs.js +7 -0
- package/features/storagegateway/step_definitions/storagegateway.js +16 -0
- package/features/storagegateway/storagegateway.feature +13 -0
- package/features/sts/step_definitions/sts.js +35 -0
- package/features/sts/sts.feature +29 -0
- package/features/support/step_definitions/support.js +35 -0
- package/features/support/support.feature +18 -0
- package/features/swf/step_definitions/swf.js +38 -0
- package/features/swf/swf.feature +15 -0
- package/index.js +2 -0
- package/lib/core.js +2 -2
- package/lib/credentials/shared_ini_file_credentials.js +0 -1
- package/lib/event_listeners.js +13 -1
- package/lib/http/node.js +19 -30
- package/lib/model/resource_waiter.js +0 -4
- package/lib/model/shape.js +2 -1
- package/lib/protocol/rest_xml.js +1 -1
- package/lib/region_config.js +31 -0
- package/lib/region_config.json +56 -0
- package/lib/request.js +37 -45
- package/lib/sequential_executor.js +17 -34
- package/lib/service.js +17 -44
- package/lib/services/cloudsearchdomain.js +69 -0
- package/lib/services/route53.js +0 -12
- package/lib/services/s3.js +3 -19
- package/lib/signers/v4.js +2 -1
- package/lib/util.js +28 -3
- package/package.json +3 -3
- package/scripts/console +11 -3
- package/scripts/coverage +126 -0
- package/tasks/apis.rake +122 -0
- package/tasks/browser.rake +89 -0
- package/tasks/docs.rake +36 -0
- package/tasks/lib/cucumber_generator.rb +40 -0
- package/tasks/util.rake +33 -0
- package/test/browser/js/jasmine-1.3.1.js +2600 -0
- package/test/browser/js/jasmine-html.js +681 -0
- package/test/browser/runner.html +109 -0
- package/test/browser/runner.js +92 -0
- package/test/browser/sample/appinfo.sample.js +15 -0
- package/test/browser/sample/console.html +429 -0
- package/test/browser/sample/css/smoothness/images/animated-overlay.gif +0 -0
- package/test/browser/sample/css/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
- package/test/browser/sample/css/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
- package/test/browser/sample/css/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
- package/test/browser/sample/css/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
- package/test/browser/sample/css/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
- package/test/browser/sample/css/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
- package/test/browser/sample/css/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
- package/test/browser/sample/css/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
- package/test/browser/sample/css/smoothness/images/ui-icons_222222_256x240.png +0 -0
- package/test/browser/sample/css/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
- package/test/browser/sample/css/smoothness/images/ui-icons_454545_256x240.png +0 -0
- package/test/browser/sample/css/smoothness/images/ui-icons_888888_256x240.png +0 -0
- package/test/browser/sample/css/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
- package/test/browser/sample/css/smoothness/jquery-ui-1.10.1.custom.css +1175 -0
- package/test/browser/sample/css/smoothness/jquery-ui-1.10.1.custom.min.css +5 -0
- package/test/browser/sample/img/loading.gif +0 -0
- package/test/browser/sample/js/jquery-1.9.1.js +9597 -0
- package/test/browser/sample/js/jquery-ui-1.10.1.custom.js +14903 -0
- package/test/browser/sample/js/jquery-ui-1.10.1.custom.min.js +6 -0
- package/test/browser/sample/s3upload.html +111 -0
- package/test/browser.spec.coffee +207 -0
- package/test/config.spec.coffee +202 -0
- package/test/credential_provider_chain.spec.coffee +90 -0
- package/test/credentials.spec.coffee +452 -0
- package/test/endpoint.spec.coffee +80 -0
- package/test/event_listeners.spec.coffee +493 -0
- package/test/helpers.coffee +150 -0
- package/test/http_request.spec.coffee +55 -0
- package/test/json/builder.spec.coffee +129 -0
- package/test/json/parser.spec.coffee +108 -0
- package/test/metadata_service.spec.coffee +54 -0
- package/test/model/api.spec.coffee +67 -0
- package/test/model/shape.spec.coffee +23 -0
- package/test/node_http_client.spec.coffee +40 -0
- package/test/param_validator.spec.coffee +456 -0
- package/test/protocol/json.spec.coffee +167 -0
- package/test/protocol/query.spec.coffee +191 -0
- package/test/protocol/rest.spec.coffee +237 -0
- package/test/protocol/rest_json.spec.coffee +255 -0
- package/test/protocol/rest_xml.spec.coffee +329 -0
- package/test/query/query_param_serializer.spec.coffee +327 -0
- package/test/region_config.spec.coffee +50 -0
- package/test/request.spec.coffee +316 -0
- package/test/resource_waiter.spec.coffee +89 -0
- package/test/response.spec.coffee +81 -0
- package/test/sequential_executor.spec.coffee +118 -0
- package/test/service.spec.coffee +230 -0
- package/test/services/cloudfront.spec.coffee +44 -0
- package/test/services/cloudsearchdomain.spec.coffee +23 -0
- package/test/services/dynamodb.spec.coffee +32 -0
- package/test/services/ec2.spec.coffee +78 -0
- package/test/services/elastictranscoder.spec.coffee +43 -0
- package/test/services/glacier.spec.coffee +61 -0
- package/test/services/rds.spec.coffee +38 -0
- package/test/services/route53.spec.coffee +77 -0
- package/test/services/s3.spec.coffee +538 -0
- package/test/services/simpledb.spec.coffee +12 -0
- package/test/services/sqs.spec.coffee +130 -0
- package/test/services/sts.spec.coffee +72 -0
- package/test/services/swf.spec.coffee +6 -0
- package/test/signers/presign.spec.coffee +36 -0
- package/test/signers/s3.spec.coffee +297 -0
- package/test/signers/v2.spec.coffee +68 -0
- package/test/signers/v4.spec.coffee +135 -0
- package/test/util.spec.coffee +510 -0
- package/test/xml/builder.spec.coffee +529 -0
- package/test/xml/parser.spec.coffee +587 -0
- package/lib/services/simpledb.js +0 -15
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
# @title Making Requests in Node.js
|
|
2
|
+
|
|
3
|
+
# Making Requests in Node.js
|
|
4
|
+
|
|
5
|
+
A "request" to an AWS service includes the full request and response lifecycle
|
|
6
|
+
of a call to an operation on a service object, including any retries that are
|
|
7
|
+
transparently attempted on your behalf. A request is encapsulated in the SDK by
|
|
8
|
+
the `AWS.Request` object. The semantics of a request are described below,
|
|
9
|
+
specifically, the support for callbacks, events, and streaming of raw HTTP
|
|
10
|
+
response data.
|
|
11
|
+
|
|
12
|
+
## Asynchronous Callbacks
|
|
13
|
+
|
|
14
|
+
All requests made through the SDK are asynchronous and use a
|
|
15
|
+
callback interface. Each service method that kicks off a request
|
|
16
|
+
can accept a callback as the last parameter with the signature
|
|
17
|
+
`function(error, data) { ... }`. This callback will be called when
|
|
18
|
+
the response or error data is available.
|
|
19
|
+
|
|
20
|
+
For example, the following service method can be called with
|
|
21
|
+
a standard callback to retrieve the response data or error:
|
|
22
|
+
|
|
23
|
+
```javascript
|
|
24
|
+
new AWS.EC2().describeInstances(function(error, data) {
|
|
25
|
+
if (error) {
|
|
26
|
+
console.log(error); // an error occurred
|
|
27
|
+
} else {
|
|
28
|
+
console.log(data); // request succeeded
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
The `error` and `data` parameters are described in the "Response Object"
|
|
34
|
+
section below.
|
|
35
|
+
|
|
36
|
+
Note that if you do not specify a callback, the operation will
|
|
37
|
+
return an `AWS.Request` object that must be manually sent using
|
|
38
|
+
the `send()` method:
|
|
39
|
+
|
|
40
|
+
```javascript
|
|
41
|
+
// create the AWS.Request object
|
|
42
|
+
var request = new AWS.EC2().describeInstances();
|
|
43
|
+
|
|
44
|
+
// register a callback to report on the data
|
|
45
|
+
request.on('success', function(resp) {
|
|
46
|
+
console.log(resp.data); // log the successful data response
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
// send the request
|
|
50
|
+
request.send();
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### The Response Object (`AWS.Response`)
|
|
54
|
+
|
|
55
|
+
The response object is passed into each callback function so
|
|
56
|
+
that you can access response data. The `AWS.Response` object that
|
|
57
|
+
is passed in contains two important properties to get at this data:
|
|
58
|
+
|
|
59
|
+
When using the standard callback mechanism, the two properties will
|
|
60
|
+
be made available as parameters on the callback method in the form:
|
|
61
|
+
`function(error, data) { ... }`
|
|
62
|
+
|
|
63
|
+
#### The `data` property
|
|
64
|
+
|
|
65
|
+
The `response.data` property contains the serialized object data
|
|
66
|
+
retrieved from the service request. For instance, for an
|
|
67
|
+
Amazon DynamoDB `listTables` method call, the response data might
|
|
68
|
+
look like this:
|
|
69
|
+
|
|
70
|
+
```javascript
|
|
71
|
+
> response.data
|
|
72
|
+
{ TableNames:
|
|
73
|
+
[ 'table1', 'table2', ... ] }
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
The `data` property can be null if an error occurs (see below).
|
|
77
|
+
|
|
78
|
+
#### The `error` property
|
|
79
|
+
|
|
80
|
+
In the event of a service error (or transfer error), the
|
|
81
|
+
`response.error` property will be filled with the given
|
|
82
|
+
error data in the form:
|
|
83
|
+
|
|
84
|
+
```javascript
|
|
85
|
+
{ code: 'SHORT_UNIQUE_ERROR_CODE',
|
|
86
|
+
message: 'Some human readable error message' }
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
In the case of an error, the `data` property will be null.
|
|
90
|
+
Note that if you handle events that can be in a failure state,
|
|
91
|
+
you should always check whether `response.error` is set
|
|
92
|
+
before attempting to access the `response.data` property.
|
|
93
|
+
|
|
94
|
+
#### The `request` property
|
|
95
|
+
|
|
96
|
+
Access to the originating request object is available through this
|
|
97
|
+
property. For example, to access the parameters that were sent
|
|
98
|
+
with a request:
|
|
99
|
+
|
|
100
|
+
```javascript
|
|
101
|
+
s3.getObject({Bucket: 'bucket', Key: 'key'}).on('success', function(response) {
|
|
102
|
+
console.log("Key was", response.request.params.Key);
|
|
103
|
+
}).send();
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### Simplified Callback Method
|
|
107
|
+
|
|
108
|
+
Each operation supports a simplified callback that can be passed as the last
|
|
109
|
+
parameter to any service operation. The callback function should
|
|
110
|
+
accept an `error` parameter, followed by the `data` from the response.
|
|
111
|
+
|
|
112
|
+
For example:
|
|
113
|
+
|
|
114
|
+
```javascript
|
|
115
|
+
s3.listBuckets(function(error, data) {
|
|
116
|
+
if (err) {
|
|
117
|
+
console.log(error); // error is Response.error
|
|
118
|
+
} else {
|
|
119
|
+
console.log(data); // data is Response.data
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
Prints (assuming the request succeeded):
|
|
125
|
+
|
|
126
|
+
```javascript
|
|
127
|
+
{ Owner: { ID: '...', DisplayName: '...' },
|
|
128
|
+
Buckets:
|
|
129
|
+
[ { Name: 'someBucketName', CreationDate: someCreationDate },
|
|
130
|
+
{ Name: 'otherBucketName', CreationDate: otherCreationDate } ],
|
|
131
|
+
RequestId: '...' }
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
The error and data parameters accepted are equivalent to the `error` and
|
|
135
|
+
`data` properties discussed in the `AWS.Response` response object section
|
|
136
|
+
above.
|
|
137
|
+
|
|
138
|
+
If you are passing parameters to the operation, the callback should be placed
|
|
139
|
+
after the parameters:
|
|
140
|
+
|
|
141
|
+
```
|
|
142
|
+
s3.getObject({Bucket: 'bucket', Key: 'key'}, function(err, data) {
|
|
143
|
+
// ...
|
|
144
|
+
});
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### AWS.Request Events
|
|
148
|
+
|
|
149
|
+
You can alternatively register callbacks on events provided by the
|
|
150
|
+
`AWS.Request` object returned by each service operation method.
|
|
151
|
+
This request object exposes the `success`, `error`, `complete`, and `httpData`
|
|
152
|
+
events, each taking a callback that accepts the response object.
|
|
153
|
+
|
|
154
|
+
Note that if you omit the simplified callback parameter on the operation
|
|
155
|
+
method, you must call `send()` on the returned request object in order to
|
|
156
|
+
kick off the request to the remote server.
|
|
157
|
+
|
|
158
|
+
#### Event: 'success'
|
|
159
|
+
|
|
160
|
+
```javascript
|
|
161
|
+
req.on('success', function(response) { ... });
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
This event triggers when a successful response
|
|
165
|
+
from the server is returned. The response contains a `.data` field
|
|
166
|
+
with the serialized response data from the service.
|
|
167
|
+
|
|
168
|
+
For example:
|
|
169
|
+
|
|
170
|
+
```javascript
|
|
171
|
+
s3.listBuckets().done(function(response) {
|
|
172
|
+
console.log(response.data);
|
|
173
|
+
}).send();
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
Prints:
|
|
177
|
+
|
|
178
|
+
```javascript
|
|
179
|
+
{ Owner: { ID: '...', DisplayName: '...' },
|
|
180
|
+
Buckets:
|
|
181
|
+
[ { Name: 'someBucketName', CreationDate: someCreationDate },
|
|
182
|
+
{ Name: 'otherBucketName', CreationDate: otherCreationDate } ],
|
|
183
|
+
RequestId: '...' }
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
#### Event: 'error'
|
|
187
|
+
|
|
188
|
+
```javascript
|
|
189
|
+
req.on('error', function(error, response) { ... });
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
The `error` event works similarly to the `success` event, except that it
|
|
193
|
+
triggers in the case of a request failure. In this case, `response.data`
|
|
194
|
+
will be `null` and the `response.error` field will be filled with
|
|
195
|
+
the error data. Note that the `error` object is also passed directly
|
|
196
|
+
as the first parameter to the event:
|
|
197
|
+
|
|
198
|
+
```javascript
|
|
199
|
+
s3.config.credentials.accessKeyId = 'invalid';
|
|
200
|
+
s3.listBuckets().fail(function(error, response) {
|
|
201
|
+
console.log(error);
|
|
202
|
+
// or:
|
|
203
|
+
console.log(response.error);
|
|
204
|
+
}).send();
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
Prints:
|
|
208
|
+
|
|
209
|
+
```javascript
|
|
210
|
+
{ code: 'Forbidden', message: null }
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
#### Event: 'complete'
|
|
214
|
+
|
|
215
|
+
```javascript
|
|
216
|
+
req.on('complete', function(response) { ... });
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
The `complete` event triggers a callback in any final state of a request, i.e.,
|
|
220
|
+
both `success` and `error`. Use this callback to handle any request cleanup
|
|
221
|
+
that must be executed regardless of the success state. Note that if you
|
|
222
|
+
do intend to use response data inside of this callback, you must check
|
|
223
|
+
for the presence of `response.data` or `response.error` before attempting
|
|
224
|
+
to access either property. For example:
|
|
225
|
+
|
|
226
|
+
```javascript
|
|
227
|
+
request.on('complete', function(response) {
|
|
228
|
+
if (response.error) {
|
|
229
|
+
// an error occurred, handle it
|
|
230
|
+
} else {
|
|
231
|
+
// we can use response.data here
|
|
232
|
+
}
|
|
233
|
+
}).send();
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
#### Event: 'httpData'
|
|
237
|
+
|
|
238
|
+
```javascript
|
|
239
|
+
req.on('httpData', function(chunk, response) { ... });
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
<p class="note">If you register a <code>httpData</code> callback,
|
|
243
|
+
<code>response.data</code> will still contain serialized output
|
|
244
|
+
for the entire request. It will be your responsibility to remove
|
|
245
|
+
the default 'httpData' listener if you do not wish to have the
|
|
246
|
+
extra parsing and memory overhead from the built-in handlers.
|
|
247
|
+
</p>
|
|
248
|
+
|
|
249
|
+
The `httpData` event is used to stream response data from the
|
|
250
|
+
service packet-by-packet. This event is mostly used for large responses,
|
|
251
|
+
when it is inefficient (or impossible) to load the entire response into
|
|
252
|
+
memory.
|
|
253
|
+
|
|
254
|
+
Note that this event contains an extra `chunk` parameter containing the
|
|
255
|
+
actual data passed on by the server.
|
|
256
|
+
|
|
257
|
+
## Multiple Callbacks and Chaining
|
|
258
|
+
|
|
259
|
+
You can register multiple callbacks on any request object. The
|
|
260
|
+
callbacks can be registered for different events, or all for the
|
|
261
|
+
same event. In addition, you can chain callback registration, for
|
|
262
|
+
example:
|
|
263
|
+
|
|
264
|
+
```javascript
|
|
265
|
+
request.
|
|
266
|
+
on('success', function(response) {
|
|
267
|
+
console.log("Success!");
|
|
268
|
+
}).
|
|
269
|
+
on('error', function(response) {
|
|
270
|
+
console.log("Error!");
|
|
271
|
+
}).
|
|
272
|
+
on('complete', function() {
|
|
273
|
+
console.log("Always!");
|
|
274
|
+
}).
|
|
275
|
+
send();
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
The above example will print either "Success! Always!", or "Error! Always!",
|
|
279
|
+
depending on whether the request succeeded or not.
|
|
280
|
+
|
|
281
|
+
## Streaming Requests
|
|
282
|
+
|
|
283
|
+
It is possible to stream a request directly to a Node.js Stream object by
|
|
284
|
+
calling the `createReadStream()` method on a request. This returns a wrapper
|
|
285
|
+
to the raw HTTP stream used to manage the request, and this data can be piped
|
|
286
|
+
into any other Node.js stream. This is mostly useful for service operations
|
|
287
|
+
that return raw data in the payload, like Amazon S3's `getObject` operation,
|
|
288
|
+
which can be used to stream data directly into a file with this functionality:
|
|
289
|
+
|
|
290
|
+
```javascript
|
|
291
|
+
var s3 = new AWS.S3();
|
|
292
|
+
var params = {Bucket: 'myBucket', Key: 'myImageFile.jpg'};
|
|
293
|
+
var file = require('fs').createWriteStream('/path/to/file.jpg');
|
|
294
|
+
s3.getObject(params).createReadStream().pipe(file);
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
The stream object can be used interchangeably as any other Node.js readable
|
|
298
|
+
Stream object.
|
|
299
|
+
|
|
300
|
+
### Limitations of Streaming
|
|
301
|
+
|
|
302
|
+
When streaming data from a request using `createReadStream()`, only the raw
|
|
303
|
+
HTTP data will be returned (the SDK will not do any post-processing on the
|
|
304
|
+
data). Additionally, if the request initially succeeds, retry logic will be
|
|
305
|
+
disabled for the rest of the response due to Node.js inability to rewind most
|
|
306
|
+
streams. This means that in the event of a socket failure in the middle of a
|
|
307
|
+
connection, the SDK will not attempt to retry and send more data to the stream.
|
|
308
|
+
It will be your responsibility to manage this logic in your library or
|
|
309
|
+
application.
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
# @title Working with Services in Node.js
|
|
2
|
+
|
|
3
|
+
# Working with Services in Node.js
|
|
4
|
+
|
|
5
|
+
## Supported Services
|
|
6
|
+
|
|
7
|
+
The SDK currently supports all available AWS services. Each service object
|
|
8
|
+
in the SDK currently provides low-level access to every API call in the
|
|
9
|
+
respective AWS service. The full list of methods and their parameters are
|
|
10
|
+
documented in the complete API reference documentation (linked from each
|
|
11
|
+
service name in the list below).
|
|
12
|
+
|
|
13
|
+
The supported services are:
|
|
14
|
+
|
|
15
|
+
* [AWS.AutoScaling](http://docs.amazonwebservices.com/AWSJavaScriptSDK/latest/frames.html#!AWS/AutoScaling.html)
|
|
16
|
+
* [AWS.CloudFormation](http://docs.amazonwebservices.com/AWSJavaScriptSDK/latest/frames.html#!AWS/CloudFormation.html)
|
|
17
|
+
* [AWS.CloudFront](http://docs.amazonwebservices.com/AWSJavaScriptSDK/latest/frames.html#!AWS/CloudFront.html)
|
|
18
|
+
* [AWS.CloudSearch](http://docs.amazonwebservices.com/AWSJavaScriptSDK/latest/frames.html#!AWS/CloudSearch.html)
|
|
19
|
+
* [AWS.CloudSearchDomain](http://docs.amazonwebservices.com/AWSJavaScriptSDK/latest/frames.html#!AWS/CloudSearchDomain.html)
|
|
20
|
+
* [AWS.DataPipeline](http://docs.amazonwebservices.com/AWSJavaScriptSDK/latest/frames.html#!AWS/DataPipeline.html)
|
|
21
|
+
* [AWS.DirectConnect](http://docs.amazonwebservices.com/AWSJavaScriptSDK/latest/frames.html#!AWS/DirectConnect.html)
|
|
22
|
+
* [AWS.DynamoDB](http://docs.amazonwebservices.com/AWSJavaScriptSDK/latest/frames.html#!AWS/DynamoDB.html)
|
|
23
|
+
* [AWS.EC2](http://docs.amazonwebservices.com/AWSJavaScriptSDK/latest/frames.html#!AWS/EC2.html)
|
|
24
|
+
* [AWS.ElastiCache](http://docs.amazonwebservices.com/AWSJavaScriptSDK/latest/frames.html#!AWS/ElastiCache.html)
|
|
25
|
+
* [AWS.ElasticBeanstalk](http://docs.amazonwebservices.com/AWSJavaScriptSDK/latest/frames.html#!AWS/ElasticBeanstalk.html)
|
|
26
|
+
* [AWS.ELB](http://docs.amazonwebservices.com/AWSJavaScriptSDK/latest/frames.html#!AWS/ELB.html)
|
|
27
|
+
* [AWS.EMR](http://docs.amazonwebservices.com/AWSJavaScriptSDK/latest/frames.html#!AWS/EMR.html)
|
|
28
|
+
* [AWS.ElasticTranscoder](http://docs.amazonwebservices.com/AWSJavaScriptSDK/latest/frames.html#!AWS/ElasticTranscoder.html)
|
|
29
|
+
* [AWS.SES](http://docs.amazonwebservices.com/AWSJavaScriptSDK/latest/frames.html#!AWS/SES.html)
|
|
30
|
+
* [AWS.Glacier](http://docs.amazonwebservices.com/AWSJavaScriptSDK/latest/frames.html#!AWS/Glacier.html)
|
|
31
|
+
* [AWS.IAM](http://docs.amazonwebservices.com/AWSJavaScriptSDK/latest/frames.html#!AWS/IAM.html)
|
|
32
|
+
* [AWS.ImportExport](http://docs.amazonwebservices.com/AWSJavaScriptSDK/latest/frames.html#!AWS/ImportExport.html)
|
|
33
|
+
* [AWS.CloudWatch](http://docs.amazonwebservices.com/AWSJavaScriptSDK/latest/frames.html#!AWS/CloudWatch.html)
|
|
34
|
+
* [AWS.OpsWorks](http://docs.amazonwebservices.com/AWSJavaScriptSDK/latest/frames.html#!AWS/OpsWorks.html)
|
|
35
|
+
* [AWS.RDS](http://docs.amazonwebservices.com/AWSJavaScriptSDK/latest/frames.html#!AWS/RDS.html)
|
|
36
|
+
* [AWS.Redshift](http://docs.amazonwebservices.com/AWSJavaScriptSDK/latest/frames.html#!AWS/Redshift.html)
|
|
37
|
+
* [AWS.Route53](http://docs.amazonwebservices.com/AWSJavaScriptSDK/latest/frames.html#!AWS/Route53.html)
|
|
38
|
+
* [AWS.S3](http://docs.amazonwebservices.com/AWSJavaScriptSDK/latest/frames.html#!AWS/S3.html)
|
|
39
|
+
* [AWS.SimpleDB](http://docs.amazonwebservices.com/AWSJavaScriptSDK/latest/frames.html#!AWS/SimpleDB.html)
|
|
40
|
+
* [AWS.SNS](http://docs.amazonwebservices.com/AWSJavaScriptSDK/latest/frames.html#!AWS/SNS.html)
|
|
41
|
+
* [AWS.SQS](http://docs.amazonwebservices.com/AWSJavaScriptSDK/latest/frames.html#!AWS/SQS.html)
|
|
42
|
+
* [AWS.StorageGateway](http://docs.amazonwebservices.com/AWSJavaScriptSDK/latest/frames.html#!AWS/StorageGateway.html)
|
|
43
|
+
* [AWS.STS](http://docs.amazonwebservices.com/AWSJavaScriptSDK/latest/frames.html#!AWS/STS.html)
|
|
44
|
+
* [AWS.Support](http://docs.amazonwebservices.com/AWSJavaScriptSDK/latest/frames.html#!AWS/Support.html)
|
|
45
|
+
* [AWS.SimpleWorkflow](http://docs.amazonwebservices.com/AWSJavaScriptSDK/latest/frames.html#!AWS/SimpleWorkflow.html)
|
|
46
|
+
|
|
47
|
+
<div class="clear"></div>
|
|
48
|
+
|
|
49
|
+
## Constructing a Service
|
|
50
|
+
|
|
51
|
+
Each service can be constructed with runtime configuration data that is
|
|
52
|
+
specific to that service object. The service-specific configuration data
|
|
53
|
+
will be merged on top of global configuration, so there is no need to
|
|
54
|
+
re-specify any global settings. For example, an EC2 object can be created
|
|
55
|
+
for a specific region:
|
|
56
|
+
|
|
57
|
+
```javascript
|
|
58
|
+
var ec2 = new AWS.EC2({region: 'us-west-2'});
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
This object will continue to use the globally provided credentials.
|
|
62
|
+
|
|
63
|
+
## Locking API Versions
|
|
64
|
+
|
|
65
|
+
Services released by AWS use API versions to keep track of API compatibility.
|
|
66
|
+
API versions in AWS services can be identified by a `YYYY-mm-dd` formatted
|
|
67
|
+
date string, i.e., 2006-03-01 for Amazon S3. It is recommended to lock into
|
|
68
|
+
an API version for a service if you are relying on it for production code.
|
|
69
|
+
This way, you can isolate yourself from service changes in updates of the
|
|
70
|
+
SDK.
|
|
71
|
+
|
|
72
|
+
In order to lock into an API version of a given service, simply pass the
|
|
73
|
+
`apiVersion` parameter when constructing the object, for example:
|
|
74
|
+
|
|
75
|
+
```javascript
|
|
76
|
+
var dynamodb = new AWS.DynamoDB({apiVersion: '2011-12-05'});
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Note that versions can also be locked globally by specifying the `apiVersion`
|
|
80
|
+
or `apiVersions` global configuration parameters. This is documented with
|
|
81
|
+
more detail in the {file:node-configuring.md Configuring} section.
|
|
82
|
+
|
|
83
|
+
### Using the Latest Version
|
|
84
|
+
|
|
85
|
+
By default, the SDK will select the **latest** available service API version
|
|
86
|
+
when constructing a service object (unless overridden globally). You can
|
|
87
|
+
also force the latest API version to be used by passing the "latest" value
|
|
88
|
+
as the `apiVersion` parameter like so:
|
|
89
|
+
|
|
90
|
+
```javascript
|
|
91
|
+
var ec2 = new AWS.EC2({apiVersion: 'latest'});
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Fuzzy Versions and Date Locking
|
|
95
|
+
|
|
96
|
+
Since AWS has many services with many different API versions, the SDK allows
|
|
97
|
+
for the specification of "fuzzy versions" instead of exact API version
|
|
98
|
+
matches. This allows you to specify any date after the API version date,
|
|
99
|
+
and the SDK will look for the *last* available matching API version when
|
|
100
|
+
loading the service object. For instance, you can also load the 2011-12-05
|
|
101
|
+
DynamoDB API by using the following code:
|
|
102
|
+
|
|
103
|
+
```javascript
|
|
104
|
+
var dynamodb = new AWS.DynamoDB({apiVersion: '2012-04-04'});
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Note that 2012-04-04 is later than the first API release (2011-12-05)
|
|
108
|
+
but earlier than the next revision of the API (2012-08-10), so the *first*
|
|
109
|
+
revision will be used.
|
|
110
|
+
|
|
111
|
+
You can also use this strategy to globally lock your application to a point
|
|
112
|
+
in time. For instance, if you begin developing your application on 2012-07-05,
|
|
113
|
+
you can add the following global `apiVersion` lock value:
|
|
114
|
+
|
|
115
|
+
```javascript
|
|
116
|
+
AWS.config.apiVersion = '2012-07-05';
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
This will allow *all* created service objects to use the latest available
|
|
120
|
+
API versions at the specified lock time. You can override any API versions
|
|
121
|
+
if you need a newer version, or if the service had not yet been released,
|
|
122
|
+
by adding the `apiVersion` parameter to the constructor call as normal:
|
|
123
|
+
|
|
124
|
+
```javascript
|
|
125
|
+
// Amazon Redshift was not yet released in 2012-07-05
|
|
126
|
+
var redshift = new AWS.Redshift({apiVersion: '2012-12-01'});
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## Passing Parameters to a Service Operation
|
|
130
|
+
|
|
131
|
+
When calling a method to a service, you should pass parameters in as
|
|
132
|
+
option values, similar to the way configuration is passed.
|
|
133
|
+
For example, to read an object for a given bucket and key in S3, you
|
|
134
|
+
can pass the following parameters to the `getObject` method:
|
|
135
|
+
|
|
136
|
+
```javascript
|
|
137
|
+
s3.getObject({Bucket: 'bucketName', Key: 'keyName'});
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
Note that the full parameter documentation for each method is found
|
|
141
|
+
in each service page in the complete API reference documentation.
|
|
142
|
+
|
|
143
|
+
## Bound Parameters
|
|
144
|
+
|
|
145
|
+
Parameters can be automatically passed to service operations by binding them
|
|
146
|
+
directly when constructing the service object. To do this, pass the `params`
|
|
147
|
+
parameter to your constructed service with the map of default parameter
|
|
148
|
+
values like so:
|
|
149
|
+
|
|
150
|
+
```javascript
|
|
151
|
+
var s3bucket = new AWS.S3({ params: {Bucket: 'myBucket'} });
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
The `s3bucket` object will now represent an S3 service object bound to a bucket
|
|
155
|
+
named 'myBucket'. Any operation that takes the `Bucket` parameter will now
|
|
156
|
+
have it auto-filled with this value. This value can be overridden by passing
|
|
157
|
+
a new value in the service operation. Additionally, operations that do not
|
|
158
|
+
require a `Bucket` parameter will automatically ignore this bound parameter,
|
|
159
|
+
so the `s3bucket` object can still be used to call `listBuckets`, for instance.
|