Skip to content

Commit d8c6928

Browse files
authored
Merge pull request #2813 from kakakakakku/lambda-sqs-terraform
lambda-sqs-terraform: Update runtime to nodejs22.x
2 parents adadcaf + 793c4ab commit d8c6928

File tree

3 files changed

+24
-14
lines changed

3 files changed

+24
-14
lines changed

lambda-sqs-terraform/.gitignore

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

lambda-sqs-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
SQSqueueName = aws_sqs_queue.sqs_queue.url
@@ -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 = "LambdaSQSRole-"
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 = "LambdaSQSRole-"
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
"sqs:SendMessage*"
7480
]

lambda-sqs-terraform/src/app.js

Lines changed: 8 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 sqs = new AWS.SQS({apiVersion: '2012-11-05'})
5+
const { SQSClient, SendMessageCommand } = require('@aws-sdk/client-sqs')
6+
7+
const sqsClient = new SQSClient({
8+
region: process.env.AWS_REGION
9+
})
810

911
// The Lambda handler
1012
exports.handler = async (event) => {
@@ -15,6 +17,7 @@ exports.handler = async (event) => {
1517
}
1618

1719
// Send to SQS
18-
const result = await sqs.sendMessage(params).promise()
20+
const command = new SendMessageCommand(params)
21+
const result = await sqsClient.send(command)
1922
console.log(result)
20-
}
23+
}

0 commit comments

Comments
 (0)