Since your build appears to start normally, becomes unresponsive midway through the process and restarting the instance restores connectivity, there is most likely a resource exhaustion issue that happens during the build. Try increasing the size of the disk attached to your instance and increasing the allocated RAM and the number of vCPUs you are using.