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

lb added for entry extraction; #25

Merged
merged 1 commit into from
Jan 4, 2024
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
5 changes: 4 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ module "nlp_server" {
# Entry Extraction
entryextraction_ecs_task_defn_arn = module.entryextraction.entryextraction_ecs_task_defn_arn
entryextraction_ecs_container_name = module.entryextraction.entryextraction_container_name
entryextraction_ecs_endpoint = module.entryextraction.aws_service_discovery_service_endpoint
entryextraction_ecs_endpoint = module.entryextraction.application_endpoint

# Model info
classification_model_id = var.classification_model_id
Expand Down Expand Up @@ -567,6 +567,9 @@ module "entryextraction" {
# ecs capacity
fargate_cpu = var.entry_extraction_fargate_cpu
fargate_memory = var.entry_extraction_fargate_memory

# ecs task count
app_count = var.entry_extraction_task_count
}

module "reliability" {
Expand Down
38 changes: 38 additions & 0 deletions modules/ecsmodules/entryextraction/alb.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
resource "aws_alb" "alb" {
name = "entry-ext-lb-${var.environment}"
subnets = var.public_subnets
security_groups = [aws_security_group.alb_sg.id]
}

resource "aws_alb_target_group" "tg" {
name = "ent-ext-alb-target-grp-${var.environment}"
port = var.app_port
protocol = "HTTP"
target_type = "ip"
vpc_id = var.vpc_id
load_balancing_algorithm_type = "least_outstanding_requests"

health_check {
port = var.app_port
healthy_threshold = 2
unhealthy_threshold = 3
timeout = 30
protocol = "HTTP"
matcher = "200,301,302"
path = "/"
interval = 60
}
}


# Redirecting all incomming traffic from ALB to the target group
resource "aws_alb_listener" "app_listener" {
load_balancer_arn = aws_alb.alb.id
port = var.app_port
protocol = "HTTP"

default_action {
type = "forward"
target_group_arn = aws_alb_target_group.tg.arn
}
}
27 changes: 6 additions & 21 deletions modules/ecsmodules/entryextraction/ecs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -127,29 +127,14 @@ resource "aws_ecs_service" "service" {
assign_public_ip = false
}

# load_balancer {
# target_group_arn = aws_alb_target_group.tg.arn
# container_name = "backend-server-${var.environment}"
# container_port = var.app_port
# }
load_balancer {
target_group_arn = aws_alb_target_group.tg.arn
container_name = "${var.ecs_container_name}-${var.environment}"
container_port = var.app_port
}

depends_on = [
#aws_alb_listener.app_listener,
aws_alb_listener.app_listener,
var.iam_ecs_task_execution_policy_arn
]
service_registries {
registry_arn = aws_service_discovery_service.name.arn
}
}

resource "aws_service_discovery_service" "name" {
name = "${var.local_sub_domain}-${var.environment}"
dns_config {
namespace_id = var.private_dns_namespace_id
dns_records {
ttl = 10
type = "A"
}
routing_policy = "MULTIVALUE"
}
}
4 changes: 2 additions & 2 deletions modules/ecsmodules/entryextraction/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ output "entryextraction_container_name" {
value = var.ecs_container_name
}

output "aws_service_discovery_service_endpoint" {
value = "http://${var.local_sub_domain}-${var.environment}.${var.private_dns_namespace_local_domain}:${var.app_port}"
output "application_endpoint" {
value = "http://${aws_alb.alb.dns_name}:${var.app_port}"
}
19 changes: 19 additions & 0 deletions modules/ecsmodules/entryextraction/securitygrps.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
resource "aws_security_group" "alb_sg" {
name = "entry-extraction-alb-security-group-${var.environment}"
description = "Controls access to the ALB"
vpc_id = var.vpc_id

ingress {
protocol = "tcp"
from_port = var.app_port
to_port = var.app_port
cidr_blocks = ["0.0.0.0/0"]
}

egress {
protocol = "-1"
from_port = 0
to_port = 0
cidr_blocks = ["0.0.0.0/0"]
}
}
3 changes: 2 additions & 1 deletion staging.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ topicmodeling_fargate_cpu = "1024"
topicmodeling_fargate_memory = "4096"

# ecs tasks count
text_extraction_task_count = 2
text_extraction_task_count = 2
entry_extraction_task_count = 2

# model info
classification_model_id = "classification_model"
Expand Down
3 changes: 2 additions & 1 deletion variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,5 @@ variable "topicmodeling_fargate_cpu" {}
variable "topicmodeling_fargate_memory" {}

# ecs task count
variable "text_extraction_task_count" {}
variable "text_extraction_task_count" {}
variable "entry_extraction_task_count" {}
Loading