Skip to content

alb-lambda-terraform: Update runtime to nodejs22.x #2803

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
7 changes: 4 additions & 3 deletions alb-lambda-terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~>4.52.0"
version = "~> 5.0"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: Older version does not support Node.js 22 runtime. So I updated the version to v5.

}
}

Expand Down Expand Up @@ -172,12 +172,13 @@ resource "aws_lb_target_group" "target_group" {
resource "aws_lb_target_group_attachment" "target_group_attachment" {
target_group_arn = aws_lb_target_group.target_group.arn
target_id = aws_lambda_function.lambda_function.arn
depends_on = [aws_lambda_permission.with_lb]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: I ran it twice, but I got an error both times.
So I added a dependency to wait for the aws_lambda_permission to be created.

first time

╷
│ Error: registering ELBv2 Target Group (arn:aws:elasticloadbalancing:us-east-1:000000000000:targetgroup/myLoadBalancerTargets/b89189d18213fa66) target: operation error Elastic Load Balancing v2: RegisterTargets, https response error StatusCode: 403, RequestID: f93d0159-c46d-4d61-a61f-ed598370fa3a, api error AccessDenied: elasticloadbalancing principal does not have permission to invoke arn:aws:lambda:us-east-1:000000000000:function:lambdaFunction from target group arn:aws:elasticloadbalancing:us-east-1:000000000000:targetgroup/myLoadBalancerTargets/b89189d18213fa66
│ 
│   with aws_lb_target_group_attachment.target_group_attachment,
│   on main.tf line 172, in resource "aws_lb_target_group_attachment" "target_group_attachment":
│  172: resource "aws_lb_target_group_attachment" "target_group_attachment" {
│ 
╵

second time

╷
│ Error: registering ELBv2 Target Group (arn:aws:elasticloadbalancing:us-east-1:000000000000:targetgroup/myLoadBalancerTargets/e9982eccdfc51ac0) target: operation error Elastic Load Balancing v2: RegisterTargets, https response error StatusCode: 403, RequestID: 03bb7f6d-cc4c-4806-bc8e-e6bd643707bf, api error AccessDenied: elasticloadbalancing principal does not have permission to invoke arn:aws:lambda:us-east-1:000000000000:function:lambdaFunction from target group arn:aws:elasticloadbalancing:us-east-1:000000000000:targetgroup/myLoadBalancerTargets/e9982eccdfc51ac0
│ 
│   with aws_lb_target_group_attachment.target_group_attachment,
│   on main.tf line 172, in resource "aws_lb_target_group_attachment" "target_group_attachment":
│  172: resource "aws_lb_target_group_attachment" "target_group_attachment" {
│ 
╵

}

# Create the Lambda Function
resource "aws_lambda_function" "lambda_function" {
function_name = "lambdaFunction"
runtime = "nodejs16.x"
runtime = "nodejs22.x"
handler = "index.handler"
filename = "lambda.zip"
role = aws_iam_role.lambda_role.arn
Expand All @@ -194,4 +195,4 @@ resource "aws_lambda_permission" "with_lb" {
function_name = aws_lambda_function.lambda_function.arn
principal = "elasticloadbalancing.amazonaws.com"
source_arn = aws_lb_target_group.target_group.arn
}
}