Skip to content
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions eventbridge-sns-lambda-terraform/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lambda.zip
21 changes: 9 additions & 12 deletions eventbridge-sns-lambda-terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 3.27"
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 @@ -103,15 +103,11 @@ resource "aws_lambda_function" "lambda_function" {
source_code_hash = data.archive_file.lambda_zip_file.output_base64sha256
handler = "app.handler"
role = aws_iam_role.lambda_iam_role.arn
runtime = "nodejs16.x"
runtime = "nodejs22.x"
}


resource "aws_iam_role" "lambda_iam_role" {
name_prefix = "LambdaSNSRole-"
managed_policy_arns = [
data.aws_iam_policy.lambda_basic_execution_role_policy.arn
]
name_prefix = "LambdaSNSRole-"

assume_role_policy = <<EOF
{
Expand All @@ -130,6 +126,11 @@ resource "aws_iam_role" "lambda_iam_role" {
EOF
}

resource "aws_iam_role_policy_attachment" "lambda_basic_execution" {
role = aws_iam_role.lambda_iam_role.name
policy_arn = data.aws_iam_policy.lambda_basic_execution_role_policy.arn
}
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: The managed_policy_arns argument is already deprecated. I update code correctly😀 See document below.


resource "aws_lambda_permission" "with_sns" {
statement_id = "AllowExecutionFromSNS"
action = "lambda:InvokeFunction"
Expand All @@ -138,10 +139,6 @@ resource "aws_lambda_permission" "with_sns" {
source_arn = aws_sns_topic.MySNSTopic.arn
}





//---------------------------------------------------------
// Output
//---------------------------------------------------------
Expand All @@ -160,4 +157,4 @@ output "SNS-Topic-ARN" {
output "Lambda-function" {
value = aws_lambda_function.lambda_function.arn
description = "TopicSubscriberFunction function name"
}
}
6 changes: 1 addition & 5 deletions eventbridge-sns-lambda-terraform/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
* SPDX-License-Identifier: MIT-0
*/

const AWS = require('aws-sdk')
AWS.config.region = process.env.AWS_REGION
const sns = new AWS.SNS({apiVersion: '2012-11-05'})
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 removed this because it wasn’t used.


// The Lambda handler
exports.handler = async (event) => {
console.log("Hello World !")
}
}