AWS SDK for .NET
Developer Guide

Managing IAM Account Aliases

These .NET examples show you how to:

  • Create an account alias for your AWS account ID

  • List an account alias for your AWS account ID

  • Delete an account alias 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.

The following examples demonstrate how to manage your AWS account alias by using these methods of the AmazonIdentityManagementServiceClient class:

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

Create an Account Alias

Create an AmazonIdentityManagementServiceClient object. Next, create a CreateAccountAliasRequest object containing the new account alias you want to use. Call the CreateAccountAlias method of the AmazonIAMClient object. If the account alias is created, display the new alias on the console. If the name already exists, write the exception message to the console.

public static void CreateAccountAlias() { try { var iamClient = new AmazonIdentityManagementServiceClient(); var request = new CreateAccountAliasRequest(); request.AccountAlias = "my-aws-account-alias-2017"; var response = iamClient.CreateAccountAlias(request); if (response.HttpStatusCode.ToString() == "OK") Console.WriteLine(request.AccountAlias + " created."); else Console.WriteLine("HTTpStatusCode returned = " + response.HttpStatusCode.ToString()); } catch (Exception e) { Console.WriteLine(e.Message); } }

List Account Aliases

Create an AmazonIdentityManagementServiceClient object. Next, create a ListAccountAliasesRequest object. Call the ListAccountAliases method of the AmazonIAMClient object. If there is an account alias, display it on the console.

If there is no account alias, write the exception message to the console.

Note

There can be only one account alias.

public static void ListAccountAliases() { try { var iamClient = new AmazonIdentityManagementServiceClient(); var request = new ListAccountAliasesRequest(); var response = iamClient.ListAccountAliases(request); List<string> aliases = response.AccountAliases; foreach (string account in aliases) { Console.WriteLine("The account alias is: " + account); } } catch (Exception e) { Console.WriteLine(e.Message); } }

Delete an Account Alias

Create an AmazonIdentityManagementServiceClient object. Next, create a DeleteAccountAliasRequest object containing the account alias you want to delete. Call the DeleteAccountAlias method of the AmazonIAMClient object. If the account alias is deleted, display the delete information on the console. If the name doesn't exist, write the exception message to the console.

public static void DeleteAccountAlias() { try { var iamClient = new AmazonIdentityManagementServiceClient(); var request = new DeleteAccountAliasRequest(); request.AccountAlias = "my-aws-account-alias-2017"; var response = iamClient.DeleteAccountAlias(request); if (response.HttpStatusCode.ToString() == "OK") Console.WriteLine(request.AccountAlias + " deleted."); else Console.WriteLine("HTTpStatusCode returned = " + response.HttpStatusCode.ToString()); } catch (NoSuchEntityException e) { Console.WriteLine(e.Message); } }