AWS CloudShell で「Connection is lost」が繰り返し発生するときの対処方法

2022.04.05

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

困っていた内容

AWS CLI の実行環境として AWS CloudShell を利用していますが、開始から数分経つとセッションが切断された旨のメッセージが表示されます。操作を行うと再使用はできますが、なぜこのような事象が発生するのでしょうか。

Connection is lost. Please refresh the browser to re-establish the connection.

どう対応すればいいの?

WebSocket の対応可否をご確認ください。

AWS CloudShell は通信プロトコル「WebSocket」を利用します。WebSocket がプロキシやVPNなどで制限されている場合、セッションの開始に失敗したり、利用中にセッションが切断される事象が発生する場合があります。

AWS CloudShell compute environment: specifications and software - AWS CloudShell

CloudShell network requirements

Web Sockets
CloudShell depends on the Web Socket protocol, which allows two-way interactive communication between the user's web browser and the CloudShell service in the AWS Cloud.

そのため、利用中のネットワーク環境で WebSocket が制限されていないか確認し、必要に応じて制限解除等をご検討ください。

なお、AWS CloudShell の仕様として約20分~30分操作しないと自動的にセッションを終了します。

参考資料

Inactive sessions: AWS CloudShell is an interactive shell environment—if you don't interact with it using your keyboard or pointer for approximately 20–30 minutes, your shell session will end. (Running processes do not count as interactions.)