Skip to content

Commit 5bf6432

Browse files
authored
Merge pull request #2834 from kakakakakku/kinesis-lambda-terraform
kinesis-lambda-terraform: Update runtime to nodejs22.x
2 parents a4314e6 + 76f8e41 commit 5bf6432

3 files changed

Lines changed: 56 additions & 9 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
lambda.zip

kinesis-lambda-terraform/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# AWS Kinesis Data Streams to AWS Lambda
1+
# Amazon Kinesis Data Streams to AWS Lambda
22

3-
This pattern creates an AWS Kinesis Data Stream, a stream consumer, and an AWS Lambda function. When data is added to the stream, the Lambda function is invoked.
3+
This pattern creates an AWS Kinesis Data Streams, a stream consumer, and an AWS Lambda function. When data is added to the stream, the Lambda function is invoked.
44

55
Learn more about this pattern at Serverless Land Patterns: [https://serverlessland.com/patterns/kinesis-to-lambda-terraform](https://serverlessland.com/patterns/kinesis-to-lambda-terraform)
66

@@ -83,4 +83,4 @@ When you are logged in, you can generate data for your stream test.
8383
```
8484
8585
----
86-
Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.
86+
Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.

kinesis-lambda-terraform/main.tf

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ terraform {
22
required_providers {
33
aws = {
44
source = "hashicorp/aws"
5-
version = "~> 4.22"
5+
version = "~> 5.0"
66
}
77
}
88

@@ -17,12 +17,20 @@ resource "aws_kinesis_stream" "sample_stream" {
1717
shard_count = 1
1818
retention_period = 24
1919
}
20+
21+
data "archive_file" "lambda_zip_file" {
22+
type = "zip"
23+
source_file = "${path.module}/src/app.js"
24+
output_path = "${path.module}/lambda.zip"
25+
}
26+
2027
resource "aws_lambda_function" "sample_lambda" {
21-
filename = "sample_lambda.zip" # Path to your Lambda code ZIP file
28+
filename = data.archive_file.lambda_zip_file.output_path
29+
source_code_hash = data.archive_file.lambda_zip_file.output_base64sha256
2230
function_name = "sample-lambda"
2331
role = aws_iam_role.lambda_role.arn
24-
handler = "index.handler"
25-
runtime = "nodejs16.x" # Change to your preferred runtime
32+
handler = "app.handler"
33+
runtime = "nodejs22.x" # Change to your preferred runtime
2634
}
2735
resource "aws_iam_role" "lambda_role" {
2836
name = "lambda-role"
@@ -40,6 +48,44 @@ resource "aws_iam_role" "lambda_role" {
4048
})
4149
}
4250

51+
resource "aws_iam_policy" "lambda_kinesis_policy" {
52+
name = "lambda-kinesis-policy"
53+
54+
policy = jsonencode(
55+
{
56+
Version = "2012-10-17",
57+
Statement = [
58+
{
59+
Effect = "Allow",
60+
Action = [
61+
"kinesis:GetRecords",
62+
"kinesis:GetShardIterator",
63+
"kinesis:DescribeStream",
64+
"kinesis:DescribeStreamSummary",
65+
"kinesis:ListShards",
66+
"kinesis:ListStreams"
67+
],
68+
Resource = aws_kinesis_stream.sample_stream.arn
69+
},
70+
{
71+
Effect = "Allow",
72+
Action = [
73+
"logs:CreateLogGroup",
74+
"logs:CreateLogStream",
75+
"logs:PutLogEvents"
76+
],
77+
Resource = "arn:aws:logs:*:*:*"
78+
}
79+
]
80+
}
81+
)
82+
}
83+
84+
resource "aws_iam_role_policy_attachment" "lambda_kinesis_policy_attachment" {
85+
role = aws_iam_role.lambda_role.name
86+
policy_arn = aws_iam_policy.lambda_kinesis_policy.arn
87+
}
88+
4389
resource "aws_lambda_event_source_mapping" "sample_mapping" {
4490
event_source_arn = aws_kinesis_stream.sample_stream.arn
4591
function_name = aws_lambda_function.sample_lambda.arn
@@ -52,6 +98,6 @@ output "kinesis_data_stream" {
5298
}
5399

54100
output "consumer_function" {
55-
value = aws_lambda_function.sample_function.arn
101+
value = aws_lambda_function.sample_lambda.arn
56102
description = "Consumer Function function name"
57-
}
103+
}

0 commit comments

Comments
 (0)