AWS Fargateでtaskを動作させるのに必要な設定の記録

task definition

以下はインスタンスのcpuinfoとメモリの情報をチェックするtaskのdefinition

{
    "family": "get_fargate_cpu_info",
    "containerDefinitions": [
        {
            "name": "get_fargate_cpu_info",
            "image": "#{AWS_ACCOUNT_ID}.dkr.ecr.us-east-1.amazonaws.com/get_fargate_cpu_info",
            "entryPoint": ["bash", "-c", "cat /proc/cpuinfo && free -h"],
            "essential": true,
            "memoryReservation": 512,
            "logConfiguration": {
               "logDriver": "awslogs",
               "options": {
                 "awslogs-group": "get-fargate-cpu-info",
                 "awslogs-region": "us-east-1",
                 "awslogs-stream-prefix": "cpuinfo"
               }
            }
        }
    ],
    "requiresCompatibilities": ["FARGATE"],
    "networkMode": "awsvpc",
    "cpu": "256",
    "memory": "512",
    "executionRoleArn": "arn:aws:iam::#{AWS_ACCOUNT_ID}:role/ecsTaskExecutionRole"
}

aws ecs run-task

{
  "taskDefinition": "get_fargate_cpu_info",
  "cluster": "get-fargate-cpu-info",
  "networkConfiguration": {
    "awsvpcConfiguration": {
      "subnets": ["subnet-********"],
      "securityGroups": ["sg-********"],
      "assignPublicIp": "ENABLED"
    }
  },
  "launchType": "FARGATE"
}
  • launchType : FARGATE 必須
  • networkConfiguration : awsvpcConfiguration の定義が必要
    • assignPublicIp: ENABLED にして、外に出れるようにしないと、ECRからコンテナを取りにいけない

参考