Skip to content

Commit

Permalink
feat: more lambda config options (#573)
Browse files Browse the repository at this point in the history
* fet: more lambda config options

* chore: remove unused var

* review
  • Loading branch information
leonard-henriquez authored Dec 12, 2023
1 parent fa1b327 commit b8108a6
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 34 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ examples/quickstart/minio/*
.terraform.lock.hcl
.terraform.tfstate.lock*
terraform.*
backend.tf
build/buz
*.build
target/*
32 changes: 16 additions & 16 deletions deploy/terraform/aws/lambda/locals.tf
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
locals {
domain_parts = split(".", var.buz_domain)
cookie_domain = join(".", slice(local.domain_parts, 1, length(local.domain_parts))) # Assumes Buz is running on a subdomain and the cookie should be on root
buz_debug_var = "DEBUG"
buz_config_var = "BUZ_CONFIG_PATH"
buz_config_path = "/etc/buz/config.yml"
system_env_base = "${var.system}-${var.env}-"
artifact_repository = "${local.system_env_base}img"
image = "buz:${var.buz_version}"
buz_source_image = "ghcr.io/silverton-io/${local.image}"
service_name = "${local.system_env_base}collector"
config = "${local.system_env_base}config"
schema_bucket = "${local.system_env_base}${var.schema_bucket_name}"
events_bucket = "${local.system_env_base}${var.events_bucket_name}"
default_output = "buz_events"
deadletter_output = "buz_invalid_events"
domain_parts = split(".", var.buz_domain)
cookie_domain = join(".", slice(local.domain_parts, 1, length(local.domain_parts))) # Assumes Buz is running on a subdomain and the cookie should be on root
buz_debug_var = "DEBUG"
buz_config_var = "BUZ_CONFIG_PATH"
buz_config_path = "/etc/buz/config.yml"
system_env_base = "${var.system}-${var.env}-"
artifact_repository = "${local.system_env_base}img"
image = "buz:${var.buz_version}"
buz_source_image = "${var.buz_image_repo}/${local.image}"
service_name = "${local.system_env_base}collector"
config = "${local.system_env_base}config"
schema_bucket = "${local.system_env_base}${var.schema_bucket_name}"
events_bucket = "${local.system_env_base}${var.events_bucket_name}"
default_output = "buz_events"
deadletter_output = "buz_invalid_events"
metadata_extraction_params = "{isValid:.isValid,vendor:.vendor,namespace:.namespace,version:.version}"
s3_dynamic_prefix = "isValid=!{partitionKeyFromQuery:isValid}/vendor=!{partitionKeyFromQuery:vendor}/namespace=!{partitionKeyFromQuery:namespace}/version=!{partitionKeyFromQuery:version}/year=!{timestamp:yyyy}/month=!{timestamp:MM}/day=!{timestamp:dd}/"
s3_dynamic_prefix = "isValid=!{partitionKeyFromQuery:isValid}/vendor=!{partitionKeyFromQuery:vendor}/namespace=!{partitionKeyFromQuery:namespace}/version=!{partitionKeyFromQuery:version}/year=!{timestamp:yyyy}/month=!{timestamp:MM}/day=!{timestamp:dd}/"
}
35 changes: 19 additions & 16 deletions deploy/terraform/aws/lambda/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ data "aws_ecr_image" "buz_image" {

resource "null_resource" "configure_docker" {
triggers = {
build_number = var.buz_version
always_run = timestamp()
}
provisioner "local-exec" {
command = "aws ecr get-login-password --region ${var.aws_region} | docker login --username AWS --password-stdin ${data.aws_caller_identity.current.account_id}.dkr.ecr.${var.aws_region}.amazonaws.com"
Expand Down Expand Up @@ -228,6 +228,14 @@ resource "aws_cloudwatch_log_group" "buz" {
}
}

data "aws_cloudfront_origin_request_policy" "buz" {
name = "Managed-AllViewerExceptHostHeader"
}

data "aws_cloudfront_cache_policy" "buz" {
name = "Managed-CachingDisabled"
}

resource "aws_cloudfront_distribution" "buz" {
enabled = true
is_ipv6_enabled = true
Expand All @@ -248,25 +256,20 @@ resource "aws_cloudfront_distribution" "buz" {
}

default_cache_behavior {
viewer_protocol_policy = "redirect-to-https"
min_ttl = 0
default_ttl = 3600
max_ttl = 86400
target_origin_id = replace(replace(aws_lambda_function_url.buz.function_url, "https://", ""), "/", "")
allowed_methods = ["DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT"]
cached_methods = ["HEAD", "GET"]
forwarded_values {
query_string = true
cookies {
forward = "all"
}
}
viewer_protocol_policy = "redirect-to-https"
min_ttl = 0
default_ttl = 3600
max_ttl = 86400
target_origin_id = replace(replace(aws_lambda_function_url.buz.function_url, "https://", ""), "/", "")
allowed_methods = ["DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT"]
cached_methods = ["HEAD", "GET"]
origin_request_policy_id = data.aws_cloudfront_origin_request_policy.buz.id
cache_policy_id = data.aws_cloudfront_cache_policy.buz.id
}

restrictions {
geo_restriction {
restriction_type = "whitelist"
locations = ["US", "CA", "GB", "DE"]
restriction_type = "none"
}
}

Expand Down
5 changes: 3 additions & 2 deletions deploy/terraform/aws/lambda/provider.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ terraform {
}

provider "aws" {
region = var.aws_region
}
region = var.aws_region
profile = var.aws_profile
}
12 changes: 12 additions & 0 deletions deploy/terraform/aws/lambda/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ variable "aws_region" {
default = "us-east-1"
}

variable "aws_profile" {
description = "AWS Profile"
type = string
default = "default"
}

variable "system" {
description = "The name of the Buz implementation. \n\nExample: buz"
type = string
Expand All @@ -26,6 +32,12 @@ variable "buz_domain" {
type = string
}

variable "buz_image_repo" {
description = "The Buz image repository"
type = string
default = "ghcr.io/silverton-io"
}

variable "buz_version" {
description = "The version of Buz to run."
type = string
Expand Down

0 comments on commit b8108a6

Please sign in to comment.