We show that the Dirac operator on a compact globally hyperbolic Lorentzian spacetime with spacelike Cauchy boundary is a Fredholm operator if appropriate boundary conditions are imposed. We prove that the index of this operator is given by the same expression as in the index formula of Atiyah-Patodi-Singer for Riemannian manifolds with boundary. The index is also shown to equal that of a certain operator constructed from the evolution operator and a spectral projection on the boundary. In case the metric is of product type near the boundary a Feynman parametrix is constructed.