Skip to content

EC2 Instance Connect Endpoint Stops Working after 2 hours

0

There is an issue is with my EC2 Instance Connect endpoint (not SSH). When the session times out after (default) 60 mins, I can refresh the page and reconnect. However, after the second timeout (around two hours), Instance Connect stops working entirely. At that point, I have to stop and start the instance to regain access. Simply rebooting the instance doesn’t resolve the issue. For context, the Winscp works without any issues while the instance connect fails to work. Also checking the CloudWatch metric didn't return any unusually high resource usage. So I'm basically stuck and unable to find a permanent fix or this issue. Hoping to get some help from more experienced folks.

Cheers, Sam

asked 9 months ago155 views
2 Answers
0

This issue with EC2 Instance Connect failing after approximately two hours could be caused by several factors:

  1. Security Group Configuration: The most common cause of EC2 Instance Connect failures is incorrect security group settings. Your security group needs to allow inbound SSH traffic (port 22) from the EC2 Instance Connect IP range for your specific region. Since WinSCP works but Instance Connect doesn't, this suggests the security group might be allowing your specific IP but not the EC2 Instance Connect IP ranges.

  2. EC2 Instance Connect Package: The EC2 Instance Connect package on your instance might be experiencing issues. This package is required for Instance Connect to function properly on supported Linux distributions.

  3. Network Settings: Verify that your instance is in a public subnet with an internet gateway attached, allowing for outbound traffic necessary for Instance Connect to function.

  4. IAM Permissions: Check that the IAM user or role you're using has the necessary permissions to use EC2 Instance Connect. These permissions might be timing out or encountering issues after extended periods.

  5. System Status: One of your EC2 status checks might be failing, which could indicate an underlying OS issue affecting connectivity.

To troubleshoot and resolve this issue:

  1. Update your security group to ensure it allows SSH traffic (TCP port 22) from the EC2 Instance Connect IP range for your region.

  2. Check the system logs in the EC2 console for any errors or issues that might be occurring around the time of the connection failures.

  3. Consider using AWS Systems Manager Session Manager as an alternative connection method if EC2 Instance Connect continues to fail.

  4. If you need to maintain longer sessions, you might need to adjust your session timeout settings or implement a solution that automatically refreshes the connection.

The fact that stopping and starting the instance resolves the issue (while rebooting doesn't) suggests that the problem might be related to the instance's networking configuration or the EC2 Instance Connect service itself, rather than just the operating system.
Sources
EC2 Instance Connect cannot connect to my instance ! | AWS re:Post
EC2: Cannot connect anymore via Instance Connect or SSH command line | AWS re:Post
EC2 instance failed to connet | AWS re:Post
Suddenly I can't connect to my ec2 server | AWS re:Post

answered 9 months ago
0

If this is an old instance, try upgrading the relevant packages.

sudo yum update ec2-instance-connect
sudo yum update amazon-ssm-agent

Also, to confirm, your AWS session has not ended right. That is, you are still connected to AWS? If your AWS session has ended, then connection could fail.

EXPERT
answered 9 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.