AWS SDK for Java
Developer Guide

Using IAM Account Aliases

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.

Note

AWS supports exactly one account alias per account.

Creating an Account Alias

To create an account alias, call the AmazonIdentityManagementClient's createAccountAlias method with a CreateAccountAliasRequest object that contains the alias name.

Imports

import com.amazonaws.services.identitymanagement.AmazonIdentityManagement; import com.amazonaws.services.identitymanagement.AmazonIdentityManagementClientBuilder; import com.amazonaws.services.identitymanagement.model.CreateAccountAliasRequest; import com.amazonaws.services.identitymanagement.model.CreateAccountAliasResult;

Code

final AmazonIdentityManagement iam = AmazonIdentityManagementClientBuilder.defaultClient(); CreateAccountAliasRequest request = new CreateAccountAliasRequest() .withAccountAlias(alias); CreateAccountAliasResult response = iam.createAccountAlias(request);

See the complete example on GitHub.

Listing Account Aliases

To list your account's alias, if any, call the AmazonIdentityManagementClient's listAccountAliases method.

Note

The returned ListAccountAliasesResponse supports the same getIsTruncated and getMarker methods as other AWS SDK for Javalist methods, but an AWS account can have only one account alias.

imports

import com.amazonaws.services.identitymanagement.AmazonIdentityManagement; import com.amazonaws.services.identitymanagement.AmazonIdentityManagementClientBuilder; import com.amazonaws.services.identitymanagement.model.ListAccountAliasesResult;

code

final AmazonIdentityManagement iam = AmazonIdentityManagementClientBuilder.defaultClient(); ListAccountAliasesResult response = iam.listAccountAliases(); for (String alias : response.getAccountAliases()) { System.out.printf("Retrieved account alias %s", alias); }

see the complete example on GitHub.

Deleting an account alias

To delete your account's alias, call the AmazonIdentityManagementClient's deleteAccountAlias method. When deleting an account alias, you must supply its name using a DeleteAccountAliasRequest object.

imports

import com.amazonaws.services.identitymanagement.AmazonIdentityManagement; import com.amazonaws.services.identitymanagement.AmazonIdentityManagementClientBuilder; import com.amazonaws.services.identitymanagement.model.DeleteAccountAliasRequest; import com.amazonaws.services.identitymanagement.model.DeleteAccountAliasResult;

Code

final AmazonIdentityManagement iam = AmazonIdentityManagementClientBuilder.defaultClient(); DeleteAccountAliasRequest request = new DeleteAccountAliasRequest() .withAccountAlias(alias); DeleteAccountAliasResult response = iam.deleteAccountAlias(request);

See the complete example on GitHub.

More Information