-
Notifications
You must be signed in to change notification settings - Fork 996
lambda-ssm-parameter-terraform: Update runtime to nodejs22.x #2814
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
a0e806f
5c4dc72
df47400
b4de213
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" | ||
} | ||
} | ||
|
||
|
@@ -31,7 +31,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 = { | ||
SSMParameterName = var.ssm_parameter_name | ||
|
@@ -50,11 +50,7 @@ data "aws_iam_policy" "lambda_basic_execution_role_policy" { | |
} | ||
|
||
resource "aws_iam_role" "lambda_iam_role" { | ||
name_prefix = "LambdaSSMParameterRole-" | ||
managed_policy_arns = [ | ||
data.aws_iam_policy.lambda_basic_execution_role_policy.arn, | ||
aws_iam_policy.lambda_policy.arn | ||
] | ||
name_prefix = "LambdaSSMParameterRole-" | ||
|
||
assume_role_policy = <<EOF | ||
{ | ||
|
@@ -73,11 +69,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 | ||
} | ||
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" "lambda_policy_document" { | ||
statement { | ||
|
||
effect = "Allow" | ||
|
||
actions = [ | ||
"ssm:GetParameter", | ||
"ssm:PutParameter" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,8 +6,11 @@ | |
// 2. GET or PUT an SSM Parameter Store parameter. | ||
// 3. Return a response with parameter result. | ||
|
||
const AWS = require("aws-sdk") | ||
const ssm = new AWS.SSM() | ||
const { SSMClient, GetParameterCommand, PutParameterCommand } = require('@aws-sdk/client-ssm') | ||
|
||
const ssmClient = new SSMClient({ | ||
region: process.env.AWS_REGION | ||
}) | ||
|
||
exports.handler = async (event, context) => { | ||
try { | ||
|
@@ -34,12 +37,12 @@ exports.handler = async (event, context) => { | |
Overwrite: true, | ||
Type: "String", | ||
}; | ||
result = await ssm.putParameter(ssmPutParams).promise() | ||
result = await ssmClient.send(new PutParameterCommand(ssmPutParams)) | ||
} else if (method == "GET") { | ||
const ssmGetParams = { | ||
Name: parameterName, | ||
}; | ||
result = await ssm.getParameter(ssmGetParams).promise() | ||
result = await ssmClient.send(new GetParameterCommand(ssmGetParams)) | ||
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. |
||
} else { | ||
result = "Method not supported" | ||
} | ||
|
@@ -57,4 +60,4 @@ exports.handler = async (event, context) => { | |
console.error(error); | ||
throw new Error(error); | ||
} | ||
} | ||
} |
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.