From f0d2585438fc5c0a51d3fa6a48e8db42bd40c572 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Taveira=20Ara=C3=BAjo?= Date: Thu, 22 Jun 2023 09:33:03 -0700 Subject: [PATCH] feat: select runtime / arch based off version We provide newer builds that can run on `provided.al2` for different architectures. These builds are under a GOARCH directory (e.g. `arm64/latest`). This commit identifies what runtime, handler and architecture to use based off of the version string. Will defer switching the default for `lambda_version` to a future release. --- main.tf | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/main.tf b/main.tf index 70fa79a..a90b16e 100644 --- a/main.tf +++ b/main.tf @@ -4,6 +4,27 @@ locals { lambda_iam_role_name = regex(".*role/(?P.*)$", local.lambda_iam_role_arn)["role_name"] s3_bucket = var.s3_bucket != "" ? var.s3_bucket : lookup(var.s3_regional_buckets, data.aws_region.current.name, local.default_lambda_bucket) s3_key = var.s3_key != "" ? var.s3_key : join("/", [var.s3_key_prefix, format("%s.zip", var.lambda_version)]) + + goarch = lookup( + { + "amd64" : { + architectures = ["x86_64"] + handler = "bootstrap" + runtime = "provided.al2" + } + "arm64" : { + architectures = ["arm64"] + handler = "bootstrap" + runtime = "provided.al2" + } + }, + split("/", var.lambda_version)[0], + { + architectures = null + handler = "main" + runtime = "go1.x" + }, + ) } data "aws_region" "current" {} @@ -15,11 +36,12 @@ resource "aws_lambda_function" "this" { s3_object_version = var.s3_object_version role = local.lambda_iam_role_arn - handler = "main" - runtime = "go1.x" - description = var.description - kms_key_arn = var.kms_key_arn - tags = var.tags + architectures = local.goarch.architectures + handler = local.goarch.handler + runtime = local.goarch.runtime + description = var.description + kms_key_arn = var.kms_key_arn + tags = var.tags memory_size = var.memory_size reserved_concurrent_executions = var.reserved_concurrent_executions < 0 ? null : var.reserved_concurrent_executions