Skip to content

Commit 0118ebb

Browse files
authored
Merge pull request #2816 from kakakakakku/eventbridge-sns-lambda-terraform
eventbridge-sns-lambda-terraform: Update runtime to nodejs22.x
2 parents 84dbd92 + 7d0f3b0 commit 0118ebb

File tree

3 files changed

+11
-17
lines changed

3 files changed

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

eventbridge-sns-lambda-terraform/main.tf

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ terraform {
66
required_providers {
77
aws = {
88
source = "hashicorp/aws"
9-
version = "~> 3.27"
9+
version = "~> 5.0"
1010
}
1111
}
1212

@@ -103,15 +103,11 @@ resource "aws_lambda_function" "lambda_function" {
103103
source_code_hash = data.archive_file.lambda_zip_file.output_base64sha256
104104
handler = "app.handler"
105105
role = aws_iam_role.lambda_iam_role.arn
106-
runtime = "nodejs16.x"
106+
runtime = "nodejs22.x"
107107
}
108108

109-
110109
resource "aws_iam_role" "lambda_iam_role" {
111-
name_prefix = "LambdaSNSRole-"
112-
managed_policy_arns = [
113-
data.aws_iam_policy.lambda_basic_execution_role_policy.arn
114-
]
110+
name_prefix = "LambdaSNSRole-"
115111

116112
assume_role_policy = <<EOF
117113
{
@@ -130,6 +126,11 @@ resource "aws_iam_role" "lambda_iam_role" {
130126
EOF
131127
}
132128

129+
resource "aws_iam_role_policy_attachment" "lambda_basic_execution" {
130+
role = aws_iam_role.lambda_iam_role.name
131+
policy_arn = data.aws_iam_policy.lambda_basic_execution_role_policy.arn
132+
}
133+
133134
resource "aws_lambda_permission" "with_sns" {
134135
statement_id = "AllowExecutionFromSNS"
135136
action = "lambda:InvokeFunction"
@@ -138,10 +139,6 @@ resource "aws_lambda_permission" "with_sns" {
138139
source_arn = aws_sns_topic.MySNSTopic.arn
139140
}
140141

141-
142-
143-
144-
145142
//---------------------------------------------------------
146143
// Output
147144
//---------------------------------------------------------
@@ -160,4 +157,4 @@ output "SNS-Topic-ARN" {
160157
output "Lambda-function" {
161158
value = aws_lambda_function.lambda_function.arn
162159
description = "TopicSubscriberFunction function name"
163-
}
160+
}

eventbridge-sns-lambda-terraform/src/app.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@
22
* SPDX-License-Identifier: MIT-0
33
*/
44

5-
const AWS = require('aws-sdk')
6-
AWS.config.region = process.env.AWS_REGION
7-
const sns = new AWS.SNS({apiVersion: '2012-11-05'})
8-
95
// The Lambda handler
106
exports.handler = async (event) => {
117
console.log("Hello World !")
12-
}
8+
}

0 commit comments

Comments
 (0)