Ejemplo n.º 1
0
        /// <summary>
        /// Deletes the User, Group, and AccessKey which were created for the purposes of
        /// this example.
        /// </summary>
        /// <param name="client">The IAM client used to delete the other
        /// resources.</param>
        /// <param name="userName">The name of the user that will be deleted.</param>
        /// <param name="groupName">The name of the group that will be deleted.</param>
        /// <param name="accessKeyId">The AccessKeyId that represents the
        /// AccessKey that was created for use with the ListBucketsAsync
        /// method.</param>
        public static async Task CleanUpResources(AmazonIdentityManagementServiceClient client, string userName, string groupName, string accessKeyId)
        {
            // Remove the user from the group.
            var removeUserRequest = new RemoveUserFromGroupRequest()
            {
                UserName  = userName,
                GroupName = groupName,
            };

            await client.RemoveUserFromGroupAsync(removeUserRequest);

            // Delete the client access keys before deleting the user.
            var deleteAccessKeyRequest = new DeleteAccessKeyRequest()
            {
                AccessKeyId = accessKeyId,
                UserName    = userName,
            };

            await client.DeleteAccessKeyAsync(deleteAccessKeyRequest);

            // Now we can safely delete the user.
            var deleteUserRequest = new DeleteUserRequest()
            {
                UserName = userName,
            };

            await client.DeleteUserAsync(deleteUserRequest);

            // We have to delete the policy attached to the group first.
            var deleteGroupPolicyRequest = new DeleteGroupPolicyRequest()
            {
                GroupName  = groupName,
                PolicyName = PolicyName,
            };

            await client.DeleteGroupPolicyAsync(deleteGroupPolicyRequest);

            // Now delete the group.
            var deleteGroupRequest = new DeleteGroupRequest()
            {
                GroupName = groupName,
            };

            await client.DeleteGroupAsync(deleteGroupRequest);

            Console.WriteLine("\n--------------------------------------------------------------------------------------------------------------");
            Console.WriteLine("Deleted the user and group created for this example.");
        }
 public Task <DeleteGroupPolicyResponse> DeleteGroupPolicyAsync(DeleteGroupPolicyRequest request,
                                                                CancellationToken cancellationToken = new CancellationToken())
 {
     throw new System.NotImplementedException();
 }