Skip to content
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
8 changes: 6 additions & 2 deletions testing/benchmarking/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ terraform {
}

locals {
load_req_path = "/test"
load_req_path = "/test"
name_from_runtime = replace(var.lambda_runtime, ".", "_")
lambda_function_zip = "../build/${local.name_from_runtime}.zip"
lambda_function_name = "${var.resource_prefix}_${local.name_from_runtime}_apm_aws_lambda"
runtimeToHandler = {
"python3.8" = "main.handler"
"go1.x" = "main"
Expand Down Expand Up @@ -53,10 +56,11 @@ module "lambda_deployment" {

resource_prefix = var.resource_prefix

build_dir = "../build"
apm_aws_extension_path = "../../bin/extension.zip"

lambda_runtime = var.lambda_runtime
lambda_function_zip = local.lambda_function_zip
lambda_function_name = local.lambda_function_name
lambda_handler = local.runtimeToHandler[var.lambda_runtime]
lambda_invoke_path = local.load_req_path
lambda_memory_size = var.lambda_memory_size
Expand Down
4 changes: 2 additions & 2 deletions testing/functions/python3.8/main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
from elasticapm import capture_serverless

coldstart = True
coldstart = "true"
@capture_serverless()
def handler(event, context):
global coldstart
Expand All @@ -13,6 +13,6 @@ def handler(event, context):
"coldstart": coldstart,
}
}
coldstart = False
coldstart = "false"
return resp

36 changes: 22 additions & 14 deletions testing/tf-modules/lambda_deployment/main.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
locals {
name_from_runtime = replace(var.lambda_runtime, ".", "_")
lambda_function_path = "${var.build_dir}/${local.name_from_runtime}.zip"
lambda_function_name = "${var.resource_prefix}_${local.name_from_runtime}_apm_aws_lambda"
}

resource "aws_iam_role" "iam_for_lambda" {
name = "${var.resource_prefix}_apm_aws_lambda_iam"

Expand All @@ -25,23 +19,37 @@ EOF
}

resource "aws_lambda_layer_version" "extn_layer" {
count = var.custom_lambda_extension_arn == "" ? 1 : 0
filename = var.apm_aws_extension_path
layer_name = "${var.resource_prefix}_apm_aws_lambda_extn"
count = var.custom_lambda_extension_arn == "" ? 1 : 0
filename = var.apm_aws_extension_path
layer_name = "${var.resource_prefix}_apm_aws_lambda_extn"
source_code_hash = filebase64sha256(var.apm_aws_extension_path)
}

resource "aws_iam_role_policy_attachment" "cw" {
role = aws_iam_role.iam_for_lambda.name
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
}

resource "aws_cloudwatch_log_group" "cw_log_group" {
name = "/aws/lambda/${var.lambda_function_name}"
retention_in_days = 1
}

# TODO: @lahsivjar Add in cloudwatch integration for visualizing logs
resource "aws_lambda_function" "test_fn" {
filename = local.lambda_function_path
function_name = local.lambda_function_name
filename = var.lambda_function_zip
function_name = var.lambda_function_name
role = aws_iam_role.iam_for_lambda.arn
handler = var.lambda_handler
runtime = var.lambda_runtime
source_code_hash = filebase64sha256(local.lambda_function_path)
source_code_hash = filebase64sha256(var.lambda_function_zip)
layers = [var.custom_lambda_extension_arn == "" ? aws_lambda_layer_version.extn_layer[0].arn : var.custom_lambda_extension_arn]
timeout = var.lambda_timeout
memory_size = var.lambda_memory_size

depends_on = [
aws_cloudwatch_log_group.cw_log_group,
]

environment {
variables = {
ELASTIC_APM_LAMBDA_APM_SERVER = var.apm_server_url
Expand All @@ -52,7 +60,7 @@ resource "aws_lambda_function" "test_fn" {
}

resource "aws_apigatewayv2_api" "trigger" {
name = local.lambda_function_name
name = var.lambda_function_name
protocol_type = "HTTP"
description = "API Gateway to trigger lambda for testing apm-aws-lambda"
}
Expand Down
13 changes: 9 additions & 4 deletions testing/tf-modules/lambda_deployment/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@ variable "resource_prefix" {
description = "Prefix to add to all created resource"
}

variable "build_dir" {
variable "apm_aws_extension_path" {
type = string
description = "Prefix to add to all created resource"
description = "Path to the zip file containing extension code"
}

variable "apm_aws_extension_path" {
variable "lambda_function_zip" {
type = string
description = "Path to the zip file containing extension code"
description = "Path to the zip package containing the lambda function to deploy"
}

variable "lambda_function_name" {
type = string
description = "The name of the lambda function"
}

variable "lambda_runtime" {
Expand Down