Skip to content

Commit

Permalink
point healthchecks to /health ep
Browse files Browse the repository at this point in the history
  • Loading branch information
chrispsheehan committed Sep 12, 2024
1 parent 95374c3 commit a2cf30a
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 10 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ Required deployment iam privileges.
]
```


## ci

Commits to `main` will kick off a deployment.
Expand Down
7 changes: 6 additions & 1 deletion justfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
format:
#!/usr/bin/env bash
cd tf
terraform fmt --recursive
terraform fmt --recursive
check:
#!/usr/bin/env bash
cd tf
terraform validate
2 changes: 1 addition & 1 deletion src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ app.use((req, res, next) => {
next();
});

app.get('/hello', (req, res) => {
app.get('/health', (req, res) => {
res.status(200).json({msg: "Hello, this is your API"});
});

Expand Down
2 changes: 1 addition & 1 deletion tf/container_definitions.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"healthcheck": {
"command": [
"CMD-SHELL",
"wget --quiet --spider --tries=1 http://localhost:${container_port}/hello || exit 1"
"wget --quiet --spider --tries=1 http://localhost:${container_port}/health || exit 1"
],
"interval": 30,
"retries": 3,
Expand Down
4 changes: 2 additions & 2 deletions tf/data.tf
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ data "aws_iam_policy_document" "assume_role" {
}
}

data "aws_iam_policy_document" "ecr_policy" {
data "aws_iam_policy_document" "logs_policy" {
statement {
actions = [
"logs:CreateLogStream",
Expand All @@ -37,7 +37,7 @@ data "aws_iam_policy_document" "ecr_policy" {

effect = "Allow"

resources = ["*"]
resources = [aws_cloudwatch_log_group.ecs_log_group.arn]
}
}

18 changes: 14 additions & 4 deletions tf/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,19 @@ resource "aws_ecs_cluster" "cluster" {
name = "${var.project_name}-cluster"
}

resource "aws_iam_policy" "ecr_access_policy" {
resource "aws_iam_policy" "logs_access_policy" {
name = "${local.formatted_name}_ecr_access_policy"
policy = data.aws_iam_policy_document.ecr_policy.json
policy = data.aws_iam_policy_document.logs_policy.json
}

resource "aws_iam_role" "ecs_task_role" {
name = "${var.project_name}-ecs-task-role"
assume_role_policy = data.aws_iam_policy_document.assume_role.json
}

resource "aws_iam_role_policy_attachment" "ecr_access_policy_attachment" {
resource "aws_iam_role_policy_attachment" "logs_access_policy_attachment" {
role = aws_iam_role.ecs_task_role.name
policy_arn = aws_iam_policy.ecr_access_policy.arn
policy_arn = aws_iam_policy.logs_access_policy.arn
}

resource "aws_ecs_task_definition" "task" {
Expand Down Expand Up @@ -168,6 +168,16 @@ resource "aws_lb_target_group" "tg" {
vpc_id = data.aws_vpc.vpc.id

target_type = "ip"

health_check {
interval = 30
path = "/health"
protocol = "HTTP"
matcher = "200"
timeout = 5
healthy_threshold = 5
unhealthy_threshold = 2
}
}

resource "aws_lb_listener" "listener" {
Expand Down

0 comments on commit a2cf30a

Please sign in to comment.