Your language correspond to the famous dangling else problem and it is well known that no $LL(k)$ grammar is able to parse it. The reason is that a $LL(k)$ grammar should be able to decide if a $a$ is paired with a $b$ when the $a$ is seen and the next $k$ symbols may be $a$.
Note that to make it $LR(1)$ you can't use a grammar like
$\qquad\begin{align}
S &\to aSb \\
&\to aS \\
&\to \varepsilon
\end{align}$
which is ambiguous. You have to use to
$\qquad\begin{align}
S &\to aS \\
&\to R \\
R &\to aRb \\
&\to \varepsilon
\end{align}$
But some parser generators like yacc are able to cope with that ambiguity, but the input has to be correctly ordered for them to work. Similarly, if you left factorize the first grammar, you get Raphael's grammar
$\qquad \begin{align}
S &\to aST \mid \varepsilon \\
T &\to b \mid \varepsilon
\end{align}$
which has an ambiguity which doesn't prevent to generate tables for LL(1) parsers.