Skip to content

Commit 55de666

Browse files
authored
Fix Lambda S3 bucket cross-region access error (#9)
* Fix Lambda S3 bucket cross-region access error The agent-scaler Lambda was using a hardcoded "buildkite-lambdas" bucket, causing PermanentRedirect errors in regions outside us-east-1. Now uses region-specific buckets (e.g., buildkite-lambdas-us-west-2), incorporating the mapping from agent-scaler's SAM template (https://github.com/buildkite/buildkite-agent-scaler/blob/ac0883ab632a8689384ec8991c6415f8f3b48052/template.yaml#L166-L187). * Use ternary to construct bucket name instead of relying on mapping
1 parent 90e3ecc commit 55de666

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

agent-scaler.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ resource "aws_lambda_function" "scaler" {
55
function_name = "${local.stack_name_full}-scaler"
66
description = "Scales ${aws_autoscaling_group.agent_auto_scale_group.name} based on Buildkite metrics"
77

8-
s3_bucket = "buildkite-lambdas"
8+
s3_bucket = local.agent_scaler_s3_bucket
99
s3_key = "buildkite-agent-scaler/v${var.buildkite_agent_scaler_version}/handler.zip"
1010

1111
handler = "bootstrap"

locals.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ locals {
6363
cloudformation_stack_version = "v6.46.0"
6464
}
6565

66+
# Region-specific Lambda deployment bucket
67+
# us-east-1 uses "buildkite-lambdas", all other regions append the region suffix
68+
agent_scaler_s3_bucket = data.aws_region.current.id == "us-east-1" ? "buildkite-lambdas" : "buildkite-lambdas-${data.aws_region.current.id}"
69+
6670
# Detect ARM and burstable instances from instance type family
6771
instance_type_family = split(".", split(",", var.instance_types)[0])[0]
6872

0 commit comments

Comments
 (0)