2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ECS Managed Instance で ECS Exec を使う際のネットワーク考慮点

2
Posted at

ECS Managed Instanceの検証をしていたらハマったので備忘録として。

Public Subnet で動く ECS Managed Instance 上のタスクコンテナに ECS Exec しようとしたらできない

何も考えずにパブリックサブネット上で上記を展開した後にExecコマンドを実行すると、下記のエラーが出ます。

An error occurred (TargetNotConnectedException) when calling the ExecuteCommand operation: The execute command failed. TargetNotConnected: ecs:ecs-task_xxxxxxxxxxxxxxxx is not connected.

ECS Managed Instance におけるネットワークの考慮点

以下のブログに詳細がありますが、ECS Managed Instance では assignPublicIp=ENABLE でタスクにパブリックIPを付与することはできないようです。

Public Subnet にタスクインスタンスを配置している場合

対応方法としては下記のとおりです。

  • VPC Endpoint を作成する

image.png

実際に試したところ接続できました。ただ、実運用を考えると Endpointの従量課金によるコスト は気になります。

Private Subnet にタスクインスタンスを配置している場合

  • 上記の方法
  • または NAT Gateway でインターネットへ通す

image.png

未検証ですが、この場合はネットワークレベルでルートが通っているため、おそらく接続できると思います。

まとめ

ECS Managed Instance を利用する際は、ネットワーク周りに注意が必要です。
本記事ではあまり触れていませんが、今回は awsvpc モードを前提としているため、これらの方法以外にも ECS ネットワークモードを bridge にするというやり方もありそうです。
実運用的には、すでに NAT Gateway や VPC Endpoint が整備されている環境であれば、ブログに記載の手法で進めるのがベターかと思います。

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?