View a markdown version of this page

Use the rewrite feature - Dynamic Image Transformation for Amazon CloudFront

Use the rewrite feature

You can use this solution’s rewrite feature to migrate your current image request model to the Dynamic Image Transformation for Amazon CloudFront solution, without changing the applications to accommodate new image URLs.

The rewrite feature translates custom URL image requests into Thumbor-consumable formats, based on JavaScript-compatible regular expression match patterns and substitution strings. After the image request is converted into Thumbor-consumable form, it’s then processed as a Thumbor image request and edits are mapped to the new sharp image library.

This feature requires that you populate the following environment variables in the image handler function. These environment variables are added to the function by default, but are left empty for user input if the rewrite feature is needed.

Variable Key Value Type Description

REWRITE_MATCH_PATTERN

Regex

By default, this parameter is empty. If you overwrite this default value, use a JavaScript-compatible regular expression for matching custom image requests using the rewrite function. This value should match the JavaScript compatible regular expression. For example, /(filters-)/gm.

REWRITE_SUBSTITUTION

String

By default, this parameter is empty. If you overwrite this default value, use a substitution string for custom image requests using the rewrite function. For example, filters:.

You can use any of the Thumbor-supported filters listed in this section with the rewrite feature. The following sections provide examples.