-
Notifications
You must be signed in to change notification settings - Fork 1k
lambda-eventbridge-terraform: Update runtime to nodejs22.x #2829
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
base: main
Are you sure you want to change the base?
Changes from all commits
da55c7c
d3080b8
98b5815
917911f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| lambda.zip |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,7 @@ terraform { | |
| required_providers { | ||
| aws = { | ||
| source = "hashicorp/aws" | ||
| version = "~> 4.22" | ||
| version = "~> 5.0" | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -29,7 +29,7 @@ resource "aws_lambda_function" "publisher_function" { | |
| source_code_hash = data.archive_file.lambda_zip_file.output_base64sha256 | ||
| handler = "app.handler" | ||
| role = aws_iam_role.iam_for_lambda.arn | ||
| runtime = "nodejs16.x" | ||
| runtime = "nodejs22.x" | ||
| } | ||
|
|
||
| data "archive_file" "lambda_zip_file" { | ||
|
|
@@ -43,11 +43,7 @@ data "aws_iam_policy" "lambda_basic_execution_role_policy" { | |
| } | ||
|
|
||
| resource "aws_iam_role" "iam_for_lambda" { | ||
| name_prefix = "PublisherFunctionRole-" | ||
| managed_policy_arns = [ | ||
| data.aws_iam_policy.lambda_basic_execution_role_policy.arn, | ||
| aws_iam_policy.event_bridge_put_events_policy.arn | ||
| ] | ||
| name_prefix = "PublisherFunctionRole-" | ||
|
|
||
| assume_role_policy = <<EOF | ||
| { | ||
|
|
@@ -66,6 +62,16 @@ resource "aws_iam_role" "iam_for_lambda" { | |
| EOF | ||
| } | ||
|
|
||
| resource "aws_iam_role_policy_attachment" "lambda_basic_execution" { | ||
| role = aws_iam_role.iam_for_lambda.name | ||
| policy_arn = data.aws_iam_policy.lambda_basic_execution_role_policy.arn | ||
| } | ||
|
|
||
| resource "aws_iam_role_policy_attachment" "lambda_eventbridge" { | ||
| role = aws_iam_role.iam_for_lambda.name | ||
| policy_arn = aws_iam_policy.event_bridge_put_events_policy.arn | ||
| } | ||
|
|
||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note: The |
||
| data "aws_iam_policy_document" "event_bridge_put_events_policy_document" { | ||
| statement { | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,9 +4,8 @@ | |
|
|
||
| 'use strict' | ||
|
|
||
| const AWS = require('aws-sdk') | ||
| AWS.config.update({ region: process.env.AWS_REGION }) | ||
| const eventbridge = new AWS.EventBridge() | ||
| const { EventBridgeClient, PutEventsCommand } = require('@aws-sdk/client-eventbridge') | ||
| const eventbridge = new EventBridgeClient({ region: process.env.AWS_REGION }) | ||
|
|
||
| exports.handler = async (event) => { | ||
| const params = { | ||
|
|
@@ -23,7 +22,8 @@ exports.handler = async (event) => { | |
| } | ||
| ] | ||
| } | ||
|
|
||
| // Publish to EventBridge | ||
| const result = await eventbridge.putEvents(params).promise() | ||
| const result = await eventbridge.send(new PutEventsCommand(params)) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note: Some error occurs. Because in Node.js 18 and later runtimes, AWS SDK v3 is bundled, so I rewrote it to v3. See articles below. |
||
| console.log(result) | ||
| } | ||
| } | ||
There was a problem hiding this comment.
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.