EasyManua.ls 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 #16 background imageLoading...
Page #16 background image
s3.client.listBuckets().done(function(response) {
console.log(response.data);
}).send();
Prints:
{ Owner: { ID: '...', DisplayName: '...' },
Buckets:
[ { Name: 'someBucketName', CreationDate: someCreationDate },
{ Name: 'otherBucketName', CreationDate: otherCreationDate } ],
RequestId: '...' }
on('error', function(error, response) { ... })
The error event works similarly to the success event, except that it triggers in the case of a request
failure. In this case, response.data will be null and the response.error field will be filled with the
error data. Note that the error object is also passed directly as the first parameter to the event:
s3.config.credentials.accessKeyId = 'invalid';
s3.client.listBuckets().fail(function(error, response) {
console.log(error);
// or:
console.log(response.error);
}).send();
Prints:
{ code: 'Forbidden', message: null }
on('complete', function(response) { ... })
The complete event triggers a callback in any final state of a request, i.e., both success and error.
Use this callback to handle any request cleanup that must be executed regardless of the success state.
Note that if you do intend to use response data inside of this callback, you must check for the presence
of response.data or response.error before attempting to access either property. For example:
request.on('complete', function(response) {
if (response.error) {
// an error occurred, handle it
} else {
// we can use response.data here
}
}).send();
Version 0.9.1-pre.2 : Preview
12
AWS SDK for Node.js Getting Started Guide
on('error', function(error, response) { ...
})
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.

Summary

AWS SDK Installation and Initial Usage

Installation

Install the AWS SDK for Node.js using the npm package manager.

Usage

Require the AWS SDK package in your Node.js application.

AWS Account and Credentials

Signing Up for an AWS Account

Steps to create an AWS account and obtain credentials.

Viewing Access Credentials

How to find your AWS access key ID and secret access key.

Configuration Guide

The Configuration Object

Explains how to configure the SDK globally or per service.

Setting AWS Credentials

Methods for providing SDK credentials (env variables, disk).

Setting the Region

Configuring the AWS region for SDK requests.

Service-Specific Configuration

Applying configuration settings to individual service objects.

Supported AWS Services

List of Services

Provides a comprehensive list of supported AWS services.

Constructing a Service Object

How to create service-specific objects for API calls.

Making AWS SDK Requests

Asynchronous Callbacks

Handling asynchronous operations using callback functions.

Request and Response Objects

Understanding the structure of request and response data.

Simplified Callback Method

Using a simplified callback signature for operations.

AWS Request Events

Registering callbacks for request lifecycle events (success, error).

Multiple Callbacks and Chaining

Chaining multiple callbacks for comprehensive request handling.

Examples and Use Cases

Amazon S3 Operations

Examples of listing buckets and creating objects in S3.

Amazon DynamoDB Operations

Example for listing tables in Amazon DynamoDB.

Related product manuals