Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions terraform-s3-object-lambda/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ aws s3 cp ./images/sample.jpg s3://<bucket-name>
Download a thumbnail version of the uploaded image from the S3 Object Lambda Access Point using this command (replace `<lambda-access-point>` with the value returned in `s3_lambda_access_point`):

```shell
mkdir ./thumbs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: I added mkdir command because it had the following error.

$ aws s3api get-object --bucket decent-raccoon-bucket --key sample.jpg ./thumbs/sample-thumbnail.jpg --region eu-west-1
[Errno 2] No such file or directory: './thumbs/sample-thumbnail.jpg'

aws s3api get-object --bucket <lambda-access-point> --key sample.jpg ./thumbs/sample-thumbnail.jpg

open ./thumbs/sample-thumbnail.jpg
Expand Down
2 changes: 1 addition & 1 deletion terraform-s3-object-lambda/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 4 additions & 4 deletions terraform-s3-object-lambda/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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));
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.


// Exit the Lambda function.
return { statusCode: 200 };
Expand Down