AWS SDK for Java
Developer Guide

Using IAM Account Aliases

Important

This is a preview release and is not recommended for production environments.

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 IamClient's createAccountAlias method with a CreateAccountAliasRequest object that contains the alias name.

Imports

import software.amazon.awssdk.services.iam.model.CreateAccountAliasRequest; import software.amazon.awssdk.services.iam.model.CreateAccountAliasResponse; import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.iam.IamClient;

Code

Region region = Region.AWS_GLOBAL; IamClient iam = IamClient.builder().region(region).build(); CreateAccountAliasRequest request = CreateAccountAliasRequest.builder() .accountAlias(alias).build(); CreateAccountAliasResponse response = iam.createAccountAlias(request);

See the complete example on GitHub.

Listing Account Aliases

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

Note

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

imports

import software.amazon.awssdk.services.iam.model.ListAccountAliasesResponse; import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.iam.IamClient;

code

Region region = Region.AWS_GLOBAL; IamClient iam = IamClient.builder().region(region).build(); ListAccountAliasesResponse response = iam.listAccountAliases(); for (String alias : response.accountAliases()) { 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 IamClient's deleteAccountAlias method. When deleting an account alias, you must supply its name using a DeleteAccountAliasRequest object.

imports

import software.amazon.awssdk.services.iam.model.DeleteAccountAliasRequest; import software.amazon.awssdk.services.iam.model.DeleteAccountAliasResponse; import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.iam.IamClient;

Code

Region region = Region.AWS_GLOBAL; IamClient iam = IamClient.builder().region(region).build(); DeleteAccountAliasRequest request = DeleteAccountAliasRequest.builder() .accountAlias(alias).build(); DeleteAccountAliasResponse response = iam.deleteAccountAlias(request); System.out.println("Successfully deleted account alias " + alias);

See the complete example on GitHub.

More Information