2024-01-04 10:14:09 -05:00
# IAM code examples for the SDK for C++
2022-08-11 16:41:32 -04:00
## Overview
2022-10-20 15:00:56 -04:00
2024-01-04 10:14:09 -05:00
Shows how to use the AWS SDK for C++ to work with AWS Identity and Access Management (IAM).
2022-08-11 16:41:32 -04:00
2024-01-04 10:14:09 -05:00
<!--custom.overview.start-->
<!--custom.overview.end-->
2022-08-11 16:41:32 -04:00
2024-01-04 10:14:09 -05:00
_ IAM is a web service for securely controlling access to AWS services. With IAM, you can centrally manage permissions in your AWS account. _
2022-10-20 15:00:56 -04:00
2024-01-04 10:14:09 -05:00
## ⚠ Important
2024-01-09 12:33:12 -05:00
* Running this code might result in charges to your AWS account. For more details, see [AWS Pricing ](https://aws.amazon.com/pricing/ ) and [Free Tier ](https://aws.amazon.com/free/ ).
2022-08-11 16:41:32 -04:00
* Running the tests might result in charges to your AWS account.
2024-01-04 10:14:09 -05:00
* We recommend that you grant your code least privilege. At most, grant only the minimum permissions required to perform the task. For more information, see [Grant least privilege ](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html#grant-least-privilege ).
2022-08-11 16:41:32 -04:00
* This code is not tested in every AWS Region. For more information, see [AWS Regional Services ](https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services ).
2024-01-04 10:14:09 -05:00
<!--custom.important.start-->
<!--custom.important.end-->
2022-08-11 16:41:32 -04:00
## Code examples
2024-01-04 10:14:09 -05:00
### Prerequisites
Before using the code examples, first complete the installation and setup steps
for [Getting started ](https://docs.aws.amazon.com/sdk-for-cpp/v1/developer-guide/getting-started.html ) in the AWS SDK for
C++ Developer Guide.
This section covers how to get and build the SDK, and how to build your own code by using the SDK with a
sample Hello World-style application.
Next, for information on code example structures and how to build and run the examples, see [Getting started with the AWS SDK for C++ code examples ](https://docs.aws.amazon.com/sdk-for-cpp/v1/developer-guide/getting-started-code-examples.html ).
<!--custom.prerequisites.start-->
<!--custom.prerequisites.end-->
### Get started
- [Hello IAM ](hello_iam/CMakeLists.txt#L4 ) (`ListPolicies` )
2024-09-26 15:14:29 -04:00
### Basics
Code examples that show you how to perform the essential operations within a service.
- [Learn the basics ](iam_create_user_assume_role_scenario.cpp )
2022-08-11 16:41:32 -04:00
### Single actions
2022-10-20 15:00:56 -04:00
2024-01-04 10:14:09 -05:00
Code excerpts that show you how to call individual service functions.
2024-04-30 12:22:08 -07:00
- [AttachRolePolicy ](attach_role_policy.cpp#L38 )
- [CreateAccessKey ](create_access_key.cpp#L35 )
- [CreateAccountAlias ](create_account_alias.cpp#L35 )
2024-09-16 07:20:14 -04:00
- [CreatePolicy ](create_policy.cpp#L69 )
2024-04-30 12:22:08 -07:00
- [CreateRole ](create_role.cpp#L35 )
- [CreateUser ](create_user.cpp#L40 )
- [DeleteAccessKey ](delete_access_key.cpp#L35 )
- [DeleteAccountAlias ](delete_account_alias.cpp#L35 )
- [DeletePolicy ](delete_policy.cpp#L38 )
- [DeleteServerCertificate ](delete_server_certificate.cpp#L34 )
- [DeleteUser ](delete_user.cpp#L42 )
- [DetachRolePolicy ](detach_role_policy.cpp#L41 )
- [GetAccessKeyLastUsed ](access_key_last_used.cpp#L36 )
- [GetPolicy ](get_policy.cpp#L36 )
- [GetServerCertificate ](get_server_certificate.cpp#L36 )
- [ListAccessKeys ](list_access_keys.cpp#L37 )
- [ListAccountAliases ](list_account_aliases.cpp#L36 )
- [ListPolicies ](list_policies.cpp#L35 )
- [ListServerCertificates ](list_server_certificates.cpp#L35 )
- [ListUsers ](list_users.cpp#L34 )
- [PutRolePolicy ](put_role_policy.cpp#L35 )
- [UpdateAccessKey ](update_access_key.cpp#L40 )
- [UpdateServerCertificate ](update_server_certificate.cpp#L35 )
- [UpdateUser ](update_user.cpp#L37 )
2022-08-11 16:41:32 -04:00
2024-01-04 10:14:09 -05:00
<!--custom.examples.start-->
<!--custom.examples.end-->
2022-08-11 16:41:32 -04:00
2022-08-17 09:41:11 -04:00
## Run the examples
2022-10-20 15:00:56 -04:00
2024-01-04 10:14:09 -05:00
### Instructions
2024-02-08 15:35:59 -05:00
An executable is built for each source file in this folder. These executables are located in the build folder and have
2024-01-04 10:14:09 -05:00
"run_" prepended to the source file name, minus the suffix. See the "main" function in the source file for further instructions.
For example, to run the action in the source file "my_action.cpp", execute the following command from within the build folder. The command
will display any required arguments.
```
./run_my_action
```
2024-02-08 15:35:59 -05:00
If the source file is in a different folder, instructions can be found in the README in that
folder.
2024-01-04 10:14:09 -05:00
<!--custom.instructions.start-->
<!--custom.instructions.end-->
#### Hello IAM
This example shows you how to get started using IAM.
2024-09-26 15:14:29 -04:00
#### Learn the basics
2024-01-04 10:14:09 -05:00
This example shows you how to create a user and assume a role.
2022-08-11 16:41:32 -04:00
2024-01-04 10:14:09 -05:00
- Create a user with no permissions.
- Create a role that grants permission to list Amazon S3 buckets for the account.
- Add a policy to let the user assume the role.
- Assume the role and list S3 buckets using temporary credentials, then clean up resources.
2024-09-26 15:14:29 -04:00
<!--custom.basic_prereqs.iam_Scenario_CreateUserAssumeRole.start-->
<!--custom.basic_prereqs.iam_Scenario_CreateUserAssumeRole.end-->
2024-01-04 10:14:09 -05:00
2024-09-26 15:14:29 -04:00
<!--custom.basics.iam_Scenario_CreateUserAssumeRole.start-->
<!--custom.basics.iam_Scenario_CreateUserAssumeRole.end-->
2024-01-04 10:14:09 -05:00
### Tests
⚠ Running tests might result in charges to your AWS account.
2022-08-11 16:41:32 -04:00
2022-10-20 15:00:56 -04:00
2022-08-11 16:41:32 -04:00
``` sh
cd <BUILD_DIR>
cmake <path-to-root-of-this-source-code> -DBUILD_TESTS= ON
make
2024-01-04 10:14:09 -05:00
ctest
2022-10-20 15:00:56 -04:00
```
2022-08-11 16:41:32 -04:00
2024-01-04 10:14:09 -05:00
<!--custom.tests.start-->
<!--custom.tests.end-->
2022-08-11 16:41:32 -04:00
## Additional resources
2022-10-20 15:00:56 -04:00
2024-01-04 10:14:09 -05:00
- [IAM User Guide ](https://docs.aws.amazon.com/IAM/latest/UserGuide/introduction.html )
- [IAM API Reference ](https://docs.aws.amazon.com/IAM/latest/APIReference/welcome.html )
- [SDK for C++ IAM reference ](https://sdk.amazonaws.com/cpp/api/LATEST/aws-cpp-sdk-iam/html/annotated.html )
<!--custom.resources.start-->
<!--custom.resources.end-->
---
2022-08-11 16:41:32 -04:00
2024-01-04 10:14:09 -05:00
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2022-10-12 14:52:10 -04:00
2024-01-04 10:14:09 -05:00
SPDX-License-Identifier: Apache-2.0