Public IP assignment for ECS tasks

Disable public IP assignment for ECS tasks that do not need direct internet exposure.

Description

AssignPublicIp: ENABLED in AwsvpcConfiguration requests a public IPv4 address for a task. An inbound internet connection also needs a route and a security group rule that permits it.

Potential impact

A direct connection can reach the task outside the service’s intended entry point.

Remediation

If tasks need no direct public access, set AssignPublicIp: DISABLED. Restrict subnet routes and security groups and provide NAT or supported VPC endpoints for required traffic such as image pulls.

Examples

Both excerpts use the same subnet. Disabling address assignment leaves its routes in place, so check connectivity on new tasks after deployment.

Before

yaml
Resources:
  ECSService:
    Type: AWS::ECS::Service
    Properties:
      NetworkConfiguration:
        AwsvpcConfiguration:
          AssignPublicIp: ENABLED
          Subnets:
            - subnet-021345abcdef67890

After

yaml
Resources:
  ECSService:
    Type: AWS::ECS::Service
    Properties:
      NetworkConfiguration:
        AwsvpcConfiguration:
          AssignPublicIp: DISABLED
          Subnets:
            - subnet-021345abcdef67890

References