Let's start from the equation of motion
\begin{equation}\tag{1}
m\frac{d^2x}{dt^2} = -kx
\end{equation}
and introduce the constant
\begin{equation}\tag{2}
\omega^2 = \frac{k}{m}
\end{equation}
so that equation (1) becomes
\begin{equation}\tag{3}
\frac{d^2x}{dt^2} = -\omega^2 x.
\end{equation}
This is a second order linear differential equation with constant coefficients and one way to solve it is by letting $x = e^{\lambda t}$ where $\lambda$ is another constant. Substituting this form in (3) we get
\begin{equation}\tag{4}
(\lambda^2 + \omega^2)e^{\lambda t} = 0.
\end{equation}
Since $e^{\lambda t} \ne 0$, we have $\lambda = \pm i\omega$ and the general solution of (3) is
\begin{equation}\tag{5}
x(t) = A_1 e^{i\omega t} + A_2e^{-i\omega t},
\end{equation}
where $A_1$ and $A_2$ are constant of integration to be determined from the initial conditions. If, for example, $x(0) = A$ and $\dot{x}(0) = 0$ then we have
\begin{eqnarray}
A &=& A_1 + A_2 \\
0 &=& i\omega(A_1 - A_2).
\end{eqnarray}
The solution of these equations is $A_1 = A/2, A_2 = A/2$. Therefore, for this choice of initial conditions, equation (5) becomes,
\begin{equation}\tag{6}
x(t) = \frac{A}{2}\left(e^{i\omega t} + e^{-i\omega t}\right) = A\cos(\omega t).
\end{equation}
The number $A$ is called the amplitude of the oscillator.