Amazon.IdentityManagement.AmazonIdentityManagementServiceClient.DeleteRole C# (CSharp) Method

DeleteRole() public method

Deletes the specified role. The role must not have any policies attached. For more information about roles, go to Working with Roles.

Make sure you do not have any Amazon EC2 instances running with the role you are about to delete. Deleting a role or instance profile that is associated with a running instance will break any applications running on the instance.

/// The request was rejected because it attempted to delete a resource that has attached /// subordinate entities. The error message describes these entities. /// /// The request was rejected because it attempted to create resources beyond the current /// AWS account limits. The error message describes the limit exceeded. /// /// The request was rejected because it referenced an entity that does not exist. The /// error message describes the entity. /// /// The request processing has failed because of an unknown error, exception or failure. ///
public DeleteRole ( DeleteRoleRequest request ) : Amazon.IdentityManagement.Model.DeleteRoleResponse
request Amazon.IdentityManagement.Model.DeleteRoleRequest Container for the necessary parameters to execute the DeleteRole service method.
return Amazon.IdentityManagement.Model.DeleteRoleResponse
        public DeleteRoleResponse DeleteRole(DeleteRoleRequest request)
        {
            var marshaller = new DeleteRoleRequestMarshaller();
            var unmarshaller = DeleteRoleResponseUnmarshaller.Instance;

            return Invoke<DeleteRoleRequest,DeleteRoleResponse>(request, marshaller, unmarshaller);
        }

Usage Example

        public virtual void PrepMode_RemoveRoles(AmazonIdentityManagementServiceClient iamClient, params string[] roles)
        {
            foreach (var roleName in roles)
            {
                try
                {
                    iamClient.GetRole(new GetRoleRequest {RoleName = roleName});
                    Console.WriteLine("Removing old role {0}.", roleName);
                    // Remove existing policies
                    var listRolePoliciesResponse =
                        iamClient.ListRolePolicies(new ListRolePoliciesRequest {RoleName = roleName});
                    foreach (var policyName in listRolePoliciesResponse.PolicyNames)
                    {
                        var deleteRolePolicyRequest = new DeleteRolePolicyRequest
                        {
                            PolicyName = policyName,
                            RoleName = roleName
                        };
                        iamClient.DeleteRolePolicy(deleteRolePolicyRequest);
                    }
                    iamClient.DeleteRole(new DeleteRoleRequest {RoleName = roleName});
                }
                catch (NoSuchEntityException)
                {

                    // Role doesn't exist, so don't do anything.
                    // Gobble the exception and loop.
                    break;
                }
            }
        }
All Usage Examples Of Amazon.IdentityManagement.AmazonIdentityManagementServiceClient::DeleteRole
AmazonIdentityManagementServiceClient