In this study, Mg-doped CdS nanostructure was deposited onto anodic aluminum oxide (AAO) membrane substrate using sol-gel spin coating method. The AAO membrane was prepared by a two-step anodization process combined with pore widening process. The morphology, chemical composition, and structure of the spin- coated CdS nanostructure have been studied. The morphology of the fabricated AAO membrane and the deposited Mg-doped CdS nanostructure was investigated using scanning electron microscopy (SEM). The SEM of AAO illustrates a typical hexagonal and smooth nanoporous alumina membrane with interpore distance of ~ 100 nm, the pore diameter of ~ 60 nm. SEM of Mgdoped CdS shows porous nanostructured film of CdS nanoparticles. This film well adherents and covers the AAO substrate. The energy dispersive X-ray (EDX) pattern exhibits the signals of Al, O from AAO membrane and Mg, Cd, and S from the deposited CdS. This indicates the high purity of the fabricated membrane and the deposited Mg-doped CdS nanostructure. Using X-ray diffraction (XRD) pattern, Scherrer equation was used to calculate the average crystallite size. Additionally, the texture coefficients and density of dislocations were calculated. The fabricated CdS/AAO was applied to detect glucose of different concentrations. The proposed method has some advantages such as simple technology, low cost of processing, and high throughput. All of these factors facilitate the use of the prepared films in sensing applications.