On the least action principle in cosmology