IAM examples using SDK for SAP ABAP - AWS SDK Code Examples

There are more AWS SDK examples available in the AWS Doc SDK Examples GitHub repo.

IAM examples using SDK for SAP ABAP

The following code examples show you how to perform actions and implement common scenarios by using the AWS SDK for SAP ABAP with IAM.

Actions are code excerpts from larger programs and must be run in context. While actions show you how to call individual service functions, you can see actions in context in their related scenarios.

Each example includes a link to the complete source code, where you can find instructions on how to set up and run the code in context.

Topics

Actions

The following code example shows how to use AttachRolePolicy.

SDK for SAP ABAP
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

TRY. lo_iam->attachrolepolicy( iv_rolename = iv_role_name iv_policyarn = iv_policy_arn ). MESSAGE 'Policy attached to role successfully.' TYPE 'I'. CATCH /aws1/cx_iamnosuchentityex. MESSAGE 'Role or policy does not exist.' TYPE 'E'. CATCH /aws1/cx_iamlimitexceededex. MESSAGE 'Policy attachment limit exceeded.' TYPE 'E'. ENDTRY.

The following code example shows how to use AttachUserPolicy.

SDK for SAP ABAP
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

TRY. lo_iam->attachuserpolicy( iv_username = iv_user_name iv_policyarn = iv_policy_arn ). MESSAGE 'Policy attached to user successfully.' TYPE 'I'. CATCH /aws1/cx_iamnosuchentityex. MESSAGE 'User or policy does not exist.' TYPE 'E'. CATCH /aws1/cx_iamlimitexceededex. MESSAGE 'Policy attachment limit exceeded.' TYPE 'E'. ENDTRY.

The following code example shows how to use CreateAccessKey.

SDK for SAP ABAP
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

TRY. oo_result = lo_iam->createaccesskey( iv_username = iv_user_name ). MESSAGE 'Access key created successfully.' TYPE 'I'. CATCH /aws1/cx_iamnosuchentityex. MESSAGE 'User does not exist.' TYPE 'E'. CATCH /aws1/cx_iamlimitexceededex. MESSAGE 'Maximum number of access keys reached.' TYPE 'E'. ENDTRY.
  • For API details, see CreateAccessKey in AWS SDK for SAP ABAP API reference.

The following code example shows how to use CreateAccountAlias.

SDK for SAP ABAP
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

TRY. lo_iam->createaccountalias( iv_accountalias = iv_account_alias ). MESSAGE 'Account alias created successfully.' TYPE 'I'. CATCH /aws1/cx_iamentityalrdyexex. MESSAGE 'Account alias already exists.' TYPE 'E'. CATCH /aws1/cx_iamlimitexceededex. MESSAGE 'Account alias limit exceeded.' TYPE 'E'. ENDTRY.

The following code example shows how to use CreatePolicy.

SDK for SAP ABAP
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

TRY. oo_result = lo_iam->createpolicy( iv_policyname = iv_policy_name iv_policydocument = iv_policy_document iv_description = iv_description ). MESSAGE 'Policy created successfully.' TYPE 'I'. CATCH /aws1/cx_iamentityalrdyexex. MESSAGE 'Policy already exists.' TYPE 'E'. CATCH /aws1/cx_iammalformedplydocex. MESSAGE 'Policy document is malformed.' TYPE 'E'. CATCH /aws1/cx_iamlimitexceededex. MESSAGE 'Policy limit exceeded.' TYPE 'E'. ENDTRY.
  • For API details, see CreatePolicy in AWS SDK for SAP ABAP API reference.

The following code example shows how to use CreatePolicyVersion.

SDK for SAP ABAP
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

TRY. oo_result = lo_iam->createpolicyversion( iv_policyarn = iv_policy_arn iv_policydocument = iv_policy_document iv_setasdefault = iv_set_as_default ). MESSAGE 'Policy version created successfully.' TYPE 'I'. CATCH /aws1/cx_iamnosuchentityex. MESSAGE 'Policy does not exist.' TYPE 'E'. CATCH /aws1/cx_iammalformedplydocex. MESSAGE 'Policy document is malformed.' TYPE 'E'. CATCH /aws1/cx_iamlimitexceededex. MESSAGE 'Policy version limit exceeded.' TYPE 'E'. ENDTRY.

The following code example shows how to use CreateRole.

SDK for SAP ABAP
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

TRY. oo_result = lo_iam->createrole( iv_rolename = iv_role_name iv_assumerolepolicydocument = iv_assume_role_policy_document ). MESSAGE 'Role created successfully.' TYPE 'I'. CATCH /aws1/cx_iamentityalrdyexex. MESSAGE 'Role already exists.' TYPE 'E'. CATCH /aws1/cx_iammalformedplydocex. MESSAGE 'Assume role policy document is malformed.' TYPE 'E'. CATCH /aws1/cx_iamlimitexceededex. MESSAGE 'Role limit exceeded.' TYPE 'E'. ENDTRY.
  • For API details, see CreateRole in AWS SDK for SAP ABAP API reference.

The following code example shows how to use CreateServiceLinkedRole.

SDK for SAP ABAP
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

TRY. oo_result = lo_iam->listpolicyversions( iv_policyarn = iv_policy_arn ). MESSAGE 'Retrieved policy versions list.' TYPE 'I'. CATCH /aws1/cx_iamnosuchentityex. MESSAGE 'Policy does not exist.' TYPE 'E'. CATCH /aws1/cx_iamservicefailureex. MESSAGE 'Service failure when listing policy versions.' TYPE 'E'. ENDTRY.

The following code example shows how to use CreateUser.

SDK for SAP ABAP
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

TRY. oo_result = lo_iam->createuser( iv_username = iv_user_name ). MESSAGE 'User created successfully.' TYPE 'I'. CATCH /aws1/cx_iamentityalrdyexex. MESSAGE 'User already exists.' TYPE 'E'. CATCH /aws1/cx_iamlimitexceededex. MESSAGE 'Limit exceeded for IAM users.' TYPE 'E'. CATCH /aws1/cx_iamnosuchentityex. MESSAGE 'Entity does not exist.' TYPE 'E'. ENDTRY.
  • For API details, see CreateUser in AWS SDK for SAP ABAP API reference.

The following code example shows how to use DeleteAccessKey.

SDK for SAP ABAP
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

TRY. lo_iam->deleteaccesskey( iv_accesskeyid = iv_access_key_id iv_username = iv_user_name ). MESSAGE 'Access key deleted successfully.' TYPE 'I'. CATCH /aws1/cx_iamnosuchentityex. MESSAGE 'Access key or user does not exist.' TYPE 'E'. ENDTRY.
  • For API details, see DeleteAccessKey in AWS SDK for SAP ABAP API reference.

The following code example shows how to use DeleteAccountAlias.

SDK for SAP ABAP
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

TRY. lo_iam->deleteaccountalias( iv_accountalias = iv_account_alias ). MESSAGE 'Account alias deleted successfully.' TYPE 'I'. CATCH /aws1/cx_iamnosuchentityex. MESSAGE 'Account alias does not exist.' TYPE 'E'. ENDTRY.

The following code example shows how to use DeletePolicy.

SDK for SAP ABAP
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

TRY. lo_iam->deletepolicy( iv_policyarn = iv_policy_arn ). MESSAGE 'Policy deleted successfully.' TYPE 'I'. CATCH /aws1/cx_iamnosuchentityex. MESSAGE 'Policy does not exist.' TYPE 'E'. CATCH /aws1/cx_iamdeleteconflictex. MESSAGE 'Policy cannot be deleted due to attachments.' TYPE 'E'. ENDTRY.
  • For API details, see DeletePolicy in AWS SDK for SAP ABAP API reference.

The following code example shows how to use DeletePolicyVersion.

SDK for SAP ABAP
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

TRY. lo_iam->deletepolicyversion( iv_policyarn = iv_policy_arn iv_versionid = iv_version_id ). MESSAGE 'Policy version deleted successfully.' TYPE 'I'. CATCH /aws1/cx_iamnosuchentityex. MESSAGE 'Policy or version does not exist.' TYPE 'E'. CATCH /aws1/cx_iamdeleteconflictex. MESSAGE 'Cannot delete default policy version.' TYPE 'E'. CATCH /aws1/cx_iamlimitexceededex. MESSAGE 'Limit exceeded.' TYPE 'E'. ENDTRY.

The following code example shows how to use DeleteRole.

SDK for SAP ABAP
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

TRY. lo_iam->deleterole( iv_rolename = iv_role_name ). MESSAGE 'Role deleted successfully.' TYPE 'I'. CATCH /aws1/cx_iamnosuchentityex. MESSAGE 'Role does not exist.' TYPE 'E'. CATCH /aws1/cx_iamdeleteconflictex. MESSAGE 'Role cannot be deleted due to attached resources.' TYPE 'E'. ENDTRY.
  • For API details, see DeleteRole in AWS SDK for SAP ABAP API reference.

The following code example shows how to use DeleteUser.

SDK for SAP ABAP
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

TRY. lo_iam->deleteuser( iv_username = iv_user_name ). MESSAGE 'User deleted successfully.' TYPE 'I'. CATCH /aws1/cx_iamnosuchentityex. MESSAGE 'User does not exist.' TYPE 'E'. CATCH /aws1/cx_iamdeleteconflictex. MESSAGE 'User cannot be deleted due to attached resources.' TYPE 'E'. ENDTRY.
  • For API details, see DeleteUser in AWS SDK for SAP ABAP API reference.

The following code example shows how to use DetachRolePolicy.

SDK for SAP ABAP
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

TRY. lo_iam->detachrolepolicy( iv_rolename = iv_role_name iv_policyarn = iv_policy_arn ). MESSAGE 'Policy detached from role successfully.' TYPE 'I'. CATCH /aws1/cx_iamnosuchentityex. MESSAGE 'Role or policy does not exist.' TYPE 'E'. ENDTRY.

The following code example shows how to use DetachUserPolicy.

SDK for SAP ABAP
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

TRY. lo_iam->detachuserpolicy( iv_username = iv_user_name iv_policyarn = iv_policy_arn ). MESSAGE 'Policy detached from user successfully.' TYPE 'I'. CATCH /aws1/cx_iamnosuchentityex. MESSAGE 'User or policy does not exist.' TYPE 'E'. ENDTRY.

The following code example shows how to use GenerateCredentialReport.

SDK for SAP ABAP
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

TRY. oo_result = lo_iam->generatecredentialreport( ). MESSAGE 'Credential report generation started.' TYPE 'I'. CATCH /aws1/cx_iamlimitexceededex. MESSAGE 'Report generation limit exceeded.' TYPE 'E'. CATCH /aws1/cx_iamservicefailureex. MESSAGE 'Service failure when generating credential report.' TYPE 'E'. ENDTRY.

The following code example shows how to use GetAccessKeyLastUsed.

SDK for SAP ABAP
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

TRY. oo_result = lo_iam->getaccesskeylastused( iv_accesskeyid = iv_access_key_id ). MESSAGE 'Retrieved access key last used information.' TYPE 'I'. CATCH /aws1/cx_iamnosuchentityex. MESSAGE 'Access key does not exist.' TYPE 'E'. ENDTRY.

The following code example shows how to use GetAccountAuthorizationDetails.

SDK for SAP ABAP
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

TRY. oo_result = lo_iam->getaccountauthdetails( ). MESSAGE 'Retrieved account authorization details.' TYPE 'I'. CATCH /aws1/cx_iamservicefailureex. MESSAGE 'Service failure when getting account authorization details.' TYPE 'E'. ENDTRY.

The following code example shows how to use GetAccountPasswordPolicy.

SDK for SAP ABAP
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

TRY. oo_result = lo_iam->getaccountpasswordpolicy( ). MESSAGE 'Retrieved account password policy.' TYPE 'I'. CATCH /aws1/cx_iamnosuchentityex. MESSAGE 'No password policy exists.' TYPE 'I'. CATCH /aws1/cx_iamservicefailureex. MESSAGE 'Service failure when getting password policy.' TYPE 'E'. ENDTRY.

The following code example shows how to use GetAccountSummary.

SDK for SAP ABAP
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

TRY. oo_result = lo_iam->getaccountsummary( ). MESSAGE 'Retrieved account summary.' TYPE 'I'. CATCH /aws1/cx_iamservicefailureex. MESSAGE 'Service failure when getting account summary.' TYPE 'E'. ENDTRY.

The following code example shows how to use GetCredentialReport.

SDK for SAP ABAP
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

TRY. oo_result = lo_iam->getcredentialreport( ). MESSAGE 'Retrieved credential report.' TYPE 'I'. CATCH /aws1/cx_iamcredrptnotpresen00. MESSAGE 'Credential report not present.' TYPE 'E'. CATCH /aws1/cx_iamcredrptexpiredex. MESSAGE 'Credential report expired.' TYPE 'E'. CATCH /aws1/cx_iamcredrptnotreadyex. MESSAGE 'Credential report not ready.' TYPE 'E'. CATCH /aws1/cx_iamservicefailureex. MESSAGE 'Service failure when getting credential report.' TYPE 'E'. ENDTRY.

The following code example shows how to use GetPolicy.

SDK for SAP ABAP
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

TRY. oo_result = lo_iam->getpolicy( iv_policyarn = iv_policy_arn ). MESSAGE 'Retrieved policy information.' TYPE 'I'. CATCH /aws1/cx_iamnosuchentityex. MESSAGE 'Policy does not exist.' TYPE 'E'. ENDTRY.
  • For API details, see GetPolicy in AWS SDK for SAP ABAP API reference.

The following code example shows how to use GetRole.

SDK for SAP ABAP
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

TRY. oo_result = lo_iam->getrole( iv_rolename = iv_role_name ). MESSAGE 'Retrieved role information.' TYPE 'I'. CATCH /aws1/cx_iamnosuchentityex. MESSAGE 'Role does not exist.' TYPE 'E'. ENDTRY.
  • For API details, see GetRole in AWS SDK for SAP ABAP API reference.

The following code example shows how to use ListAccessKeys.

SDK for SAP ABAP
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

TRY. oo_result = lo_iam->listaccesskeys( iv_username = iv_user_name ). MESSAGE 'Retrieved access key list.' TYPE 'I'. CATCH /aws1/cx_iamnosuchentityex. MESSAGE 'User does not exist.' TYPE 'E'. ENDTRY.
  • For API details, see ListAccessKeys in AWS SDK for SAP ABAP API reference.

The following code example shows how to use ListAccountAliases.

SDK for SAP ABAP
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

TRY. oo_result = lo_iam->listaccountaliases( ). MESSAGE 'Retrieved account alias list.' TYPE 'I'. CATCH /aws1/cx_iamservicefailureex. MESSAGE 'Service failure when listing account aliases.' TYPE 'E'. ENDTRY.

The following code example shows how to use ListAttachedRolePolicies.

SDK for SAP ABAP
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

TRY. oo_result = lo_iam->listattachedrolepolicies( iv_rolename = iv_role_name ). MESSAGE 'Retrieved attached policy list for role.' TYPE 'I'. CATCH /aws1/cx_iamnosuchentityex. MESSAGE 'Role does not exist.' TYPE 'E'. ENDTRY.

The following code example shows how to use ListGroups.

SDK for SAP ABAP
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

TRY. oo_result = lo_iam->listgroups( ). MESSAGE 'Retrieved group list.' TYPE 'I'. CATCH /aws1/cx_iamservicefailureex. MESSAGE 'Service failure when listing groups.' TYPE 'E'. ENDTRY.
  • For API details, see ListGroups in AWS SDK for SAP ABAP API reference.

The following code example shows how to use ListPolicies.

SDK for SAP ABAP
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

TRY. oo_result = lo_iam->listpolicies( iv_scope = iv_scope ). MESSAGE 'Retrieved policy list.' TYPE 'I'. CATCH /aws1/cx_iamservicefailureex. MESSAGE 'Service failure when listing policies.' TYPE 'E'. ENDTRY.
  • For API details, see ListPolicies in AWS SDK for SAP ABAP API reference.

The following code example shows how to use ListPolicyVersions.

SDK for SAP ABAP
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

TRY. oo_result = lo_iam->listpolicyversions( iv_policyarn = iv_policy_arn ). MESSAGE 'Retrieved policy versions list.' TYPE 'I'. CATCH /aws1/cx_iamnosuchentityex. MESSAGE 'Policy does not exist.' TYPE 'E'. CATCH /aws1/cx_iamservicefailureex. MESSAGE 'Service failure when listing policy versions.' TYPE 'E'. ENDTRY.

The following code example shows how to use ListRolePolicies.

SDK for SAP ABAP
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

TRY. oo_result = lo_iam->listrolepolicies( iv_rolename = iv_role_name ). MESSAGE 'Retrieved inline policy list for role.' TYPE 'I'. CATCH /aws1/cx_iamnosuchentityex. MESSAGE 'Role does not exist.' TYPE 'E'. ENDTRY.

The following code example shows how to use ListRoles.

SDK for SAP ABAP
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

TRY. oo_result = lo_iam->listroles( ). MESSAGE 'Retrieved role list.' TYPE 'I'. CATCH /aws1/cx_iamservicefailureex. MESSAGE 'Service failure when listing roles.' TYPE 'E'. ENDTRY.
  • For API details, see ListRoles in AWS SDK for SAP ABAP API reference.

The following code example shows how to use ListSAMLProviders.

SDK for SAP ABAP
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

TRY. oo_result = lo_iam->listsamlproviders( ). MESSAGE 'Retrieved SAML provider list.' TYPE 'I'. CATCH /aws1/cx_iamservicefailureex. MESSAGE 'Service failure when listing SAML providers.' TYPE 'E'. ENDTRY.

The following code example shows how to use ListUsers.

SDK for SAP ABAP
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

TRY. oo_result = lo_iam->listusers( ). MESSAGE 'Retrieved user list.' TYPE 'I'. CATCH /aws1/cx_iamservicefailureex. MESSAGE 'Service failure when listing users.' TYPE 'E'. ENDTRY.
  • For API details, see ListUsers in AWS SDK for SAP ABAP API reference.

The following code example shows how to use SetDefaultPolicyVersion.

SDK for SAP ABAP
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

TRY. lo_iam->setdefaultpolicyversion( iv_policyarn = iv_policy_arn iv_versionid = iv_version_id ). MESSAGE 'Default policy version set successfully.' TYPE 'I'. CATCH /aws1/cx_iamnosuchentityex. MESSAGE 'Policy or version does not exist.' TYPE 'E'. CATCH /aws1/cx_iaminvalidinputex. MESSAGE 'Invalid input provided.' TYPE 'E'. CATCH /aws1/cx_iamlimitexceededex. MESSAGE 'Limit exceeded.' TYPE 'E'. ENDTRY.

The following code example shows how to use UpdateAccessKey.

SDK for SAP ABAP
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

TRY. lo_iam->updateaccesskey( iv_accesskeyid = iv_access_key_id iv_status = iv_status iv_username = iv_user_name ). MESSAGE 'Access key updated successfully.' TYPE 'I'. CATCH /aws1/cx_iamnosuchentityex. MESSAGE 'Access key or user does not exist.' TYPE 'E'. ENDTRY.
  • For API details, see UpdateAccessKey in AWS SDK for SAP ABAP API reference.

The following code example shows how to use UpdateUser.

SDK for SAP ABAP
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

TRY. lo_iam->updateuser( iv_username = iv_user_name iv_newusername = iv_new_user_name ). MESSAGE 'User updated successfully.' TYPE 'I'. CATCH /aws1/cx_iamnosuchentityex. MESSAGE 'User does not exist.' TYPE 'E'. CATCH /aws1/cx_iamentityalrdyexex. MESSAGE 'New user name already exists.' TYPE 'E'. ENDTRY.
  • For API details, see UpdateUser in AWS SDK for SAP ABAP API reference.