When you use the AWS Ruby SDK to register your ECS task definition files you maybe struggle with the same error I struggled around.

ArgumentError: unexpected value at params[:container_definitions][0]["portMappings"]

The same error message was also returned when I tried to define mountPoints.

The short answer is that the AWS Ruby SDK use also Rubyish snake_case instead of camelBack JSON-style. After changing “portMappings” into “port_mappings” everything worked (same applies to containerPort and hostPort).

If I had started with Ruby directly I would maybe never run into that situation because it’s well documented. But I started with the AWS Command Line Interface (CLI) to play around with ECS and I also had my task definition in a separate file.

aws ecs register-task-definition --cli-input-json file://<path_to_json_file>/hubot_task_definiton.json

Based on that I started with the automation and reused my existing task definiton file.

ecs.register_task_definition(family: "HuBot", container_definitions: JSON.parse(taskDefintion))

After that confusion I can now also define port mappings as well as mount points. The later I need for my idea to have secret keys as environment variables inside a docker container instead of defining them in the task definition file. Of course, if it works I’ll post my solution.