AWS SDK for C++
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.

Note

These code snippets assume that you understand the material in Getting Started Using the AWS SDK for C++ and have configured default AWS credentials using the information in Providing AWS Credentials.

Creating an Account Alias

To create an account alias, call the IAMClient's CreateAccountAlias function with a CreateAccountAliasRequest object that contains the alias name.

Includes:

CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ #include <aws/core/Aws.h>

Code:

Aws::String alias_name(argv[1]); Aws::IAM::IAMClient iam; Aws::IAM::Model::CreateAccountAliasRequest request; request.SetAccountAlias(alias_name); auto outcome = iam.CreateAccountAlias(request); if (!outcome.IsSuccess()) { std::cout << "Error creating account alias " << alias_name << ": " << outcome.GetError().GetMessage() << std::endl; } else {

See the complete example.

Listing Account Aliases

To list your account's alias, if any, call the IAMClient's ListAccountAliases function. It takes a ListAccountAliasesRequest object.

Note

The returned ListAccountAliasesResult supports the same GetIsTruncated and GetMarker functions as other AWS SDK for C++list functions, but an AWS account can have only one account alias.

Includes:

CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ #include <aws/core/Aws.h> #include <aws/iam/IAMClient.h> #include <aws/iam/model/ListAccountAliasesRequest.h>

Code:

:SDKOptions options; :InitAPI(options); Aws::IAM::IAMClient iam; Aws::IAM::Model::ListAccountAliasesRequest request; bool done = false; bool header = false; while (!done) { auto outcome = iam.ListAccountAliases(request); if (!outcome.IsSuccess()) { std::cout << "Failed to list account aliases: " << outcome.GetError().GetMessage() << std::endl; break; } const auto &aliases = outcome.GetResult().GetAccountAliases(); if (!header) { if (aliases.size() == 0) { std::cout << "Account has no aliases" << std::endl; break; } std::cout << std::left << std::setw(32) << "Alias" << std::endl; header = true; } for (const auto &alias : aliases) { std::cout << std::left << std::setw(32) << alias << std::endl; } if (outcome.GetResult().GetIsTruncated()) { request.SetMarker(outcome.GetResult().GetMarker()); } else

see the complete example.

Deleting an account alias

To delete your account's alias, call the IAMClient's DeleteAccountAlias function. When deleting an account alias, you must supply its name using a DeleteAccountAliasRequest object.

Includes:

CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ #include <aws/core/Aws.h>

Code:

Aws::String alias_name(argv[1]); Aws::IAM::IAMClient iam; Aws::IAM::Model::DeleteAccountAliasRequest request; request.SetAccountAlias(alias_name); const auto outcome = iam.DeleteAccountAlias(request); if (!outcome.IsSuccess()) { std::cout << "Error deleting account alias " << alias_name << ": " << outcome.GetError().GetMessage() << std::endl; } else {

See the complete example.

More Information