In this paper, an electrochemical sensor was fabricated for the sensitive and simultaneous analysis of Pb(II) and Cd(II) by the modification of glassy carbon electrodes (GCEs) with a dispersion of l-cysteine-functionalized single-walled carbon nanotubes (SWCNs) incorporating Nafion and ionic liquid (IL) (SWCNs/l-cysteine/Nafion-IL/GCE). The SWCNs were functionalized by the covalent interaction between the −NH3 groups of l-cysteine and −COOH groups of pyrene carboxylic acid (PCA), and this interaction was activated by N-ethyl-N′(3-dimethylaminopropyl) carbodiimide hydrochloride (EDC) and N-hydroxysulfosuccinimide (NHS). The modification of PCA on the SWCNs was realized by noncovalent π–π stacking interactions between the PCA molecules and SWCNs. The prepared nanocomposite was characterized by square-wave anodic stripping voltammetry (SWASV), electrochemical impedance spectroscopy (EIS), scanning electron microscopy (SEM) and cyclic voltammetry (CV). By combining the outstanding adsorption capacity of l-cysteine and Nafion toward Pb(II) and Cd(II) with the advantages of SWCNs and ILs, the modified SWCNs/l-cysteine/Nafion-IL/GCE composite showed excellent detection performance, including good stability, high sensitivity and selectivity. Under the optimal conditions, the concentration of target heavy metals (HMs) was significantly linear with corresponding stripping currents for Pb(II) and Cd(II) in the concentration range of 0–50 μg L−1. The limits of detection for Cd(II) and Pb(II) were 0.05 μg L−1 and 0.08 μg L−1, respectively. Finally, SWCNs/l-cysteine/Nafion-IL/GCEs were successfully applied in the determination of Pb(II) and Cd(II) in real samples, and the results were compared with those of an atomic absorption spectrometry (AAS) analysis.