Skip to content

Commit

Permalink
Add advanced lambda logging options
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobgill1 committed May 16, 2024
1 parent ed3da37 commit 1ec45f8
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 0 deletions.
4 changes: 4 additions & 0 deletions locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ locals {
dead_letter_config = try(var.server_options.function.dead_letter_config, null)
reserved_concurrent_executions = coalesce(try(var.server_options.function.reserved_concurrent_executions, null), 10)
code_signing_config = try(var.server_options.function.code_signing_config, null)
logging_config = try(var.server_options.function.logging_config, null)
}

log_group = {
Expand Down Expand Up @@ -141,6 +142,7 @@ locals {
dead_letter_config = try(var.image_optimization_options.function.dead_letter_config, null)
reserved_concurrent_executions = coalesce(try(var.image_optimization_options.function.reserved_concurrent_executions, null), 3)
code_signing_config = try(var.image_optimization_options.function.code_signing_config, null)
logging_config = try(var.image_optimization_options.function.logging_config, null)
}

log_group = {
Expand Down Expand Up @@ -191,6 +193,7 @@ locals {
dead_letter_config = try(var.revalidation_options.function.dead_letter_config, null)
reserved_concurrent_executions = coalesce(try(var.revalidation_options.function.reserved_concurrent_executions, null), 3)
code_signing_config = try(var.revalidation_options.function.code_signing_config, null)
logging_config = try(var.revalidation_options.function.logging_config, null)
}

log_group = {
Expand Down Expand Up @@ -242,6 +245,7 @@ locals {
dead_letter_config = try(var.warmer_options.function.dead_letter_config, null)
reserved_concurrent_executions = coalesce(try(var.warmer_options.function.reserved_concurrent_executions, null), 3)
code_signing_config = try(var.warmer_options.function.code_signing_config, null)
logging_config = try(var.warmer_options.function.logging_config, null)
}

log_group = {
Expand Down
4 changes: 4 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ module "server_function" {
reserved_concurrent_executions = local.server_options.function.reserved_concurrent_executions
code_signing_config = local.server_options.function.code_signing_config
log_group = local.server_options.log_group
logging_config = local.server_options.logging_config


source_dir = local.server_options.package.source_dir
Expand Down Expand Up @@ -91,6 +92,7 @@ module "image_optimization_function" {
reserved_concurrent_executions = local.image_optimization_options.function.reserved_concurrent_executions
code_signing_config = local.image_optimization_options.function.code_signing_config
log_group = local.image_optimization_options.log_group
logging_config = local.image_optimization_options.logging_config

source_dir = local.image_optimization_options.package.source_dir
output_dir = local.image_optimization_options.package.output_dir
Expand Down Expand Up @@ -126,6 +128,7 @@ module "revalidation_function" {
reserved_concurrent_executions = local.revalidation_options.function.reserved_concurrent_executions
code_signing_config = local.revalidation_options.function.code_signing_config
log_group = local.revalidation_options.log_group
logging_config = local.revalidation_options.logging_config

source_dir = local.revalidation_options.package.source_dir
output_dir = local.revalidation_options.package.output_dir
Expand Down Expand Up @@ -177,6 +180,7 @@ module "warmer_function" {
reserved_concurrent_executions = local.warmer_options.function.reserved_concurrent_executions
code_signing_config = local.warmer_options.function.code_signing_config
log_group = local.warmer_options.log_group
logging_config = local.warmer_options.logging_config

source_dir = local.warmer_options.package.source_dir
output_dir = local.warmer_options.package.output_dir
Expand Down
11 changes: 11 additions & 0 deletions modules/opennext-lambda/lambda.tf
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,17 @@ resource "aws_lambda_function" "function" {
target_arn = var.dead_letter_config.target_arn
}
}

dynamic "logging_config" {
for_each = var.logging_config != null ? [true] : []

content {
log_format = var.logging_config.log_format
log_group = try(var.logging_config.log_group, null)
application_log_level = try(var.logging_config.application_log_level, null)
system_log_level = try(var.logging_config.system_log_level, null)
}
}
}

resource "aws_lambda_function_url" "function_url" {
Expand Down
10 changes: 10 additions & 0 deletions modules/opennext-lambda/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,16 @@ variable "reserved_concurrent_executions" {
default = 10
}

variable "logging_config" {
description = "Advanced Logging Configuration for the Lambda Function"
default = null
type = object({
log_format = string
log_group = optional(string)
application_log_level = optional(string)
system_log_level = optional(string)
})
}

/**
* Lambda Networking
Expand Down
24 changes: 24 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ variable "server_options" {
signing_profile_version_arns = list(string)
untrusted_artfact_on_deployment = optional(string)
}))
logging_config = optional(object({
log_format = string
log_group = optional(string)
application_log_level = optional(string)
system_log_level = optional(string)
}))
}))
environment_variables = optional(map(string))
iam_policy = optional(list(object({
Expand Down Expand Up @@ -152,6 +158,12 @@ variable "image_optimization_options" {
signing_profile_version_arns = list(string)
untrusted_artfact_on_deployment = optional(string)
}))
logging_config = optional(object({
log_format = string
log_group = optional(string)
application_log_level = optional(string)
system_log_level = optional(string)
}))
}))
environment_variables = optional(map(string))
iam_policy = optional(list(object({
Expand Down Expand Up @@ -218,6 +230,12 @@ variable "revalidation_options" {
signing_profile_version_arns = list(string)
untrusted_artfact_on_deployment = optional(string)
}))
logging_config = optional(object({
log_format = string
log_group = optional(string)
application_log_level = optional(string)
system_log_level = optional(string)
}))
}))
environment_variables = optional(map(string))
iam_policy = optional(list(object({
Expand Down Expand Up @@ -284,6 +302,12 @@ variable "warmer_options" {
signing_profile_version_arns = list(string)
untrusted_artfact_on_deployment = optional(string)
}))
logging_config = optional(object({
log_format = string
log_group = optional(string)
application_log_level = optional(string)
system_log_level = optional(string)
}))
}))
environment_variables = optional(map(string))
iam_policy = optional(list(object({
Expand Down

0 comments on commit 1ec45f8

Please sign in to comment.