node-iam
This is an AWS IAM client for Node.js. For a real use-case, see aws-bootstrap.
Pre-Reqs
Via the command line, or process.env
, set:
process.env['AWS_ACCESS_KEY_ID'] = '<ID>';
process.env['AWS_SECRET_ACCESS_KEY'] = '<KEY>';
Then instantiate a new client in your application:
var REST = require('node-iam');
var client = new REST.AmazonIAMClient();
All responses are returned in JSON
. When useful, cleaned-up objects are returned.
Usage
To create a group:
client.createGroup('<groupName>', function(response) {
console.log(response);
});
To view groups:
client.listGroups(function(response, groups) {
console.log(response);
groups.forEach(function(group) {
console.log('Group: ' + group);
});
});
To create a group security policy:
var policy = '{"Statement":[{"Effect":"Allow","Action":"*","Resource":"*"}]}';
client.putGroupPolicy('<groupName>', '<groupPolicyName>', policy, function(response) {
console.log(response);
});
To list security policies for a group:
client.listGroupPolicies('<groupName>', function(response, policies) {
console.log(response);
});
To create a user:
client.createUser('<userName>', function(response) {
console.log(response);
});
To allow a user login:
client.createUserLoginProfile('<userName>', '<password>', function(response) {
console.log(response);
});
To view users:
client.listUsers(function(response, users) {
console.log(response);
users.forEach(function(user) {
console.log('User: ' + user);
});
});
To add a user to a group:
client.addUserToGroup('<userName>', '<groupName>', function(response) {
console.log(response);
});
To create a user security policy:
var policy = '{"Statement":[{"Effect":"Allow","Action":"*","Resource":"*"}]}';
client.putUserPolicy('<userName>', '<userPolicyName>', policy, function(response) {
console.log(response);
});
To list security policies for a user:
client.listUserPolicies('<userName>', function(response, policies) {
console.log(response);
});
To list access keys for a user:
client.listAccessKeys('<userName>', function(response) {
console.log(response);
});
To list access keys at a higher level:
client.listAccessKeys(function(response) {
console.log(response);
});
To create credentials for a user:
client.createAccessKey('<userName>', function(response) {
console.log(response);
});
To delete credentials for a user:
client.deleteAccessKey('<userName>', function(response) {
console.log(response);
});
To view an account summary:
client.getAccountSummary(function(response) {
console.log(response);
});