Background. There is evidence that the immune system plays a key critical role in the pathogenesis of myocardial infarction (MI). However, the exact mechanisms associated with immunity have not been systematically uncovered. Methods. This study used the weighted gene coexpression network analysis (WGCNA) and the CIBERSORT algorithm to analyze the MI expression data from the Gene Expression Omnibus database and then identify the module associated with immune cell infiltration. In addition, we built the coexpression network and protein-protein interactions network analysis to identify the hub genes. Furthermore, the relationship between hub genes and NK cell resting was validated by using another dataset GSE123342. Finally, receiver operating characteristic (ROC) curve analyses were used to assess the diagnostic value of verified hub genes. Results. Monocytes and neutrophils were markedly increased, and T cell CD8, T cell CD4 naive, T cell CD4 memory resting, and NK cell resting were significantly decreased in MI groups compared with stable coronary artery disease (CAD) groups. The WGCNA results showed that the pink model had the highest correlation with the NK cell resting infiltration level. We identified 11 hub genes whose expression correlated to the NK cell resting infiltration level, among which, 7 hub genes (NKG7, TBX21, PRF1, CD247, KLRD1, FASLG, and EOMES) were successfully validated in GSE123342. And these 7 genes had diagnostic value to distinguish MI and stable CAD. Conclusions. NKG7, TBX21, PRF1, CD247, KLRD1, FASLG, and EOMES may be a diagnostic biomarker and therapeutic target associated with NK cell resting infiltration in MI.