Technological advancements in Information and Communication Technology (ICT) have transformed the computing paradigm, introducing various communication channels, with the Internet of Things (IoT) playing a crucial role. The Internet of Medical Things (IoMT) is a specialized category within IoT, enabling medical devices to communicate for sharing sensitive data, and improving patient care. However, these advancements also pose security and privacy challenges, including replay, man-in-the-middle, impersonation, and other attacks. To address these issues, machine learning algorithms are extensively employed in Intrusion Detection Systems (IDS) to dynamically detect and classify attacks at the network and host levels. Researchers have developed numerous supervised and unsupervised algorithms for reliable anomaly detection. The primary challenge lies in adapting IDS models to the dynamic and random behaviour of malicious attacks while designing scalable solutions. This paper explores the use of a Convolutional Neural Network (CNN) with Elephant Herding Optimization to create an effective IDS in the IoMT environment, aiming to classify and predict unforeseen cyberattacks. The CNN model undergoes pre-processing, optimization, and tuning of network parameters using hyperparameter selection methods. Experimental results, comparing the CNN with other machine learning algorithms on a benchmark intrusion detection dataset, demonstrate that the proposed model outperforms existing approaches. The CNN model exhibits a 17% increase in accuracy and a 35% decrease in time complexity, facilitating faster alerts to prevent post-effects of intrusion in sensitive cloud data storage.