Review the ECS task definition network mode

Choose an ECS network mode supported by the launch environment and allow only the communication each task needs.

Description

Fargate uses awsvpc, which gives each task its own network interface so you can apply security groups at task level. For EC2, choose a mode that supports the OS, host-sharing needs and port mappings.

Potential impact

An unsupported mode can prevent task registration or startup. On Linux EC2 tasks, none can suit a task that needs no external connectivity.

Remediation

Set network_mode: awsvpc for Fargate. Configure the service subnets, routes and security groups for the traffic it needs. Deploy the new task definition revision to the service, then check ports, load-balancer connectivity and outbound access.

Examples

The port mappings use the default NGINX listener on port 80. Supply the service network configuration and any required execution role separately.

Before

yaml
- name: Task Definition 생성
  community.aws.ecs_taskdefinition:
    family: nginx
    containers:
      - name: nginx
        essential: true
        image: nginx
        portMappings:
          - containerPort: 80
            hostPort: 80
    launch_type: FARGATE
    cpu: 512
    memory: 1024
    state: present
    network_mode: default

After

yaml
- name: Task Definition 생성
  community.aws.ecs_taskdefinition:
    family: nginx
    containers:
      - name: nginx
        essential: true
        image: nginx
        portMappings:
          - containerPort: 80
            hostPort: 80
    launch_type: FARGATE
    cpu: 512
    memory: 1024
    state: present
    network_mode: awsvpc

On Linux, default uses bridge, which Fargate does not support. Confirm that the service runs the revision registered with awsvpc.

References