There are more AWS SDK examples available in the AWS Doc SDK Examples
Delete an inline IAM policy from a user using an AWS SDK
The following code examples show how to delete an inline IAM policy from a user.
- Go
-
- SDK for Go V2
-
Note There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository
. // UserWrapper encapsulates AWS Identity and Access Management (IAM) user actions // used in the examples. // It contains an IAM service client that is used to perform user actions. type UserWrapper struct { IamClient *iam.Client } // DeleteUserPolicy deletes an inline policy from a user. func (wrapper UserWrapper) DeleteUserPolicy(userName string, policyName string) error { _, err := wrapper.IamClient.DeleteUserPolicy(context.TODO(), &iam.DeleteUserPolicyInput{ PolicyName: aws.String(policyName), UserName: aws.String(userName), }) if err != nil { log.Printf("Couldn't delete policy from user %v. Here's why: %v\n", userName, err) } return err }
-
For API details, see DeleteUserPolicy
in AWS SDK for Go API Reference.
-
- Ruby
-
- SDK for Ruby
-
Note There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository
. # Deletes a user. If the user has inline policies or access keys, they are deleted # before the user is deleted. # # @param user [Aws::IAM::User] The user to delete. def delete_user(user) user.policies.each do |policy| name = policy.name policy.delete puts("Deleted user policy #{name}.") end user.access_keys.each do |key| key.delete puts("Deleted access key for user #{user.name}.") end name = user.name user.delete puts("Deleted user #{name}.") rescue Aws::Errors::ServiceError => e puts("Couldn't detach policies and delete user #{user.name}. Here's why:") puts("\t#{e.code}: #{e.message}") end
-
For API details, see DeleteUserPolicy in AWS SDK for Ruby API Reference.
-
- Rust
-
- SDK for Rust
-
Note This documentation is for an SDK in preview release. The SDK is subject to change and should not be used in production.
Note There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository
. pub async fn delete_user_policy( client: &iamClient, user: &User, policy_name: &str, ) -> Result<(), SdkError<DeleteUserPolicyError>> { client .delete_user_policy() .user_name(user.user_name.as_ref().unwrap()) .policy_name(policy_name) .send() .await?; Ok(()) }
-
For API details, see DeleteUserPolicy
in AWS SDK for Rust API reference.
-
- Swift
-
- SDK for Swift
-
Note This is prerelease documentation for an SDK in preview release. It is subject to change.
Note There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository
. func deleteUserPolicy(user: IAMClientTypes.User, policyName: String) async throws { let input = DeleteUserPolicyInput( policyName: policyName, userName: user.userName ) do { _ = try await iamClient.deleteUserPolicy(input: input) } catch { throw error } }
-
For API details, see DeleteUserPolicy
in AWS SDK for Swift API reference.
-