Skip to content

Commit adadcaf

Browse files
authored
Merge pull request #2815 from kakakakakku/lambda-sns-terraform
lambda-sns-terraform: Update runtime to nodejs22.x
2 parents 96ba72e + d408928 commit adadcaf

File tree

3 files changed

+23
-14
lines changed

3 files changed

+23
-14
lines changed

lambda-sns-terraform/.gitignore

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

lambda-sns-terraform/main.tf

Lines changed: 15 additions & 9 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

@@ -22,7 +22,7 @@ resource "aws_lambda_function" "lambda_function" {
2222
source_code_hash = data.archive_file.lambda_zip_file.output_base64sha256
2323
handler = "app.handler"
2424
role = aws_iam_role.lambda_iam_role.arn
25-
runtime = "nodejs16.x"
25+
runtime = "nodejs22.x"
2626
environment {
2727
variables = {
2828
SNStopic = aws_sns_topic.sns_topic.arn
@@ -41,11 +41,7 @@ data "aws_iam_policy" "lambda_basic_execution_role_policy" {
4141
}
4242

4343
resource "aws_iam_role" "lambda_iam_role" {
44-
name_prefix = "LambdaSNSRole-"
45-
managed_policy_arns = [
46-
data.aws_iam_policy.lambda_basic_execution_role_policy.arn,
47-
aws_iam_policy.lambda_policy.arn
48-
]
44+
name_prefix = "LambdaSNSRole-"
4945

5046
assume_role_policy = <<EOF
5147
{
@@ -64,11 +60,21 @@ resource "aws_iam_role" "lambda_iam_role" {
6460
EOF
6561
}
6662

63+
resource "aws_iam_role_policy_attachment" "lambda_basic_execution" {
64+
role = aws_iam_role.lambda_iam_role.name
65+
policy_arn = data.aws_iam_policy.lambda_basic_execution_role_policy.arn
66+
}
67+
68+
resource "aws_iam_role_policy_attachment" "lambda_sqs" {
69+
role = aws_iam_role.lambda_iam_role.name
70+
policy_arn = aws_iam_policy.lambda_policy.arn
71+
}
72+
6773
data "aws_iam_policy_document" "lambda_policy_document" {
6874
statement {
69-
75+
7076
effect = "Allow"
71-
77+
7278
actions = [
7379
"sns:Publish"
7480
]

lambda-sns-terraform/src/app.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
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'})
5+
const { SNSClient, PublishCommand } = require('@aws-sdk/client-sns')
6+
7+
const snsClient = new SNSClient({
8+
region: process.env.AWS_REGION
9+
})
810

911
// The Lambda handler
1012
exports.handler = async (event) => {
@@ -16,6 +18,6 @@ exports.handler = async (event) => {
1618
}
1719

1820
// Send to SNS
19-
const result = await sns.publish(params).promise()
21+
const result = await snsClient.send(new PublishCommand(params))
2022
console.log(result)
21-
}
23+
}

0 commit comments

Comments
 (0)