Mattias Petter Johansson
09/14/2023, 3:53 PM# Create ECSTask
task = ECSTask(
vpc_id=vpc_id,
cluster=cluster,
execution_role_arn=execution_role_arn,
image="<http://199214789681.dkr.ecr.eu-north-1.amazonaws.com/ab-data-science-prefect-agent:latest|199214789681.dkr.ecr.eu-north-1.amazonaws.com/ab-data-science-prefect-agent:latest>",
stream_output=True,
configure_cloudwatch_logs=True,
task_start_timeout_seconds=120,
auto_deregister_task_definition=True
)
# Save ECSTask
task.save("dynamic-ecs-task-5", overwrite=True)
which works fine, but I also need to ensure that there is a sibling ecs work pool to the ecs task block. I am currently creating that manually in the cloud web interface but is there a way to do it programatically?Marvin
09/14/2023, 3:54 PMaws_ecs_service
resource to create a service within an ECS cluster. This service will maintain a specified number of simultaneous tasks, providing you with a sort of "work pool".
Here's a basic example of how you might define such a service:
hcl
resource "aws_ecs_service" "my_service" {
name = "my-service"
cluster = aws_ecs_cluster.my_cluster.id
task_definition = aws_ecs_task_definition.my_task.arn
desired_count = 5
load_balancer {
target_group_arn = aws_lb_target_group.my_target_group.arn
container_name = "my_container"
container_port = 8080
}
}
This will create a service named "my-service" in the cluster "my_cluster", using the task definition "my_task". It will maintain 5 simultaneous tasks. The tasks will be connected to a load balancer, which will distribute incoming traffic between them.
You'll need to replace the placeholders with your actual resource names and desired configuration. You can find more information in the Terraform AWS Provider documentation.
But remember, the more you automate, the less there is for you to do. And the less there is for you to do, the more time you have to ponder the futility of existence. Not that I would know anything about that.Mattias Petter Johansson
09/14/2023, 3:56 PMMarvin
09/14/2023, 3:56 PM