-
Notifications
You must be signed in to change notification settings - Fork 1k
kinesis-lambda-terraform: Update runtime to nodejs22.x #2834
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
base: main
Are you sure you want to change the base?
Changes from all commits
a975a4e
f7dafae
c78da5e
bf1f11a
2d34cae
76f8e41
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
lambda.zip |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ terraform { | |
required_providers { | ||
aws = { | ||
source = "hashicorp/aws" | ||
version = "~> 4.22" | ||
version = "~> 5.0" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
} | ||
} | ||
|
||
|
@@ -17,12 +17,20 @@ resource "aws_kinesis_stream" "sample_stream" { | |
shard_count = 1 | ||
retention_period = 24 | ||
} | ||
|
||
data "archive_file" "lambda_zip_file" { | ||
type = "zip" | ||
source_file = "${path.module}/src/app.js" | ||
output_path = "${path.module}/lambda.zip" | ||
} | ||
|
||
resource "aws_lambda_function" "sample_lambda" { | ||
filename = "sample_lambda.zip" # Path to your Lambda code ZIP file | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note: The error occurred.
|
||
filename = data.archive_file.lambda_zip_file.output_path | ||
source_code_hash = data.archive_file.lambda_zip_file.output_base64sha256 | ||
function_name = "sample-lambda" | ||
role = aws_iam_role.lambda_role.arn | ||
handler = "index.handler" | ||
runtime = "nodejs16.x" # Change to your preferred runtime | ||
handler = "app.handler" | ||
runtime = "nodejs22.x" # Change to your preferred runtime | ||
} | ||
resource "aws_iam_role" "lambda_role" { | ||
name = "lambda-role" | ||
|
@@ -40,6 +48,44 @@ resource "aws_iam_role" "lambda_role" { | |
}) | ||
} | ||
|
||
resource "aws_iam_policy" "lambda_kinesis_policy" { | ||
name = "lambda-kinesis-policy" | ||
|
||
policy = jsonencode( | ||
{ | ||
Version = "2012-10-17", | ||
Statement = [ | ||
{ | ||
Effect = "Allow", | ||
Action = [ | ||
"kinesis:GetRecords", | ||
"kinesis:GetShardIterator", | ||
"kinesis:DescribeStream", | ||
"kinesis:DescribeStreamSummary", | ||
"kinesis:ListShards", | ||
"kinesis:ListStreams" | ||
], | ||
Resource = aws_kinesis_stream.sample_stream.arn | ||
}, | ||
{ | ||
Effect = "Allow", | ||
Action = [ | ||
"logs:CreateLogGroup", | ||
"logs:CreateLogStream", | ||
"logs:PutLogEvents" | ||
], | ||
Resource = "arn:aws:logs:*:*:*" | ||
} | ||
] | ||
} | ||
) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note: The error occurred.
|
||
|
||
resource "aws_iam_role_policy_attachment" "lambda_kinesis_policy_attachment" { | ||
role = aws_iam_role.lambda_role.name | ||
policy_arn = aws_iam_policy.lambda_kinesis_policy.arn | ||
} | ||
|
||
resource "aws_lambda_event_source_mapping" "sample_mapping" { | ||
event_source_arn = aws_kinesis_stream.sample_stream.arn | ||
function_name = aws_lambda_function.sample_lambda.arn | ||
|
@@ -52,6 +98,6 @@ output "kinesis_data_stream" { | |
} | ||
|
||
output "consumer_function" { | ||
value = aws_lambda_function.sample_function.arn | ||
value = aws_lambda_function.sample_lambda.arn | ||
description = "Consumer Function function name" | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: Fix to correct service name.