1
votes

I'm creating a scheduled ECS task in Terraform. When I try to override the container definition for the entryPoint, the resulting task does not use the overridden entryPoint. However, if I try to override the command, it works fine (adds a new command in addition to existing entry point). I cannot find anything in the docs that lead me to believe that there is no support for entryPoint overriding but that may be the case?

Below is the code for the Cloudwatch event target in terraform

resource "aws_cloudwatch_event_target" "ecs_task" {
  target_id = "run-${var.task_name}-scheduled"
  arn       = "${var.cluster_arn}"
  rule      = "${aws_cloudwatch_event_rule.ecs_task_event_rule.name}"
  role_arn  = "${aws_iam_role.ecs_event.arn}"

  ecs_target = {
    launch_type = "${var.launch_type}"
    network_configuration = {
      subnets = ["${var.subnet_ids}"]
      security_groups = ["${var.security_group_ids}"]
    }
    task_count = 1
    task_definition_arn = "${var.task_arn}"
  }

  input = <<DOC
{
  "containerOverrides": [
    {
      "name": "${var.task_name}",
      "entryPoint": ${jsonencode(var.command_overrides)}
    }
  ]
}
DOC
}

This creates a new scheduled task on the AWS console, where the input field is the following:

{
    "containerOverrides": [
        {
            "name": "my-container-name",
            "entryPoint": [
                "sh",
                "/my_script.sh"
            ]
        }
    ]
}

However tasks launched by this rule do not have the entry point override and use the entrypoint defined in the original task definition.

TLDR: How can I override the entrypoint for a scheduled task?

1

1 Answers

3
votes

As of today, only a certain number of fields can be overridden as the scheduled task ultimately uses the run-task API. These fields are the following:

  • command
  • environment
  • taskRoleArn
  • cpu
  • memory
  • memoryReservation
  • resourceRequirements

Container definitions for other fields are not supported, such as entryPoint, portMappings, and logConfiguration.

The solution is to use command instead of entryPoint in the original task definition, as command can be overridden but entryPoint cannot.