node package manager


Extensible Node.js library for the Amazon Web Services API

Node.js library for the Amazon Web Services

Build Status


A simple Node.js library to communicate with the Amazon Web Services API.

It includes clients for the following services:

Richard Rodger maintains a user-friendly SimpleDB library which is based on aws-lib.


The following snippet implements an ec2 client and makes a call to DescribeInstances

var aws = require("aws-lib");
ec2 = aws.createEC2Client(yourAccessKeyId, yourSecretAccessKey);"DescribeInstances", {}, function(err, result) {

Which returns a JSON response similar to:

  "instanceState": {"code":"80","name":"stopped"},
  "reason":"User initiated (2010-07-28 19:37:54 GMT)"

Another example, using Product Advertising API:

var prodAdv = aws.createProdAdvClient(yourAccessKeyId, yourSecretAccessKey, yourAssociateTag);
var options = {SearchIndex: "Books", Keywords: "Javascript"}"ItemSearch", options, function(err, result) {

Will return a long list of books.

Most clients, such as ec2, ses, simpledb, etc. accept an optional third parameter options which should be an object of options used to instantiate the client. For example, the ec2 client could be instantiated with an options object like:

ec2 = aws.createEC2Client(yourAccessKeyId, yourSecretAccessKey, {version: '2010-08-31'});

which would instantiate the ec2 client, but using the 2010-08-31 API version.

The example below shows how you can filter results using one of the list of filters documented in the AWS API docs. See the library code for each service to learn about other possible options.

var options = {
  host: "", // use a different region to the default 
  version: "2010-08-31"
ec2 = aws.createEC2Client(yourAccessKeyId, yourSecretAccessKey, options);
// create a filter for instances with `mytagname = mytagvalue` 
var params = {
  "Filter.1.Name": "tag:mytagname",
  "Filter.1.Value.1": "mytagvalue"
}"DescribeInstances", params, function(err, result) {

For more examples have a look at /examples and /test.

Credentials, metadata API, and IAM Roles

If you use aws-lib on EC2s it is necessary to distribute your AWS API access key and secret id to each EC2 in order to authenticate requests. IAM Roles removes the need to manually distribute your AWS API access key and secret id to EC2s. Create an IAM role(s) and assign to your EC2s (CloudFormation supports IAM Roles). An access key, secret id, and token will then be provided on the EC2 metadata API. You can then use aws-lib without passing in any credentials to API clients. For example:

var aws = require("aws-lib");
ec2 = aws.createEC2Client(); // Notice no access key nor secret id passed in to client"DescribeInstances", {}, function(err, result) {

If no access key or secret id are passed in to the client, aws-lib will attempt to look up the credentials from the EC2 metadata API. The metadata API can also be used like other aws-lib API clients, such as:

var aws = require("aws-lib");
var md = aws.createMetaDataClient();{endpoint: "instance-id"}, function(err, res) {
  console.log(res); // outputs this EC2's instance-id. 


In order to run the tests you need to copy "test/credentials_template.js" to "test/credentials.js" and add your access key and secret.
credentials.js is part of .gitignore so you don't have to worry about accidentially commiting your secret.

To run the tests execute:

npm test


At livelycode we currently can't invest enough time to merge and test all new contributions. So our friends at mapbox offered to jump in and help maintain this library. We have granted Ian Ward commit access to this repository.

aws-lib is designed to be easily extensible.
If you want to add support for a service, have a look at an existing client and simply follow the pattern.
When submitting a pull request please add a test for at least one API call.

Many thanks to the following people who have contributed so far (ordered by number of commits):

Mirko Kiefer
Paul Bonser
Bernhard K. Weisshuhn
David Valentiate
Richard Rodger
Sean Coates
Jonathan Leibiusky
Matt Duncan
Cameron Gray
Blake Matheny
Van Nguyen
Ian Ward
Johannes Auer
Chris Castle
Mike MacCana