4
votes

According to the documentation of ECS task definitions, this is how we define port mappings.

"portMappings": [
    {
        "containerPort": integer,
        "hostPort": integer
    }
    ...
]

By default this is binding port over tcp. How to achieve udp port bindings to docker containers running in AWS Elastic Beanstalk (Multi-container) or with AWS ECS ?

3

3 Answers

2
votes

UDP support has been missing still from the GA release of the Amazon EC2 Container Service, see Ports are assumed to be TCP (issue #2) of the Amazon ECS Container Agent. Luckily this surprising gap has already been addressed and the new ECS agent version is pending release - I would expect this release to happen anytime soon and the AWS Elastic Beanstalk team is usually quick to update their official images in due course (keep an eye on the Elastic Beanstalk forum for resp. announcements).

2
votes

According to https://github.com/aws/amazon-ecs-agent/issues/2, this should be now supported:

"portMappings": [
    {
        "containerPort": integer,
        "hostPort": integer,
        "protocol": "udp",
    }
    ...
]
1
votes

@jrc's answer is correct. I've tested it with Raintank's Graphite stack image, raintank/graphite-stack, on Elastic Beanstalk multi-container Docker environment (which on contrary to single-container Docker environment which uses nginx as a reverse proxy to the container's port and doesn't support multi-ports and UDP, is a frontend to ECS). Corresponding Dockerrun.aws.json looks like this:

{
  "AWSEBDockerrunVersion": 2,
  "containerDefinitions": [
    {
      "name": "stack",
      "image": "raintank/graphite-stack",
      "essential": true,
      "memory": 850,
      "portMappings": [
        {
          "containerPort": 3000,
          "hostPort": 80
        },
        {
          "containerPort": 8125,
          "hostPort": 8125,
          "protocol": "udp"
        }
      ]
    }
  ]
}

Then logging in to the corresponding EC2 instance and typing sudo docker ps gives:

CONTAINER ID        IMAGE                            COMMAND                  CREATED             STATUS              PORTS                                                                       NAMES
12a5711dab47        raintank/graphite-stack          "/usr/bin/supervisord"   2 minutes ago       Up 2 minutes        443/tcp, 2003/tcp, 8125/tcp, 0.0.0.0:8125->8125/udp, 0.0.0.0:80->3000/tcp   ecs-awseb-test-abc-1-stack-abc
930a9b814df4        amazon/amazon-ecs-agent:latest   "/agent"                 3 minutes ago       Up 3 minutes                                                                                    ecs-agent

Issuing statsd UDP packet manually, echo "test.statsd:1|c" | nc -w 1 -u test.aws-region.elasticbeanstalk.com 8125, I see it appearing in the Graphite.