Cloud computing is becoming an essential component in the emerging Internet of Things (IoT) paradigm. The available resources at the cloud such as computing nodes, storage, databases, etc. are often packaged in the form of virtual machines (VMs) to be used by remotely located IoT client applications for computational tasks. However, the cloud has a limited number of VMs available and hence, for massive IoT systems, the available resources must be efficiently utilized to increase productivity and subsequently maximize revenue of the cloud service provider (CSP). IoT client applications generate requests with computational tasks at random times with random complexity to be processed by the cloud. The CSP has to decide whether to allocate a VM to a task at hand or to wait for a higher complexity task in the future. We propose a threshold-based mechanism to optimally decide the allocation and pricing of VMs to sequentially arriving requests in order to maximize the revenue of the CSP over a finite time horizon. Moreover, we develop an adaptive and resilient framework that can counter the effect of realtime changes in the number of available VMs at the cloud server, the frequency and nature of arriving tasks on the revenue of the CSP.