1 Answer
- Newest
- Most votes
- Most comments
0
Hello,
It's better not to hardcode the task definition revision in the code, instead in event bridge scheduler resource provide the task definition family without the revision like this below example. So, whenever you create a new version of task definition it will automatically update the event bridge scheduler to run the latest revision of the task definition.
resource "aws_scheduler_schedule" "serverlessland-eb-ecs-invoke-schedule" {
name = "serverlessland-eb-ecs-invoke-schedule"
flexible_time_window {
mode = "OFF"
}
schedule_expression = "rate(5 minute)"
target {
arn = aws_ecs_cluster.serverlessland-ecs-test-cluster.arn
role_arn = aws_iam_role.serverlessland-eventbridge-invoke-ecs-role.arn
ecs_parameters {
task_count = 1
task_definition_arn = aws_ecs_task_definition.serverlessland-ecs-task-definition.arn
launch_type = "FARGATE"
network_configuration {
subnets = aws_subnet.prod-subnet-public-1.*.id
assign_public_ip = true
security_groups = [aws_security_group.prod-sg.id]
}
}
}
}
resource "aws_ecs_task_definition" "serverlessland-ecs-task-definition" {
family = "serverlessland-ecs-task-definition"
requires_compatibilities = ["FARGATE"]
network_mode = "awsvpc"
cpu = 1024
memory = 2048
task_role_arn = aws_iam_role.serverlessland-ecs-task-role.arn
execution_role_arn = aws_iam_role.serverlessland-ecs-task-execution-role.arn
container_definitions = <<TASK_DEFINITION
[
{
"name": "webcontainer",
"image": "${local.container_image}",
"cpu": 1024,
"memory": 2048,
"essential": true,
"portMappings": [
{
"containerPort": 8080,
"hostPort": 8080
}
]
}
]
TASK_DEFINITION
}
Relevant content
- asked 2 years ago
- Accepted Answerasked a year ago
- asked 7 months ago
- AWS OFFICIALUpdated 3 years ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 6 months ago
- AWS OFFICIALUpdated a year ago