Skip to content

Commit 764b458

Browse files
committed
feat: add boto3 Lambda layer support and integrate with existing Lambda functions
1 parent 43bc02d commit 764b458

2 files changed

Lines changed: 40 additions & 1 deletion

File tree

infrastructure/lambdas/process_build/index.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ def _generate_user_data(build_id, arch, python_version, requirements, single_fil
387387
388388
389389
def _mark_failed(reason):
390-
"""Best-effort: mark the build FAILED in DynamoDB."""
390+
# Best-effort: mark the build FAILED in DynamoDB.
391391
for attempt in range(3):
392392
try:
393393
table.update_item(

infrastructure/terraform/lambda.tf

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,42 @@
22
# Lambda Functions
33
# =============================================================================
44

5+
# =============================================================================
6+
# boto3 Lambda Layer (Python 3.13 no longer bundles the AWS SDK)
7+
# =============================================================================
8+
9+
resource "null_resource" "boto3_layer" {
10+
triggers = {
11+
requirements = filesha256("${path.module}/boto3_layer_requirements.txt")
12+
}
13+
14+
provisioner "local-exec" {
15+
command = <<-EOT
16+
rm -rf ${path.module}/.build/boto3_layer
17+
mkdir -p ${path.module}/.build/boto3_layer/python
18+
pip3 install \
19+
-r ${path.module}/boto3_layer_requirements.txt \
20+
-t ${path.module}/.build/boto3_layer/python \
21+
--quiet
22+
EOT
23+
}
24+
}
25+
26+
data "archive_file" "boto3_layer" {
27+
type = "zip"
28+
source_dir = "${path.module}/.build/boto3_layer"
29+
output_path = "${path.module}/.build/boto3_layer.zip"
30+
depends_on = [null_resource.boto3_layer]
31+
}
32+
33+
resource "aws_lambda_layer_version" "boto3" {
34+
filename = data.archive_file.boto3_layer.output_path
35+
layer_name = "${local.name_prefix}-boto3"
36+
source_code_hash = data.archive_file.boto3_layer.output_base64sha256
37+
38+
compatible_runtimes = ["python3.13"]
39+
}
40+
541
# Package Lambda source code into zip archives
642
data "archive_file" "submit_build" {
743
type = "zip"
@@ -35,6 +71,7 @@ resource "aws_lambda_function" "submit_build" {
3571
timeout = 30
3672
memory_size = 128
3773
role = aws_iam_role.lambda_submit.arn
74+
layers = [aws_lambda_layer_version.boto3.arn]
3875

3976
environment {
4077
variables = {
@@ -68,6 +105,7 @@ resource "aws_lambda_function" "process_build" {
68105
timeout = 60
69106
memory_size = 256
70107
role = aws_iam_role.lambda_process.arn
108+
layers = [aws_lambda_layer_version.boto3.arn]
71109

72110
environment {
73111
variables = {
@@ -121,6 +159,7 @@ resource "aws_lambda_function" "check_status" {
121159
timeout = 15
122160
memory_size = 128
123161
role = aws_iam_role.lambda_status.arn
162+
layers = [aws_lambda_layer_version.boto3.arn]
124163

125164
environment {
126165
variables = {

0 commit comments

Comments
 (0)