Have you tried looking at the Serial Console when your instance stops responding to SSH? That might show error messages or other indicators of what is happening. If not, you may be able to log into the instance and troubleshoot from there - for example, you might find it has run out of memory or there is a runaway process consuming all the CPU.
So this was tricky, but if you closed our AWS account at some point in the past, and then re-open the account, not all services are fully restored. Only a support ticket to AWS will enable them to fully "re-open" your account and unblock EC2. This is tricky issue as you can launch and even SSH in no prob for a while, but after some time (~7 to 8 mins) it'll kill your connection and freeze the machine. Long story short, to resolve this issue, open a ticket with AWS support.
SSH into EC2 stops accepting connections after about 8 minutesAccepted Answerasked 9 months ago
lightsail ssh "connecting to instance..." can't connected to my instance with sshasked 6 months ago
I am not able to ssh to EC2 instancesasked 5 months ago
Can't connect to EC2 instance via sshasked 6 days ago
trying to ssh into an ec2 instanceasked 5 months ago
Unable to connect to ec2 this morningasked 3 years ago
What is the difference between EC2 Instance Connect and Session Manager SSH connections?Accepted Answerasked 3 years ago
Contrast between file creation via EC2 Instance Connect & SSH Clientasked 9 months ago
i cannot connect my ec2 by sshasked a year ago
EC2 Instance Connect SSH source IPasked 2 months ago