We announced
Managing IAM Account Aliases
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
aliases 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:
Install Node.js. For more information about installing Node.js, see the Node.js website
. Create a shared configurations file with your user credentials. For more information about providing a shared credentials file, see Loading Credentials in Node.js from the Shared Credentials File.
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