ECS
Stands for Elastic Container Service
ネットワーク周りの設定がめんどいんだよ、Cloud Run みたいにならんかね、という気持ちに答えてくれそうなのが、App Runner ユースケースごとの設定などが紹介されていて良い
ECS deploy
ECS 環境の作成、管理、デプロイを簡単にできる
同じアプリを複数環境にデプロイするなど
こちらはアプリケーション、copilot はインフラという感じなのだろうか?
でも copilot でもコンテナのデプロイもできるんだよね?
amazon-ecs-cli
ローカルで簡単に環境をつくれるらしい?
インスタンス管理の方法=Capacity Providor がある
例えば Fargate
Auto-scalling-group というのもあるらしい
Task
task に複数コンテナ含めるか問題
つねに一つだけ task を実行する
task を停止するには、desired count も 0 にする必要があるみたい
A task is the instantiation of a task definition within a cluster. After you create a task definition for your application within Amazon ECS, you can specify the number of tasks to run on your cluster.
Task definitions
If your image is in a private registry outside of Amazon ECR, under Private registry, turn on Private registry authentication. Then, in Secrets Manager ARN or name, enter the Amazon Resource Name (ARN) of the secret.
execution role の設定が必要
パラメータ
ログ
ログに関するパラメータ
awslog を使う
Secret
SM と PS どっち使うか問題
Network
subnet を private にすべきか、public でよいか
private にすると外部アクセスに NAT が必要で、これの料金が高い?
public でも security group を設定すればよさそう
これ読むと良さそう
service ごとに subnet を設定できるもよう
security group
container instance に適用される
Fargate は network mode が awsvpc になる
IAM
task role
For Amazon ECS tasks (for all launch types), we recommend that you use the IAM policy and role for your tasks. These credentials allow your task to make AWS API requests without calling sts:AssumeRole to assume the same role that is already associated with the task. If your task requires that a role assumes itself, you must create a trust policy that explicitly allows that role to assume itself. For more information, see Updating a role trust policy in the IAM User Guide.
これの意味がわからない
わかった
ecs task が何らかの権限が必要なら、コンテナないのアプリが assumeRole API を読んでクレデンシャルを取得するのではなく、ecs task role を task 定義に追加しろ、ということ。そしたら自動で その role に assumerole される
Healthcheck
alpine だと curl 入っていなくて healthcheck 通らない
container image
docker hub のものも使える
デバッグ用には busybox とかが使える?
実行が終わると終了してしまうので、sleep とか使う
code:task-definition.json
{
"family": "busybox-task",
"containerDefinitions": [
{
"name": "busybox-container",
"image": "busybox",
"memory": 128,
"cpu": 128,
}
]
}
private subnet の場合は image pull するために、vpc endpoint を追加するなどしてネットワークへアクセスする必要がある