0
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⇒S3の通信が必要

Last updated at Posted at 2025-02-24

はじめに

閉域網内に、ECS + ECRの構成では、以下の通り、VPC Endpointの作成が必要です。

  • Interface Endpoint
    • ecr.api
    • ecr.dkr
  • S3 Gateway Endpoint

なぜS3 Gateway Endpointが必要なのかを調べてみました。

For your Amazon ECS tasks to pull private images from Amazon ECR, you must create a gateway endpoint for Amazon S3.
The gateway endpoint is required because Amazon ECR uses Amazon S3 to store your image layers.
When your containers download images from Amazon ECR, they must access Amazon ECR to get the image manifest and then Amazon S3 to download the actual image layers.

要するに、ECSは、S3から実際のimage layersを取得するため、ECS⇒S3が必要です。

リソース

  • 諸VPC Endpoints作成
    image.png
  • ECS、ECRなど必要なリソース

S3 Gateway Endpointを利用できない場合

ECSからS3 Gateway Endpointを利用できない場合、CannotPullContainerErrorが発生します。

  • ECS用のsubnet - Route tableにS3 Gateway Endpointへのrouteが設定されていない
    image.png

CannotPullContainerError

route設定なしにより、ECS task起動エラーが発生しました。

CannotPullContainerError:
The task cannot pull 123456789000.dkr.ecr.ap-northeast-1.amazonaws.com/test:NviE_Ss@sha256:6ecf45eff21e095ad8d60b724a6bbcax9df49da3b39fe80237ad7d688723c8706c3c from the registry 123456789000.dkr.ecr.ap-northeast-1.amazonaws.com/test:NviE_Ss@sha256:6ecf45eff21e095ad8d60b724a6bbcax9df49da3b39fe80237ad7d688723c8706c3c.
There is a connection issue between the task and the registry.
Check your task network configuration. : failed to copy: httpReadSeeker: failed open: failed to do request: Get 123456789000.dkr.ecr.ap-northeast-1.amazonaws.com/test:NviE_Ss@sha256:6ecf45eff21e095ad8d60b724a6bbcax9df49da3b39fe80237ad7d688723c8706c3c: dial tcp 52.219.172.118:443: i/o timeout

52.219.172.118はS3関連のEndpointみたいです。

nslookup 52.219.172.118
名前:    s3-ap-northeast-1-r-w.amazonaws.com
Address:  52.219.172.118

要するに、S3に接続できてず、imageを取得できなかったです。

S3 Gateway Endpointを利用できる場合

  • ECS用のsubnet - Route tableにS3 Gateway Endpointへのrouteが設定されている
    image.png

ECS task起動できた

image.png

NACL設定

NACLがStateLessであることを忘れてはいけないです。
以下のように、ECS subnetに付与されるNACLのOutboundにはALL Allowになっているが、Inbound ruleには、VPC内部の通信のみが許可されています。
そうすると、ECS⇒S3はOKで、戻り通信S3⇒ECSはblockされるため、同様に CannotPullContainerError が発生します。

image.png

0
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
0
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?