I had the same issue when working with my Typescipt project on EC2.
Here is an answer that solved the issue for me:
https://github.com/microsoft/vscode-remote-release/issues/2692#issuecomment-852548425
If you are working on a typescript repo, I suggest trying the same:
Quoting the original answser:
I had the very same problem with VSCode connecting to my EC2 instance.
However, this wasn't the first time that I had VSCode running with an
EC2, and the other server that I had, was running smoothly. What was
the difference between my old server (that is actually still running)
and the new one? That in the old one, I was running an Apache server
with only PHP code, so basically, I was only using VSCode for setting
files and PHP.
I created a new server, started writing PHP again and everything was
going fine. The problem came when I started writing JS code in a
Node.js, and suddenly became very slow and began crashing, just with
the same symptoms described above.
So, it looks like VSCode has an extension built-in in a release called
"TypeScript and JavaScript Language Features" but you can find it
easily by looking at the extensions box and writing: "@Builtin
typescript". Find it and disable it and you'll be just fine.

However, it has downsides - mainly the coding experience would suck after you disabled the tool.
So Here is another way that is worth a shot:
According to https://github.com/microsoft/vscode-remote-release/issues/2692#issuecomment-901643826, VS Code Insider solved the issue.
So, try to download and use VS Code Insider: https://code.visualstudio.com/insiders/
UPDATE:
Nah, VS Code Insider did not work for me.
Disabling "TypeScript and JavaScript Language Features" definitely worked, at the cost of shitty coding experience.