Skip to content

Commit 04dffe3

Browse files
authored
Merge pull request #2829 from kakakakakku/lambda-eventbridge-terraform
lambda-eventbridge-terraform: Update runtime to nodejs22.x
2 parents 25f979e + 917911f commit 04dffe3

3 files changed

Lines changed: 19 additions & 12 deletions

File tree

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

lambda-eventbridge-terraform/main.tf

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

@@ -29,7 +29,7 @@ resource "aws_lambda_function" "publisher_function" {
2929
source_code_hash = data.archive_file.lambda_zip_file.output_base64sha256
3030
handler = "app.handler"
3131
role = aws_iam_role.iam_for_lambda.arn
32-
runtime = "nodejs16.x"
32+
runtime = "nodejs22.x"
3333
}
3434

3535
data "archive_file" "lambda_zip_file" {
@@ -43,11 +43,7 @@ data "aws_iam_policy" "lambda_basic_execution_role_policy" {
4343
}
4444

4545
resource "aws_iam_role" "iam_for_lambda" {
46-
name_prefix = "PublisherFunctionRole-"
47-
managed_policy_arns = [
48-
data.aws_iam_policy.lambda_basic_execution_role_policy.arn,
49-
aws_iam_policy.event_bridge_put_events_policy.arn
50-
]
46+
name_prefix = "PublisherFunctionRole-"
5147

5248
assume_role_policy = <<EOF
5349
{
@@ -66,6 +62,16 @@ resource "aws_iam_role" "iam_for_lambda" {
6662
EOF
6763
}
6864

65+
resource "aws_iam_role_policy_attachment" "lambda_basic_execution" {
66+
role = aws_iam_role.iam_for_lambda.name
67+
policy_arn = data.aws_iam_policy.lambda_basic_execution_role_policy.arn
68+
}
69+
70+
resource "aws_iam_role_policy_attachment" "lambda_eventbridge" {
71+
role = aws_iam_role.iam_for_lambda.name
72+
policy_arn = aws_iam_policy.event_bridge_put_events_policy.arn
73+
}
74+
6975
data "aws_iam_policy_document" "event_bridge_put_events_policy_document" {
7076
statement {
7177

lambda-eventbridge-terraform/src/app.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44

55
'use strict'
66

7-
const AWS = require('aws-sdk')
8-
AWS.config.update({ region: process.env.AWS_REGION })
9-
const eventbridge = new AWS.EventBridge()
7+
const { EventBridgeClient, PutEventsCommand } = require('@aws-sdk/client-eventbridge')
8+
const eventbridge = new EventBridgeClient({ region: process.env.AWS_REGION })
109

1110
exports.handler = async (event) => {
1211
const params = {
@@ -23,7 +22,8 @@ exports.handler = async (event) => {
2322
}
2423
]
2524
}
25+
2626
// Publish to EventBridge
27-
const result = await eventbridge.putEvents(params).promise()
27+
const result = await eventbridge.send(new PutEventsCommand(params))
2828
console.log(result)
29-
}
29+
}

0 commit comments

Comments
 (0)