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.
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.
To create a blueprint for a Cloudinary webhook listener, you need the following:
- A Cloudinary account
- An AWS account
- The AWS command-line interface (CLI)
- An S3 bucket to host the artifacts uploaded by Cloudformation, e.g., Lambda's ZIP-deployment packages.
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}'
- 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
- 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
- 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.
- 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.
- Ensure that the upload preset you configured is the default for ML or API uploads.
- Upload an asset to Cloudinary.
- Verify that the
Hello World!
tag is displayed for the asset. - Confirm that the created log entries are displayed in CloudWatch.
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.
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
: ThecldListenerUtils.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.