Menu
AWS SDK for JavaScript
Developer Guide for SDK v2.154.0

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 AWS 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 AWS account ID, you can create an alias for your AWS account ID. If you create an AWS 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 alises using these methods of the AWS.IAM client class:

For more information about IAM account aliases, see Your AWS 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:

Configuring the SDK

Configure the SDK for JavaScript by creating a global configuration object then setting the region for your code. In this example, the region is set to us-west-2.

Copy
// Load the SDK for JavaScript var AWS = require('aws-sdk'); // Set the region AWS.config.update({region: 'us-west-2'});

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.

Copy
// 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) { throw err; } else { console.log('Account alias ' + process.argv[2] + ' created.'); } });

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

Copy
node iam_createaccountalias.js ALIAS

This sample code can be found here on GitHub.

Listing Account Alises

Create a Node.js module with the file name iam_listaccountalises.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 alises, which includes the maximum number of items to return. Call the listAccountAlises method of the AWS.IAM service object.

Copy
// 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) { throw err; } else { console.log('Aliases: ' + data.AccountAliases.join(', ')); } });

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

Copy
node iam_listaccountalises.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.

Copy
// 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) { throw err; } else { console.log('Account alias ' + process.argv[2] + ' deleted.'); } });

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

Copy
node iam_deleteaccountalias.js ALIAS

This sample code can be found here on GitHub.