Page 1
AWS SDK for Node.js Getting Started Guide Version 0.9.1-pre.2 : Preview...
Page 2
AWS SDK for Node.js Getting Started Guide Amazon Web Services...
Page 3
Amazon's trademarks and trade dress may not be used in connection with any product or service that is not Amazon's, in any manner that is likely to cause confusion among customers, or in any manner that disparages or discredits Amazon.
The official JavaScript implementation of the AWS SDK for Node.js. Installing To use the AWS SDK for Node.js, you must have an AWS account. If you do not yet have an AWS account, see AWS Account and Credentials (p. 2) for instructions on how to sign up.
Apache License, Version 2.0. Copyright 2012. Amazon Web Services, Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0...
Page 7
Store it securely in a safe place, and never email it. Do not share it outside your organization, even if an inquiry appears to come from AWS or Amazon.com. No one who legitimately represents Amazon will ever ask you for your secret key.
Setting AWS Credentials Note Remember, if you set your AWS credentials in your environment variables, the AWS SDK for Node.js will automatically detect them, and you will not need to perform any manual credential configuration in your application.
Page 9
AWS SDK for Node.js Getting Started Guide Setting AWS Credentials Credentials are the most important thing you need to set when using any AWS SDK. Credentials can be set globally on the AWS.config object or per service by passing the credential information to the service object directly.
Page 10
AWS.config.update() : AWS.config.update({accessKeyId: 'akid', secretAccessKey: 'secret'}); Setting the Region The AWS SDK for Node.js doesn't select the region by default. You can choose a region similarly to setting credentials by either loading from disk or using AWS.config.update() : AWS.config.update({region: 'us-west-1'});...
AWS SDK for Node.js Getting Started Guide Supported Services Services Supported Services Here's the list of supported service objects: • AWS.AutoScaling • AWS.CloudFormation • AWS.CloudFront • AWS.CloudSearch • AWS.CloudWatch • AWS.DataPipeline • AWS.DirectConnect • AWS.DynamoDB • AWS.EC2 • AWS.ElastiCache •...
Page 12
AWS SDK for Node.js Getting Started Guide Constructing a Service • AWS.StorageGateway • AWS.STS Each service object in the SDK currently provides low-level access to every API call in the respective AWS service. The full list of methods and their parameters are documented in the complete API reference (linked from each service name in the above list).
AWS SDK for Node.js Getting Started Guide Asynchronous Callbacks Making Requests Asynchronous Callbacks All requests made through the SDK are asynchronous and use a callback interface. Each service method that kicks off a request can accept a callback as the last parameter with the signature function(error, data) { ...
Page 14
The response.data property contains the serialized object data retrieved from the service request. For instance, for an Amazon DynamoDB listTables method call, the response data might look like this: > response.data { TableNames: [ 'table1', 'table2', ... ] } The data property can be null if an error occurs (see below).
Page 15
AWS SDK for Node.js Getting Started Guide Simplified Callback Method 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.
Page 17
AWS SDK for Node.js Getting Started Guide on('httpData', function(chunk, response) { ... }) on('httpData', function(chunk, response) { ... }) Note If you register a httpData callback, response.data will still contain serialized output for the entire request. It will be your responsibility to remove the default 'httpData' listener if you do not wish to have the extra parsing and memory overhead from the built-in handlers.
AWS SDK for Node.js Getting Started Guide Amazon Simple Storage Service (Amazon S3) 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'});...
Page 19
HTTP body data to a file. This is especially useful when streaming objects to streams like filesystem objects. The following example shows how you can stream an object from Amazon S3 directly to a file on disk: var s3 = new AWS.S3();...
Need help?
Do you have a question about the AWS SDK and is the answer not in the manual?
Questions and answers