EasyManuals Logo

Amazon AWS SDK User Manual

Amazon AWS SDK
19 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #15 background imageLoading...
Page #15 background image
Simplified Callback Method
Each operation supports a simplified callback that can be passed as the last parameter to any low-level
client operation.The callback function should accept an error parameter, followed by the data from
the response.
For example:
s3.client.listBuckets(function(error, data) {
if (err) {
console.log(error); // error is Response.error
} else {
console.log(data); // data is Response.data
}
});
Prints (assuming the request succeeded):
{ Owner: { ID: '...', DisplayName: '...' },
Buckets:
[ { Name: 'someBucketName', CreationDate: someCreationDate },
{ Name: 'otherBucketName', CreationDate: otherCreationDate } ],
RequestId: '...' }
The error and data parameters accepted are equivalent to the error and data properties discussed in
the AWS.Response response object section above.
If you are passing parameters to the operation, the callback should be placed after the parameters:
s3.client.getObject({Bucket: 'bucket', Key: 'key'}, function(err, data) {
// ...
});
AWS.Request Events
You can alternatively register callbacks on events provided by the AWS.Request object returned by each
low-level client operation method.This request object exposes the success, error, complete, and
httpData events, each taking a callback that accepts the response object.
Note that if you omit the simplified callback parameter on the operation method, you must call send()
on the returned request object in order to kick off the request to the remote server.
on('success', function(response) { ... })
This event triggers when a successful response from the server is returned.The response contains a
.data field with the serialized response data from the service.
For example:
Version 0.9.1-pre.2 : Preview
11
AWS SDK for Node.js Getting Started Guide
Simplified Callback Method

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Amazon AWS SDK and is the answer not in the manual?

Amazon AWS SDK Specifications

General IconGeneral
CategorySoftware Development Kit (SDK)
DeveloperAmazon Web Services (AWS)
LicenseApache License 2.0
PurposeTo enable developers to interact with AWS services from their applications.
Supported LanguagesJava, Python, JavaScript, .NET, Ruby, PHP, Go, C++
Supported AWS ServicesAll AWS services
Operating SystemsWindows, macOS, Linux
Latest VersionVaries by SDK and language. Refer to the official AWS documentation for the specific SDK.
RepositoryGitHub (for many SDKs)
DocumentationAvailable on the AWS website.
SDK FeaturesAPI abstraction, request signing, error handling, retry logic, data serialization, and support for various authentication methods.

Related product manuals