

The AWS SDK for JavaScript v2 has reached end-of-support. We recommend that you migrate to [AWS SDK for JavaScript v3](https://docs.aws.amazon.com//sdk-for-javascript/v3/developer-guide/). For additional details and information on how to migrate, please refer to this [announcement](https://aws.amazon.com/blogs//developer/announcing-end-of-support-for-aws-sdk-for-javascript-v2/).

# Setting Up the SDK for JavaScript
<a name="setting-up"></a>

The topics in this section explain how to install the SDK for JavaScript for use in web browsers and with Node.js. It also shows how to load the SDK so you can access the web services supported by the SDK.

**Note**  
React Native developers should use AWS Amplify to create new projects on AWS. See the [aws-sdk-react-native](https://github.com/amazon-archives/aws-sdk-react-native) archive for details.

**Topics**
+ [Prerequisites](jssdk-prerequisites.md)
+ [Installing the SDK for JavaScript](installing-jssdk.md)
+ [Loading the SDK for JavaScript](loading-the-jssdk.md)
+ [Upgrading the SDK for JavaScript from Version 1](upgrading-from-v1.md)

# Prerequisites
<a name="jssdk-prerequisites"></a>

Before you use the AWS SDK for JavaScript, determine whether your code needs to run in Node.js or web browsers. After that, do the following: 
+ For Node.js, install Node.js on your servers if it is not already installed.
+ For web browsers, identify the browser versions you need to support.

**Topics**
+ [Setting Up an AWS Node.js Environment](setting-up-node.md)
+ [Web Browsers Supported](browsers-supported.md)

# Setting Up an AWS Node.js Environment
<a name="setting-up-node"></a>

To set up an AWS Node.js environment in which you can run your application, use any of the following methods:
+ Choose an Amazon Machine Image (AMI) with Node.js pre-installed and create an Amazon EC2 instance using that AMI. When creating your Amazon EC2 instance, choose your AMI from the AWS Marketplace. Search the AWS Marketplace for Node.js and choose an AMI option that includes a version of Node.js (32-bit or 64-bit) pre-installed.
+ Create an Amazon EC2 instance and install Node.js on it. For more information about how to install Node.js on an Amazon Linux instance, see [Tutorial: Setting Up Node.js on an Amazon EC2 Instance](setting-up-node-on-ec2-instance.md).
+ Create a serverless environment using AWS Lambda to run Node.js as a Lambda function. For more information about using Node.js within a Lambda function, see [Programming Model (Node.js)](https://docs.aws.amazon.com/lambda/latest/dg/programming-model.html) in the *AWS Lambda Developer Guide*.
+ Deploy your Node.js application to AWS Elastic Beanstalk. For more information on using Node.js with Elastic Beanstalk, see [Deploying Node.js Applications to AWS Elastic Beanstalk](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_nodejs.html) in the *AWS Elastic Beanstalk Developer Guide*. 

# Web Browsers Supported
<a name="browsers-supported"></a>

The SDK for JavaScript supports all modern web browsers, including these minimum versions:


****  

| Browser | Version | 
| --- | --- | 
| Google Chrome | 28.0\$1 | 
| Mozilla Firefox | 26.0\$1 | 
| Opera | 17.0\$1 | 
| Microsoft Edge | 25.10\$1 | 
| Windows Internet Explorer | N/A | 
| Apple Safari | 5\$1 | 
| Android Browser | 4.3\$1 | 

**Note**  
Frameworks such as AWS Amplify might not offer the same browser support as the SDK for JavaScript. Check a framework's documentation for details.

# Installing the SDK for JavaScript
<a name="installing-jssdk"></a>

Whether and how you install the AWS SDK for JavaScript depends whether the code executes in Node.js modules or browser scripts.

Not all services are immediately available in the SDK. To find out which services are currently supported by the AWS SDK for JavaScript, see [https://github.com/aws/aws-sdk-js/blob/master/SERVICES.md](https://github.com/aws/aws-sdk-js/blob/master/SERVICES.md)

------
#### [ Node ]

The preferred way to install the AWS SDK for JavaScript for Node.js is to use [npm, the Node.js package manager](https://www.npmjs.com/). To do so, type this at the command line.

```
npm install aws-sdk
```

In the event you see this error message:

```
npm WARN deprecated node-uuid@1.4.8: Use uuid module instead
```

Type these commands at the command line:

```
npm uninstall --save node-uuid
npm install --save uuid
```

------
#### [ Browser ]

You don't have to install the SDK to use it in browser scripts. You can load the hosted SDK package directly from Amazon Web Services with a script in your HTML pages. The hosted SDK package supports the subset of AWS services that enforce cross-origin resource sharing (CORS). For more information, see [Loading the SDK for JavaScript](loading-the-jssdk.md).

You can create a custom build of the SDK in which you select the specific web services and versions that you want to use. You then download your custom SDK package for local development and host it for your application to use. For more information about creating a custom build of the SDK, see [Building the SDK for Browsers](building-sdk-for-browsers.md).

You can download minified and non-minified distributable versions of the current AWS SDK for JavaScript from GitHub at:

[https://github.com/aws/aws-sdk-js/tree/master/dist](https://github.com/aws/aws-sdk-js/tree/master/dist)

------

## Installing Using Bower
<a name="w2aac13c11b9"></a>

[Bower](https://bower.io) is a package manager for the web. After you install Bower, you can use it to install the SDK. To install the SDK using Bower, type the following into a terminal window:

```
bower install aws-sdk-js
```

# Loading the SDK for JavaScript
<a name="loading-the-jssdk"></a>

How you load the SDK for JavaScript depends on whether you are loading it to run in a web browser or in Node.js.

Not all services are immediately available in the SDK. To find out which services are currently supported by the AWS SDK for JavaScript, see [https://github.com/aws/aws-sdk-js/blob/master/SERVICES.md](https://github.com/aws/aws-sdk-js/blob/master/SERVICES.md)

------
#### [ Node.js ]

After you install the SDK, you can load the AWS package in your node application using `require`. 

```
var AWS = require('aws-sdk');
```

------
#### [ React Native ]

To use the SDK in a React Native project, first install the SDK using npm:

```
npm install aws-sdk
```

In your application, reference the React Native compatible version of the SDK with the following code:

```
var AWS = require('aws-sdk/dist/aws-sdk-react-native');
```

------
#### [ Browser ]

The quickest way to get started with the SDK is to load the hosted SDK package directly from Amazon Web Services. To do this, add a `<script>` element to your HTML pages in the following form:

```
<script src="https://sdk.amazonaws.com/js/aws-sdk-SDK_VERSION_NUMBER.min.js"></script>
```

To find the current SDK\$1VERSION\$1NUMBER, see the API Reference for the SDK for JavaScript at [AWS SDK for JavaScript API Reference Guide](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/).

After the SDK loads in your page, the SDK is available from the global variable `AWS` (or `window.AWS`).

If you bundle your code and module dependencies using [browserify](http://browserify.org), you load the SDK using `require`, just as you do in Node.js.

------

# Upgrading the SDK for JavaScript from Version 1
<a name="upgrading-from-v1"></a>

The following notes help you upgrade the SDK for JavaScript from version 1 to version 2.

## Automatic Conversion of Base64 and Timestamp Types on Input/Output
<a name="upgrading-from-v1-base64-timestamp-conversion"></a>

The SDK now automatically encodes and decodes base64-encoded values, as well as timestamp values, on the user's behalf. This change affects any operation where base64 or timestamp values were sent by a request or returned in a response that allows for base64-encoded values.

User code that previously converted base64 is no longer required. Values encoded as base64 are now returned as buffer objects from server responses and can also be passed as buffer input. For example, the following version 1 `SQS.sendMessage` parameters:

```
var params = {
   MessageBody: 'Some Message',
   MessageAttributes: {
      attrName: {
         DataType: 'Binary',
         BinaryValue: new Buffer('example text').toString('base64')
      }
   }
};
```

Can be rewritten as follows.

```
var params = {
   MessageBody: 'Some Message',
   MessageAttributes: {
      attrName: {
         DataType: 'Binary',
         BinaryValue: 'example text'
      }
   }
};
```

Here is how the message is read.

```
sqs.receiveMessage(params, function(err, data) {
  // buf is <Buffer 65 78 61 6d 70 6c 65 20 74 65 78 74>
  var buf = data.Messages[0].MessageAttributes.attrName.BinaryValue;
  console.log(buf.toString()); // "example text"
});
```

## Moved response.data.RequestId to response.requestId
<a name="upgrading-from-v1-response-requestid"></a>

The SDK now stores request IDs for all services in a consistent place on the `response` object, rather than inside the `response.data` property. This improves consistency across services that expose request IDs in different ways. This is also a breaking change that renames the `response.data.RequestId` property to `response.requestId` (`this.requestId` inside a callback function).

In your code, change the following:

```
svc.operation(params, function (err, data) {
  console.log('Request ID:', data.RequestId);
});
```

To the following:

```
svc.operation(params, function () {
  console.log('Request ID:', this.requestId);
});
```

## Exposed Wrapper Elements
<a name="upgrading-from-v1-exposed-wrapper-elements"></a>

If you use `AWS.ElastiCache`, `AWS.RDS`, or `AWS.Redshift`, you must access the response through the top-level output property in the response for some operations. 

For example, the `RDS.describeEngineDefaultParameters` method used to return the following.

```
{ Parameters: [ ... ] }
```

It now returns the following.

```
{ EngineDefaults: { Parameters: [ ... ] } }
```

The list of affected operations for each service are shown in the following table.


****  

| Client Class | Operations | 
| --- | --- | 
| `AWS.ElastiCache` | `authorizeCacheSecurityGroupIngress` `createCacheCluster` `createCacheParameterGroup` `createCacheSecurityGroup` `createCacheSubnetGroup` `createReplicationGroup` `deleteCacheCluster` `deleteReplicationGroup` `describeEngineDefaultParameters` `modifyCacheCluster` `modifyCacheSubnetGroup` `modifyReplicationGroup` `purchaseReservedCacheNodesOffering` `rebootCacheCluster` `revokeCacheSecurityGroupIngress` | 
| `AWS.RDS` | `addSourceIdentifierToSubscription` `authorizeDBSecurityGroupIngress` `copyDBSnapshot` `createDBInstance` `createDBInstanceReadReplica` `createDBParameterGroup` `createDBSecurityGroup` `createDBSnapshot` `createDBSubnetGroup` `createEventSubscription` `createOptionGroup` `deleteDBInstance` `deleteDBSnapshot` `deleteEventSubscription` `describeEngineDefaultParameters` `modifyDBInstance` `modifyDBSubnetGroup` `modifyEventSubscription` `modifyOptionGroup` `promoteReadReplica` `purchaseReservedDBInstancesOffering` `rebootDBInstance` `removeSourceIdentifierFromSubscription` `restoreDBInstanceFromDBSnapshot` `restoreDBInstanceToPointInTime` `revokeDBSecurityGroupIngress` | 
| `AWS.Redshift` | `authorizeClusterSecurityGroupIngress` `authorizeSnapshotAccess` `copyClusterSnapshot` `createCluster` `createClusterParameterGroup` `createClusterSecurityGroup` `createClusterSnapshot` `createClusterSubnetGroup` `createEventSubscription` `createHsmClientCertificate` `createHsmConfiguration` `deleteCluster` `deleteClusterSnapshot` `describeDefaultClusterParameters` `disableSnapshotCopy` `enableSnapshotCopy` `modifyCluster` `modifyClusterSubnetGroup` `modifyEventSubscription` `modifySnapshotCopyRetentionPeriod` `purchaseReservedNodeOffering` `rebootCluster` `restoreFromClusterSnapshot` `revokeClusterSecurityGroupIngress` `revokeSnapshotAccess` `rotateEncryptionKey` | 

## Dropped Client Properties
<a name="upgrading-from-v1-dropped-client-properties"></a>

The `.Client` and `.client` properties have been removed from service objects. If you use the `.Client` property on a service class or a `.client` property on a service object instance, remove these properties from your code.

The following code used with version 1 of the SDK for JavaScript:

```
var sts = new AWS.STS.Client();
// or
var sts = new AWS.STS();

sts.client.operation(...);
```

Should be changed to the following code.

```
var sts = new AWS.STS();
sts.operation(...)
```