The UV bump is a broad absorption feature centred at 2175 A˚ that is seen in the attenuation/extinction curve of some galaxies, but its origin is not well known. Here, we use a sample of 86 star-forming galaxies at z = 1.7-2.7 with deep rest-frame UV spectroscopy from the MUSE HUDF Survey to study the connection between the strength of the observed UV 2175 A˚ bump and the Spitzer/MIPS 24 $\mu$m photometry, which at the redshift range of our sample probes mid-IR polycyclic aromatic hydrocarbon (PAH) emission at ∼6-8 μm. The sample has robust spectroscopic redshifts and consists of typical main-sequence galaxies with a wide range in stellar mass (log (M&z.ast;/M⊙ ) ∼8.5-10.7) and star formation rates (SFRs; SFR∼ 1-100 M⊙ yr-1). Galaxies with MIPS detections have strong UV bumps, except for those with mass-weighted ages younger than ∼150 Myr. We find that the UV bump amplitude does not change with SFR at fixed stellar mass but increases with mass at fixed SFR. The UV bump amplitude and the PAH strength (defined as mid-IR emission normalized by SFR) are highly correlated and both also correlate strongly with stellar mass. We interpret these correlations as the result of the mass-metallicity relationship, such that at low metallicities PAH emission is weak due to a lower abundance of PAH molecules. The weak or complete absence of the 2175 A˚ bump feature on top of the underlying smooth attenuation curve at low mass/metallicities is then expected if the PAH carriers are the main source of the additional UV absorption.