diff --git a/terraform-s3-object-lambda/README.md b/terraform-s3-object-lambda/README.md index 251c15613..64b978053 100644 --- a/terraform-s3-object-lambda/README.md +++ b/terraform-s3-object-lambda/README.md @@ -28,6 +28,8 @@ aws s3 cp ./images/sample.jpg s3:// Download a thumbnail version of the uploaded image from the S3 Object Lambda Access Point using this command (replace `` with the value returned in `s3_lambda_access_point`): ```shell +mkdir ./thumbs + aws s3api get-object --bucket --key sample.jpg ./thumbs/sample-thumbnail.jpg open ./thumbs/sample-thumbnail.jpg diff --git a/terraform-s3-object-lambda/main.tf b/terraform-s3-object-lambda/main.tf index be3eac48c..5dbc2d26b 100644 --- a/terraform-s3-object-lambda/main.tf +++ b/terraform-s3-object-lambda/main.tf @@ -19,7 +19,7 @@ module "lambda_function" { function_name = "${random_pet.this.id}-lambda" description = "My awesome lambda function" handler = "app.handler" - runtime = "nodejs16.x" + runtime = "nodejs22.x" publish = true architectures = ["arm64"] # Set to "arm64" if you are running this from ARM, else use "x86_64" diff --git a/terraform-s3-object-lambda/src/app.js b/terraform-s3-object-lambda/src/app.js index 2897f2f08..699d46b7c 100644 --- a/terraform-s3-object-lambda/src/app.js +++ b/terraform-s3-object-lambda/src/app.js @@ -2,11 +2,11 @@ * SPDX-License-Identifier: MIT-0 */ -const { S3 } = require("aws-sdk"); +const { S3Client, WriteGetObjectResponseCommand } = require("@aws-sdk/client-s3"); const axios = require("axios").default; // Promise-based HTTP requests const sharp = require("sharp"); // Used for image resizing -const s3 = new S3(); +const s3 = new S3Client(); exports.handler = async (event) => { // Output the event details to CloudWatch Logs. @@ -30,9 +30,9 @@ exports.handler = async (event) => { const params = { RequestRoute: outputRoute, RequestToken: outputToken, - Body: resized, + Body: await resized.toBuffer(), }; - await s3.writeGetObjectResponse(params).promise(); + await s3.send(new WriteGetObjectResponseCommand(params)); // Exit the Lambda function. return { statusCode: 200 };