ECS
Product of AWS
Stands for Elastic Container Service
ネットワーク周りの設定がめんどいんだよ、Cloud Run みたいにならんかね、という気持ちに答えてくれそうなのが、App Runner
What is Amazon Elastic Container Service? - Amazon Elastic Container Service
ユースケースごとの設定などが紹介されていて良い
Amazon ECS best practices - Amazon Elastic Container Service
Setup ECS Fargate using cli
describe で出力した ECS タスク定義をさくっと登録可能な形に整形する | Stuck inside
ECS deploy
AWS Copilot という便利な CLI があるらしい
AWS Copilot のご紹介 | Amazon Web Services ブログ
ECS 環境の作成、管理、デプロイを簡単にできる
同じアプリを複数環境にデプロイするなど
aws/copilot-cli: The AWS Copilot CLI is a tool for developers to build, release and operate production ready containerized applications on AWS App Runner or Amazon ECS on AWS Fargate.
docker compose でもデプロイできるらしい
Docker ComposeによるAmazon ECS対応がGAに!コンテナをローカル環境と同じノリでECS環境で起動できるぞ!! | DevelopersIO
こちらはアプリケーション、copilot はインフラという感じなのだろうか?
でも copilot でもコンテナのデプロイもできるんだよね?
ecspresso
あなたの組織に最適なECSデプロイ手法の考察 | DevelopersIO
amazon-ecs-cli
ローカルで簡単に環境をつくれるらしい?
aws/amazon-ecs-cli: The Amazon ECS CLI enables users to run their applications on ECS/Fargate using the Docker Compose file format, quickly provision resources, push/pull images in ECR, and monitor running applications on ECS/Fargate.
インスタンス管理の方法=Capacity Providor がある
Amazon ECS capacity providers - Amazon Elastic Container Service
例えば Fargate
Amazon ECS on AWS Fargate - Amazon Elastic Container Service
Auto-scalling-group というのもあるらしい
Task
task に複数コンテナ含めるか問題
Application architecture - Amazon Elastic Container Service
つねに一つだけ task を実行する
https://github.com/aws/containers-roadmap/issues/959#issuecomment-1117717863
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.
https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task_definitions.html
Amazon ECS task lifecycle - Amazon Elastic Container Service
Task definitions
Creating an Amazon ECS task definition using the console - Amazon Elastic Container Service
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.
Private registry authentication in Amazon ECR - Amazon ECR
execution role の設定が必要
Amazon ECS task execution IAM role - Amazon Elastic Container Service
パラメータ
Amazon ECS task definition parameters for the Fargate launch type - Amazon Elastic Container Service
ログ
ログに関するパラメータ
Amazon ECS task definition parameters for the Fargate launch type - Amazon Elastic Container Service
awslog を使う
Send Amazon ECS logs to CloudWatch - Amazon Elastic Container Service
Secret
SM と PS どっち使うか問題
AWSのParameter StoreとSecrets Manager、結局どちらを使えばいいのか?比較 - Qiita
Network
subnet を private にすべきか、public でよいか
private にすると外部アクセスに NAT が必要で、これの料金が高い?
public でも security group を設定すればよさそう
これ読むと良さそう
Task Networking in AWS Fargate | AWS Compute Blog
service ごとに subnet を設定できるもよう
Service definition parameters - Amazon Elastic Container Service
Troubleshoot Amazon ECS tasks for Fargate that are stuck in the Pending state
security group
container instance に適用される
Connect Amazon ECS applications to the internet - Amazon Elastic Container Service
Fargate は network mode が awsvpc になる
Amazon ECS task definition parameters for the Fargate launch type - Amazon Elastic Container Service
IAM
Amazon ECS task execution IAM role - Amazon Elastic Container Service
task role
https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-iam-roles.html#create_task_iam_policy_and_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
Task definition parameters - Amazon ECS
ECSタスク定義のヘルスチェックコマンドを設定してみた | DevelopersIO
ハマりポイントから学ぶ ALB と NLB の違い - Qiita
alpine だと curl 入っていなくて healthcheck 通らない
container image
Amazon ECS で使用するコンテナイメージの作成  - Amazon Elastic Container Service
docker hub のものも使える
デバッグ用には busybox とかが使える?
実行が終わると終了してしまうので、sleep とか使う
code:task-definition.json
{
"family": "busybox-task",
"containerDefinitions": [
{
"name": "busybox-container",
"image": "busybox",
"memory": 128,
"cpu": 128,
"command": "sleep", "3600"
}
]
}
private subnet の場合は image pull するために、vpc endpoint を追加するなどしてネットワークへアクセスする必要がある