• Stars
    star
    681
  • Rank 63,949 (Top 2 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 13 years ago
  • Updated about 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Extensible Node.js library for the Amazon Web Services API

Node.js library for the Amazon Web Services

Build Status

NPM

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.

Usage

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

var aws = require("aws-lib");

ec2 = aws.createEC2Client(yourAccessKeyId, yourSecretAccessKey);

ec2.call("DescribeInstances", {}, function(err, result) {
  console.log(result);
})

Which returns a JSON response similar to:

[...]
{"item":{
  "instanceId":"i-acb2d1db","imageId":"ami-03765c77",
  "instanceState": {"code":"80","name":"stopped"},
  "privateDnsName":{},"dnsName":{},
  "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"}

prodAdv.call("ItemSearch", options, function(err, result) {
  console.log(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: "ec2.eu-west-1.amazonaws.com", // 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"
}

ec2.call("DescribeInstances", params, function(err, result) {
  console.log(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
ec2.call("DescribeInstances", {}, function(err, result) {
  console.log(JSON.stringify(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();
md.call({endpoint: "instance-id"}, function(err, res) {
  console.log(res); // outputs this EC2's instance-id.
});

Tests

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

Contributing

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
Kent
David Valentiate
Richard Rodger
Sean Coates
john
Jonathan Leibiusky
Matt Duncan
Cameron Gray
Bryon
nagoodman
Blake Matheny
Van Nguyen
Ian Ward
Johannes Auer
Chris Castle
Mike MacCana

More Repositories

1

syncing-thesis

Syncing strategies for mobile apps. A Protocol for Peer-to-Peer Data Synchronization.
TeX
118
star
2

bunyan-cloudwatch

Writable stream to write bunyan logs to AWS CloudWatch
JavaScript
47
star
3

spawn.js

spawn functions in a new Node
JavaScript
37
star
4

canonical-json

Canonical JSON implementation - a repeatable version of JSON.stringify
JavaScript
36
star
5

async-iterators

Utility functions for the async-iterator pattern in Node.js
JavaScript
16
star
6

Node-Magick

GraphicsMagick wrapper for Node.js
JavaScript
13
star
7

osm-routing

An OpenStreetMap based geo-routing system written in Erlang
Erlang
10
star
8

diff-merge-patch

diff, merge and patch sets, dictionaries and lists in javascript
JavaScript
6
star
9

array-diff

diffs of arrays based on longest common subsequences
JavaScript
6
star
10

LivelyBlocks

Objective-C library that allows you to use forEach, filter or collect on NSArray
Objective-C
5
star
11

stream-iterator

Transform a node.js stream into an async iterator
JavaScript
4
star
12

line-iterator

iterate over streams (or iterators) by line in Node.js
JavaScript
3
star
13

bunyan-pretty

Pretty-printed bunyan output in Node.js
JavaScript
3
star
14

bluetooth-low-energy-demo

Bluetooth low-energy demo featuring the iPhone gyrometer, a Node.js central, Websockets and Three.js
Objective-C
3
star
15

ObjectiveGraphics

an object-oriented, declarative interface to CoreGraphics
Objective-C
3
star
16

express-layout

CoffeeScript
2
star
17

lua-experiments

experiments with c, lua, mongoose and cmake
C
2
star
18

HistoDB

A forkable database that runs in the browser and on Node.js
JavaScript
2
star
19

ancestor

find the lowest common ancestor in a directed, acyclic graph
JavaScript
2
star
20

array-merge

3-way merging of arrays
JavaScript
2
star
21

graph-difference

find the subgraph between two nodes in a directed acyclic graph
JavaScript
2
star
22

synclib

distributed syncing to build offline apps
CoffeeScript
2
star
23

dockerfile-node

Shell
2
star
24

luajit.cmake

2
star
25

LivelyC

An object system and object database for C.
C
2
star
26

lambda-api-example

Implementing a Node.js based API with AWS Lambda and API Gateway
JavaScript
2
star
27

dockerfile-base

Shell
2
star
28

express-layout-addons

CoffeeScript
1
star
29

content-addressable

a content-addressable store interface
CoffeeScript
1
star
30

DataInk

create data-driven graphics on iOS and OSX
Objective-C
1
star
31

histo-fs

a file-system data type for HistoDB
JavaScript
1
star
32

mirkos-boxen

Ruby
1
star
33

LivelyStore

A git-inspired content tracker written as a C library
C
1
star
34

filter-csv

filter csv files
JavaScript
1
star
35

range-merge

merge range-maps
JavaScript
1
star
36

flights

An interactive map showing outgoing flights from US airports
JavaScript
1
star
37

dockerfile-beaver

Shell
1
star
38

dockerfile-couchdb

Shell
1
star
39

MoonStore

start of a library for data tracking and syncing in Lua
Lua
1
star
40

Dockerfiles

my collection of Dockerfiles for node, couchdb, elasticsearch and logstash
Shell
1
star
41

longest-common-substring

javascript implementation of the longest common substring problem
JavaScript
1
star
42

chef-couchdb

fork of the travis couchdb cookbook
Ruby
1
star
43

backbone-listview

a generic list-view for backbone
CoffeeScript
1
star
44

id-merge

3-way merging of arrays with identifyable objects
JavaScript
1
star
45

Grammars

an erlang parser generator
Erlang
1
star
46

csv2json

Node.js utility script to convert csv to json
JavaScript
1
star
47

octopress-theme-classic-light

octopress classic theme re-styled for simplicity
JavaScript
1
star
48

dockerfile-boom

Docker container for boom, the http load generator
Shell
1
star
49

SyncDemo

demoing synclib for building offline webapps
JavaScript
1
star