aws / aws-cli

Universal Command Line Interface for Amazon Web Services
Other
15.51k stars 4.12k forks source link

`aws ec2-instance-connect` times out too fast on MacOS #8802

Open augustfeng-vention opened 3 months ago

augustfeng-vention commented 3 months ago

Describe the bug

When I use the ec2-instance-connect command, the ssh connection disconnects after 5 second of inactivity.

Expected Behavior

I expect it to wait for a longer idle time before disconnectcing.

Current Behavior

The ssh connection times out after 5 seconds of inactivity.

Reproduction Steps

$ aws ec2-instance-connect ssh --instance-id <REDACTED> --connection-type eice
   ,     #_
   ~\_  ####_        Amazon Linux 2023
  ~~  \_#####\
  ~~     \###|
  ~~       \#/ ___   https://aws.amazon.com/linux/amazon-linux-2023
   ~~       V~' '->
    ~~~         /
      ~~._.   _/
         _/ _/
       _/m/'
Last login: Mon Jul 15 19:11:22 2024 from 10.0.2.10
[ec2-user@ip-10-80-195-10 ~]$ Timeout, server 10.80.195.10 not responding.

Possible Solution

There's a configuration for the ServerAliveInterval in ssh.py for 5 seconds.

My MacOS's /etc/ssh/ssh_config file contains the following configuration:

ServerAliveCountMax 0
ServerAliveInterval 900

The short ServerAliveInternal option from the AWS CLI doesn't work too well with MacOS's default ServerAliveCountMax 0.

Can we either remove it, or configure the ServerAliveCountMax alongside it?

Additional Information/Context

No response

CLI version used

aws-cli/2.17.13 Python/3.11.9 Darwin/23.5.0 exe/x86_64

Environment details (OS name and version, etc.)

Sonoma 14.5 (Apple M3 Pro)

tim-finnigan commented 3 months ago

Thanks for reaching out. Have you tried increasing your ServerAliveCountMax value to address this? I'll also share EC2 documentation on addressing connection timeout issues: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/TroubleshootingInstancesConnecting.html#TroubleshootingInstancesConnectionTimeout

The code you referenced is maintained by a customization owner on another team so I'll also reach out to them for feedback on this request.

augustfeng-vention commented 3 months ago

Np. I currently have this in my ~/.ssh/config file to make things work:

Host *
  ServerAliveCountMax 3