Reputation: 360
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?
Upvotes: 4
Views: 7221
Reputation: 421
IMO it's a misleading proposal to default to using command
over entryPoint
in ECS task definitions since command
will not handle (termination) signals properly, especially when using long lived tasks (e.g. in ECS services), so careful with that! If you really need to have a single task definition with changing commands, I'd rather suggest to use a dedicated entrypoint there (could be simply ['sh', '-c']
for example) and use the dynamic command
for the (short lived) task runs.
Upvotes: 0
Reputation: 360
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.
Upvotes: 5