/serverless-thumbnails-creator

AWS Lambda to process an Amazon S3 event input image. Resizes the image in the source bucket and save the output to the target bucket.

Primary LanguagePython

Serverless Thumbnail Creator

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.

AWS Serverless Thumbnail Creator

Follow this article in Youtube

  1. Prerequisites

  • AWS CLI pre-configured
  1. Clone the repository

    git clone https://github.com/miztiik/serverless-thumbnails-creator.git
  2. Customize the deployment

    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 section

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

  3. Deployment

    We will use the deploy.sh in the helper_scripts directory to deploy our AWS SAM template

    chmod +x ./helper_scripts/deploy*.sh
    ./helper_scripts/deploy.sh
  4. Test Event Processor

    Upload an object to the Source S3 Bucket created by the stack(The bucket name should be something like serverless-thumbnails-creator-srceventbucket-zwpgvaxxb3qh). You will be able to see the output in the Destination 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"
        }
      ]
    }

Contact Us

You can reach out to us to get more details through here.