Lets say, we have to create thumbnails, profile picture for the images uploaded by users. We can use S3 Event notification along with lambda function to do it.
Follow this article in Youtube
- AWS CLI pre-configured
-
git clone https://github.com/miztiik/serverless-thumbnails-creator.git
-
In the
serverless-thumbnails-creator
directory, Edit the./helper_scripts/deploy.sh
to update your environment variables.You will have to create an S3 bucket in your account and update the
BUCKET_NAME
in the below sectionAWS_PROFILE="default" AWS_REGION="us-east-1" BUCKET_NAME="YOUR-BUCKET-NAME-GOES-HERE" # bucket must exist in the SAME region the deployment is taking place SERVICE_NAME="serverless-thumbnails-creator" TEMPLATE_NAME="${SERVICE_NAME}.yaml" STACK_NAME="${SERVICE_NAME}" OUTPUT_DIR="./outputs/" PACKAGED_OUTPUT_TEMPLATE="${OUTPUT_DIR}${STACK_NAME}-packaged-template.yaml"
Save the file.
-
We will use the
deploy.sh
in thehelper_scripts
directory to deploy our AWS SAM templatechmod +x ./helper_scripts/deploy*.sh ./helper_scripts/deploy.sh
-
Upload an object to the
Source S3 Bucket
created by the stack(The bucket name should be something likeserverless-thumbnails-creator-srceventbucket-zwpgvaxxb3qh
). You will be able to see the output in theDestination S3 Bucket
(In your account*tgtbucket
) three directories with resized images. In the lambda logs you will see the following output{ "status": "True", "TotalItems": { "Received": 1, "Processed": 1 }, "Items": [ { "time": "2019-05-09T18:02:24.534Z", "object_owner": "AWS:AIDAUR7KWXJQLWZZ56LRA", "bucket_name": "serverless-thumbnails-creator-srceventbucket-zwpgvaxxb3qh", "key": "wt-cloudtrail-100.png" } ] }
You can reach out to us to get more details through here.