Skip to content

lambda-sns-terraform: Update runtime to nodejs22.x #2815

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 4 commits into
base: main
Choose a base branch
from
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 lambda-sns-terraform/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lambda.zip
24 changes: 15 additions & 9 deletions lambda-sns-terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 4.22"
version = "~> 5.0"
}
}

Expand All @@ -22,7 +22,7 @@ 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"
environment {
variables = {
SNStopic = aws_sns_topic.sns_topic.arn
Expand All @@ -41,11 +41,7 @@ data "aws_iam_policy" "lambda_basic_execution_role_policy" {
}

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

assume_role_policy = <<EOF
{
Expand All @@ -64,11 +60,21 @@ 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
}

resource "aws_iam_role_policy_attachment" "lambda_sqs" {
role = aws_iam_role.lambda_iam_role.name
policy_arn = aws_iam_policy.lambda_policy.arn
}

data "aws_iam_policy_document" "lambda_policy_document" {
statement {

effect = "Allow"

actions = [
"sns:Publish"
]
Expand Down
12 changes: 7 additions & 5 deletions lambda-sns-terraform/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
* 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'})
const { SNSClient, PublishCommand } = require('@aws-sdk/client-sns')

const snsClient = new SNSClient({
region: process.env.AWS_REGION
})

// The Lambda handler
exports.handler = async (event) => {
Expand All @@ -16,6 +18,6 @@ exports.handler = async (event) => {
}

// Send to SNS
const result = await sns.publish(params).promise()
const result = await snsClient.send(new PublishCommand(params))
console.log(result)
}
}