Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ncas: update ecs, add logging using EventBridge #3677

Merged
merged 2 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 27 additions & 6 deletions terraform/environments/ncas/ecs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ resource "aws_ecs_cluster" "ncas_cluster" {
}
}

resource "aws_cloudwatch_log_group" "ncasFamily_logs" {
name = "/ecs/ncasFamily"
resource "aws_cloudwatch_log_group" "deployment_logs" {
name = "/aws/events/deploymentLogs"
}

resource "aws_ecs_task_definition" "ncas_task_definition" {
Expand All @@ -21,7 +21,7 @@ resource "aws_ecs_task_definition" "ncas_task_definition" {
container_definitions = jsonencode([
{
name = "ncas-container"
image = "mcr.microsoft.com/dotnet/framework/aspnet:4.8"
image = "${aws_ecr_repository.ncas_ecr_repo.repository_url}:latest"
cpu = 1024
memory = 2048
essential = true
Expand All @@ -35,7 +35,7 @@ resource "aws_ecs_task_definition" "ncas_task_definition" {
logConfiguration = {
logDriver = "awslogs"
options = {
awslogs-group = "${aws_cloudwatch_log_group.ncasFamily_logs.name}"
awslogs-group = "${aws_cloudwatch_log_group.deployment_logs.name}"
awslogs-region = "eu-west-2"
awslogs-stream-prefix = "ecs"
}
Expand Down Expand Up @@ -92,8 +92,8 @@ resource "aws_ecs_service" "ncas_ecs_service" {
task_definition = aws_ecs_task_definition.ncas_task_definition.arn
launch_type = "FARGATE"
enable_execute_command = true
desired_count = 1
health_check_grace_period_seconds = 90
desired_count = 2
health_check_grace_period_seconds = 180

network_configuration {
subnets = data.aws_subnets.shared-public.ids
Expand Down Expand Up @@ -239,3 +239,24 @@ resource "aws_ecr_repository" "ncas_ecr_repo" {
name = "ncas-ecr-repo"
force_delete = true
}

# AWS EventBridge rule
resource "aws_cloudwatch_event_rule" "ecs_events" {
name = "ecs-events"
description = "Capture all ECS events"

event_pattern = jsonencode({
"source" : ["aws.ecs"],
"detail" : {
"clusterArn" : [aws_ecs_cluster.ncas_cluster.arn]
}
})
}

# AWS EventBridge target
resource "aws_cloudwatch_event_target" "logs" {
depends_on = [aws_cloudwatch_log_group.deployment_logs]
rule = aws_cloudwatch_event_rule.ecs_events.name
target_id = "send-to-cloudwatch"
arn = aws_cloudwatch_log_group.deployment_logs.arn
}
6 changes: 3 additions & 3 deletions terraform/environments/ncas/load_balancer.tf
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,12 @@ resource "aws_lb_target_group" "ncas_target_group" {

health_check {
healthy_threshold = "3"
interval = "15"
interval = "30"
protocol = "HTTP"
port = "80"
unhealthy_threshold = "3"
unhealthy_threshold = "5"
matcher = "200-302"
timeout = "5"
timeout = "10"
}

}
Expand Down
Loading