Delete an IAM service-linked role using an Amazon SDK
The following code examples show how to delete an IAM service-linked role.
- 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 Amazon Code Examples Repository
. // RoleWrapper encapsulates AWS Identity and Access Management (IAM) role actions // used in the examples. // It contains an IAM service client that is used to perform role actions. type RoleWrapper struct { IamClient *iam.Client } // DeleteServiceLinkedRole deletes a service-linked role. func (wrapper RoleWrapper) DeleteServiceLinkedRole(roleName string) error { _, err := wrapper.IamClient.DeleteServiceLinkedRole(context.TODO(), &iam.DeleteServiceLinkedRoleInput{ RoleName: aws.String(roleName)}, ) if err != nil { log.Printf("Couldn't delete service-linked role %v. Here's why: %v\n", roleName, err) } return err }
-
For API details, see DeleteServiceLinkedRole
in Amazon SDK for Go API Reference.
-
- JavaScript
-
- SDK for JavaScript (v3)
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the Amazon Code Examples Repository
. import { DeleteServiceLinkedRoleCommand, IAMClient } from "@aws-sdk/client-iam"; const client = new IAMClient({}); /** * * @param {string} roleName */ export const deleteServiceLinkedRole = (roleName) => { const command = new DeleteServiceLinkedRoleCommand({ RoleName: roleName }); return client.send(command); };
-
For API details, see DeleteServiceLinkedRole in Amazon SDK for JavaScript 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 Amazon Code Examples Repository
. # Deletes a service-linked role from the account. # # @param role [Aws::IAM::Role] The role to delete. def delete_service_linked_role(role) response = @iam_resource.client.delete_service_linked_role(role_name: role.name) task_id = response.deletion_task_id while true response = @iam_resource.client.get_service_linked_role_deletion_status( deletion_task_id: task_id) status = response.status puts("Deletion of #{role.name} #{status}.") if %w(SUCCEEDED FAILED).include?(status) break else sleep(3) end end rescue Aws::Errors::ServiceError => e # If AWS has not yet fully propagated the role, it deletes the role but # returns NoSuchEntity. if e.code != "NoSuchEntity" puts("Couldn't delete #{role.name}. Here's why:") puts("\t#{e.code}: #{e.message}") raise end end
-
For API details, see DeleteServiceLinkedRole in Amazon 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 Amazon Code Examples Repository
. pub async fn delete_service_linked_role( client: &iamClient, role_name: &str, ) -> Result<(), iamError> { client .delete_service_linked_role() .role_name(role_name) .send() .await?; Ok(()) }
-
For API details, see DeleteServiceLinkedRole
in Amazon SDK for Rust API reference.
-
For a complete list of Amazon SDK developer guides and code examples, see Using IAM with an Amazon SDK. This topic also includes information about getting started and details about previous SDK versions.