Skip to content

Commit ab3c13f

Browse files
author
João Taveira Araújo
committed
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.
1 parent 665da06 commit ab3c13f

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

main.tf

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,26 @@ locals {
44
lambda_iam_role_name = regex(".*role/(?P<role_name>.*)$", local.lambda_iam_role_arn)["role_name"]
55
s3_bucket = var.s3_bucket != "" ? var.s3_bucket : lookup(var.s3_regional_buckets, data.aws_region.current.name, local.default_lambda_bucket)
66
s3_key = var.s3_key != "" ? var.s3_key : join("/", [var.s3_key_prefix, format("%s.zip", var.lambda_version)])
7+
8+
goarch = lookup({
9+
"amd64" : {
10+
architectures = ["x86_64"]
11+
handler = "bootstrap"
12+
runtime = "provided.al2"
13+
}
14+
"arm64" : {
15+
architectures = ["arm64"]
16+
handler = "bootstrap"
17+
runtime = "provided.al2"
18+
}
19+
},
20+
split("/", var.lambda_version)[0],
21+
{
22+
architectures = null
23+
handler = "main"
24+
runtime = "go1.x"
25+
},
26+
)
727
}
828

929
data "aws_region" "current" {}
@@ -15,11 +35,12 @@ resource "aws_lambda_function" "this" {
1535
s3_object_version = var.s3_object_version
1636
role = local.lambda_iam_role_arn
1737

18-
handler = "main"
19-
runtime = "go1.x"
20-
description = var.description
21-
kms_key_arn = var.kms_key_arn
22-
tags = var.tags
38+
architectures = local.goarch.architectures
39+
handler = local.goarch.handler
40+
runtime = local.goarch.runtime
41+
description = var.description
42+
kms_key_arn = var.kms_key_arn
43+
tags = var.tags
2344

2445
memory_size = var.memory_size
2546
reserved_concurrent_executions = var.reserved_concurrent_executions < 0 ? null : var.reserved_concurrent_executions

versions.tf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ terraform {
22
required_version = ">= 1.1.0"
33

44
required_providers {
5-
aws = ">= 2.68"
5+
aws = {
6+
version = ">= 2.68"
7+
}
68
}
79
}

0 commit comments

Comments
 (0)