We compute the supersymmetric partition function of N = 1 supersymmetric gauge theories with an R-symmetry on M 4 ∼ = M g,p × S 1 , a principal elliptic fiber bundle of degree p over a genus-g Riemann surface, Σ g . Equivalently, we compute the generalized supersymmetric index I Mg,p , with the supersymmetric three-manifold M g,p as the spatial slice. The ordinary N = 1 supersymmetric index on the round three-sphere is recovered as a special case. We approach this computation from the point of view of a topological A-model for the abelianized gauge fields on the base Σ g . This A-model -or A-twisted twodimensional N = (2, 2) gauge theory -encodes all the information about the generalized indices, which are viewed as expectations values of some canonically-defined surface defects wrapped on T 2 inside Σ g × T 2 . Being defined by compactification on the torus, the Amodel also enjoys natural modular properties, governed by the four-dimensional 't Hooft anomalies. As an application of our results, we provide new tests of Seiberg duality. We also present a new evaluation formula for the three-sphere index as a sum over twodimensional vacua.