Cloud computing is a massively distributed system in which existing resources interact with user-requested tasks to meet their requests. In such a system, the problem of optimizing Resource Allocation and Scheduling (RAS) is vital, because recourse allocation and scheduling deals with the mapping between recourses and user requests and also is responsible for optimal allocating of tasks to available resources. In the cloud environment, a user may face hundreds of computational resources to do his work. Therefore, manually recourse allocation and scheduling are impossible, and having a schedule between user requests and available recourses seems logical. In this paper, we used Whale Optimization Algorithm (WOA) to solve resource allocation and task scheduling problem in cloud computing to have optimal resource allocation and reduce the total runtime of requested services by users. The proposed algorithm is compared with the other existed algorithms. Results indicate the proper performance of the proposed algorithm than other ones.