Skip to content

cloudinary-devs/web-listener-blueprint-aws

Repository files navigation

Cloudinary

A powerful media API for websites and mobile apps alike, Cloudinary enables developers to efficiently manage, transform, optimize, and deliver images and videos through multiple CDNs. Ultimately, viewers enjoy responsive and personalized visual-media experiences—irrespective of the viewing device.

Description

Cloudinary offers an easy-to-use listener for almost any type of Cloudinary extension. The package is on AWS Cloudformation, displaying the tag Hello World! for newly uploaded assets.

Prerequisites

To create a blueprint for a Cloudinary webhook listener, you need the following:

To create an Amazon S3 bucket, say, in the us-east-1 region, type:

export my_bucket=<my-bucket-name>
aws s3 mb s3://$my_bucket --region us-east-1
aws s3api put-bucket-encryption \
    --bucket $my_bucket \           
    --server-side-encryption-configuration '{"Rules": [{"ApplyServerSideEncryptionByDefault": {"SSEAlgorithm": "AES256"}}]}'
aws s3api put-public-access-block \
    --bucket $my_bucket \
    --public-access-block-configuration '{"BlockPublicAcls": true, "IgnorePublicAcls": true, "BlockPublicPolicy": true, "RestrictPublicBuckets": true}'

Installing

  1. Upload the repository’s ZIP files to your bucket with the command lines below. Alternatively, create the ZIP files yourself
aws s3 cp cldListenerUtils.zip s3://$my_bucket
aws s3 cp CloudinarySDK.zip s3://$my_bucket
aws s3 cp index.zip s3://$my_bucket
  1. Create a Cloudformation stack Create a Cloudformation stack by importing the serverless.yml file in the AWS Management Console. Alternatively, log in to a higher permission level and type the command lines below.
aws cloudformation deploy \
    --region us-east-1 \
    --template serverless.yml \
    --stack-name CloudinaryListener \
    --s3-bucket $my_bucket \
    --parameter-overrides CloudinaryListenerS3='$my_bucket' CloudinaryListenerUploadPrefix='https://api.cloudinary.com' \
    --capabilities CAPABILITY_IAM CAPABILITY_NAMED_IAM CAPABILITY_AUTO_EXPAND
  1. Configure the new web listener in Cloudinary
  • Check the Outputs section of the new Cloudformation stack and copy the cldListenerAPI.
  • In the Cloudinary console, paste the URL as the notification URL for the upload preset.
  1. Configure the Cloudinary credentials in AWS
  • Log in as a subaccount admin and copy the environment variable from the Cloudinary dashboard in the console. Click "reveal account details" near the top to display the environment variable.
  • Go to the AWS SecretsManager, edit the secret cldListenerSecret, and paste the environment variable as the secret's value.

Testing

  1. Ensure that the upload preset you configured is the default for ML or API uploads.
  2. Upload an asset to Cloudinary.
  3. Verify that the Hello World! tag is displayed for the asset.
  4. Confirm that the created log entries are displayed in CloudWatch.

Optional - Creation of Packages From Sources

You can create various Lambda layers to upgrade the current libraries, add libraries, or redistribute the main app code to, for example, a colleague or your IT DevOps team. Here are the command lines:

mkdir python
python3 -m pip install --target ./python cloudinary
zip -r9 CloudinarySDK.zip python
rm -rf python/*
cp cldListenerUtils.py python
zip -r9 cldListenerUtils.zip python
rm -rf python/*
zip -j9 index.zip index.py

Afterwards, upload all the ZIP files to your source bucket, as described in step 1 of the section on installation.

Files in distribution

  • CloudinarySDK.zip: Cloudinary’s Python SDK packaged as an AWS Lambda layer.
  • cldListenerUtils.py: A wrapper of the Cloudinary SDK and AWS SDK for abstracting and simplifying the web listener’s code.
  • cldListenerUtils.zip: The cldListenerUtils.py wrapper packaged as an AWS Lambda layer.
  • index.py: The blueprint’s sample code.
  • index.zip: index.py packaged as AWS Lambda code.
  • testEvent.json: A test event associated with the web listener Lambda for unit testing.
  • serverless.yml: The Cloudformation template.

About

A secured and optimized Cloudinary web listener in few clicks

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages