Skip to content

kinano/serverless-image-thumbnail-generator

Repository files navigation

Setup a Lambda function that optimizes images uploaded to an S3 bucket. The Lambda function will also generate thumbnails for every image uploaded to the S3 bucket.

The Lambda function gets executed automatically when a new file is uploaded to the source bucket.

-- Setup some environment variables
FUNC_NAME=ENTER_LAMBDA_FUNCTION_NAME
STATEMENT_ID=ENTER_NUMBER
SOURCE_BUCKET=ENTER_SOURCE_S3_BUCKET_NAME
SOURCE_AWS_ACCOUNT=ENTER_AWS_ACCOUNT_ID

-- Allow S3 to invoke our Lambda function on the source bucket
aws lambda add-permission --function-name $FUNC_NAME --principal s3.amazonaws.com --statement-id $STATEMENT_ID --action "lambda:InvokeFunction" --source-arn arn:aws:s3:::$SOURCE_BUCKET --source-account $SOURCE_AWS_ACCOUNT

-- Verify the policy
aws lambda get-policy --function-name $FUNC_NAME

python3 -m venv ./venv && pip3 install Pillow && pip3 freeze > requirements.txt
  • You can invoke a Lambda function locally using serverless
serverless invoke local --function $FUNC_NAME --path ./sample_data.json

About

Experiment with AWS Lambda, S3 & the Serverless framework

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages