Managing IAM Account Aliases - Amazon SDK for JavaScript
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China.

The Amazon SDK for JavaScript version 3 (v3) is a rewrite of v2 with some great new features, including modular architecture. For more information, see the Amazon SDK for JavaScript v3 Developer Guide.

Managing IAM Account Aliases

JavaScript code example that applies to Node.js execution

This Node.js code example shows:

  • How to manage aliases for your Amazon account ID.

The Scenario

If you want the URL for your sign-in page to contain your company name or other friendly identifier instead of your Amazon account ID, you can create an alias for your Amazon account ID. If you create an Amazon account alias, your sign-in page URL changes to incorporate the alias.

In this example, a series of Node.js modules are used to create and manage IAM account aliases. The Node.js modules use the SDK for JavaScript to manage aliases using these methods of the AWS.IAM client class:

For more information about IAM account aliases, see Your Amazon Account ID and Its Alias in the IAM User Guide.

Prerequisite Tasks

To set up and run this example, you must first complete these tasks:

Creating an Account Alias

Create a Node.js module with the file name iam_createaccountalias.js. Be sure to configure the SDK as previously shown. To access IAM, create an AWS.IAM service object. Create a JSON object containing the parameters needed to create an account alias, which includes the alias you want to create. Call the createAccountAlias method of the AWS.IAM service object.

// Load the AWS SDK for Node.js var AWS = require('aws-sdk'); // Set the region AWS.config.update({region: 'REGION'}); // Create the IAM service object var iam = new AWS.IAM({apiVersion: '2010-05-08'}); iam.createAccountAlias({AccountAlias: process.argv[2]}, function(err, data) { if (err) { console.log("Error", err); } else { console.log("Success", data); } });

To run the example, type the following at the command line.

node iam_createaccountalias.js ALIAS

This sample code can be found here on GitHub.

Listing Account Aliases

Create a Node.js module with the file name iam_listaccountaliases.js. Be sure to configure the SDK as previously shown. To access IAM, create an AWS.IAM service object. Create a JSON object containing the parameters needed to list account aliases, which includes the maximum number of items to return. Call the listAccountAliases method of the AWS.IAM service object.

// Load the AWS SDK for Node.js var AWS = require('aws-sdk'); // Set the region AWS.config.update({region: 'REGION'}); // Create the IAM service object var iam = new AWS.IAM({apiVersion: '2010-05-08'}); iam.listAccountAliases({MaxItems: 10}, function(err, data) { if (err) { console.log("Error", err); } else { console.log("Success", data); } });

To run the example, type the following at the command line.

node iam_listaccountaliases.js

This sample code can be found here on GitHub.

Deleting an Account Alias

Create a Node.js module with the file name iam_deleteaccountalias.js. Be sure to configure the SDK as previously shown. To access IAM, create an AWS.IAM service object. Create a JSON object containing the parameters needed to delete an account alias, which includes the alias you want deleted. Call the deleteAccountAlias method of the AWS.IAM service object.

// Load the AWS SDK for Node.js var AWS = require('aws-sdk'); // Set the region AWS.config.update({region: 'REGION'}); // Create the IAM service object var iam = new AWS.IAM({apiVersion: '2010-05-08'}); iam.deleteAccountAlias({AccountAlias: process.argv[2]}, function(err, data) { if (err) { console.log("Error", err); } else { console.log("Success", data); } });

To run the example, type the following at the command line.

node iam_deleteaccountalias.js ALIAS

This sample code can be found here on GitHub.