About
Amazon Web Services node.js client.
Installation
npm install aws2js
Requires these libraries:
Project and Design goals
- HTTPS-only APIs communication (exceptions allowed for HTTP-only APIs)
- Proper error reporting
- Simple to write clients for a specific AWS service (abstracts most of the low level plumbing)
- Modular design
- Simple to use AWS API calls
- Higher level clients for specific work flows
- Proper documentation
Migrating from pre 0.9
The library loader used by aws2js from v0.3 up to v0.8 is deprecated. Creating a new instance for each service is the preferred way. Creating a new client without specifying the AWS credentials is not allowed, therefore the loader doesn't support this style anymore:
var ec2 = require('aws2js').load('ec2');
ec2.setCredentials('AKIAccessKeyId', 'SecretAccessKey');
You have to add the credentials to the load call even for the deprecated mode:
var ec2 = require('aws2js').load('ec2', 'AKIAccessKeyId', 'SecretAccessKey');
The presence of the AWS credentials is now checked when the client is instantiated instead of checking that with each AWS request. It is the right thing to do at the cost of backward incompatibility.
The String Request Body Handler is removed. http-request was implemented without String support for PUT/POST request bodies, which is a deliberate decision. Use a Buffer instance instead. It can be created from a String:
var body = new Buffer('string to use as buffer');
Supported Amazon Web Services
- EC2 (Elastic Compute Cloud)
- RDS (Relational Database Service)
- SES (Simple Email Service)
- ELB (Elastic Load Balancing)
- IAM (Identity and Access Management)
- AS (Auto Scaling)
- CW (CloudWatch)
- EC (ElastiCache)
- SQS (Simple Queue Service)
- CFN (CloudFormation)
- SDB (SimpleDB)
- STS (Security Token Service)
- DDB (DynamoDB)
- SNS (Simple Notification Service)
- EMR (Elastic MapReduce)
- S3 (Simple Storage Service)
Examples
var aws = require('aws2js');
var EC2 = aws.EC2;
var ec2 = new EC2('accessKeyId', 'secretAccessKey'); // Elastic Compute Cloud
ec2.request('DescribeInstances', function (error, result) {
if (error) {
console.error(error);
return;
}
console.log(result);
});
var RDS = aws.RDS;
var rds = new RDS('accessKeyId', 'secretAccessKey'); // Relational Database Service
rds.request('DescribeDBInstances', function (error, result) {
if (error) {
console.error(error);
return;
}
console.log(result);
});
var SES = aws.SES;
var ses = new SES('accessKeyId', 'secretAccessKey'); // Simple Email Service
ses.request('ListVerifiedEmailAddresses', function (error, result) {
if (error) {
console.error(error);
return;
}
console.log(result);
});
var ELB = aws.ELB;
var elb = new ELB('accessKeyId', 'secretAccessKey'); // Elastic Load Balancing
ses.request('DescribeLoadBalancers', function (error, result) {
if (error) {
console.error(error);
return;
}
console.log(result);
});
var IAM = aws.IAM;
var iam = new IAM('accessKeyId', 'secretAccessKey'); // Identity and Access Management
iam.request('ListUsers', function (error, result) {
if (error) {
console.error(error);
return;
}
console.log(result);
});
var AS = aws.AS;
var as = new AS('accessKeyId', 'secretAccessKey'); // Auto Scaling
as.request('DescribeScalingActivities', function (error, result) {
if (error) {
console.error(error);
return;
}
console.log(result);
});
var CW = aws.CW;
var cw = new CW('accessKeyId', 'secretAccessKey'); // CloudWatch
cw.request('DescribeAlarms', function (error, result) {
if (error) {
console.error(error);
return;
}
console.log(result);
});
var EC = aws.EC;
var ec = new EC('accessKeyId', 'secretAccessKey'); // ElastiCache
ec.request('DescribeCacheClusters', function (error, result) {
if (error) {
console.error(error);
return;
}
console.log(result);
});
var SQS = aws.SQS;
var sqs = new SQS('accessKeyId', 'secretAccessKey'); // Simple Queue Service
sqs.request('ListQueues', function (error, result) {
if (error) {
console.error(error);
return;
}
console.log(result);
});
var CFN = aws.CFN;
var cfn = new CFN('accessKeyId', 'secretAccessKey'); // CloudFormation
cfn.request('DescribeStacks', function (error, result) {
if (error) {
console.error(error);
return;
}
console.log(result);
});
var SDB = aws.SDB;
var sdb = new SDB('accessKeyId', 'secretAccessKey'); // SimpleDB
sdb.request('ListDomains', function (error, result) {
if (error) {
console.error(error);
return;
}
console.log(result);
});
var STS = aws.sts;
var sts = new STS('accessKeyId', 'secretAccessKey'); // Security Token Service
sts.request('GetSessionToken', function (error, result) {
if (error) {
console.error(error);
return;
}
var credentials = result.GetSessionTokenResult.Credentials;
var DDB = aws.DDB;
var ddb = new DDB(credentials.AccessKeyId, credentials.SecretAccessKey, credentials.SessionToken); // DynamoDB
ddb.request('ListTables', function (err, res) {
if (err) {
console.error(err);
return;
}
console.log(res);
});
});
var SNS = aws.SNS;
var sns = new SNS('accessKeyId', 'secretAccessKey'); // Simple Notification Service
sns.request('ListSubscriptions', function (error, result) {
if (error) {
console.error(error);
return;
}
console.log(result);
});
var EMR = aws.EMR;
var emr = new EMR('accessKeyId', 'secretAccessKey'); // Elastic MapReduce
emr.request('DescribeJobFlows', function (error, result) {
if (error) {
console.error(error);
return;
}
console.log(result);
});