This repository contains the code for an AWS Lambda function designed to automatically process image uploads to an S3 bucket. The Lambda function is triggered whenever an image is uploaded to the specified S3 bucket. It retrieves metadata about the uploaded image, updates a images.json file stored in the bucket, and then re-uploads the updated images.json file.
- Trigger: The Lambda function is triggered by S3 events, specifically
ObjectCreatedevents. - Metadata Extraction: Upon trigger, the function extracts metadata (name, size, type) of the uploaded image.
- JSON File Update: It retrieves the existing
images.jsonfile from the S3 bucket, adds the metadata of the newly uploaded image to it, and then uploads the updatedimages.jsonfile back to the bucket. - Dependencies: The function uses the AWS SDK v3 (
@aws-sdk/client-s3) for S3 interaction andnode-fetchfor handling responses.
- Lambda Function: Create a new Lambda function in your AWS account.
- Trigger Configuration: Configure the Lambda function to be triggered by S3 events (ObjectCreated) in the desired bucket.
- Dependencies: Ensure that the
aws-sdkandnode-fetchdependencies are included in your deployment package (package.json). - Permissions: Grant necessary permissions to the Lambda function to interact with S3 buckets.
- Testing: Upload an image to the specified S3 bucket and verify that the Lambda function is triggered and the
images.jsonfile is updated accordingly.
index.js: Contains the Lambda function code.package.json: Lists project dependencies.
- Error Handling: The Lambda function includes basic error handling to handle cases where S3 object retrieval or file upload fails.
- Testing: It's recommended to test the Lambda function thoroughly to ensure proper functionality.
- Qilin Xie
This project is licensed under the ISC License.