The optimal control of epidemic-like stochastic processes is important both historically and for emerging applications today, where it can be especially critical to include time-varying parameters that impact viral epidemic-like propagation. We connect the control of such stochastic processes with time-varying behavior to the stochastic shortest path problem and obtain solutions for various cost functions. Then, under a mean-field scaling, this general class of stochastic processes is shown to converge to a corresponding dynamical system. We further establish that the optimal control of this class of processes converges to the optimal control of the limiting dynamical system. Our comparative study of the optimal control of both systems renders various important mathematical properties of interest.