Skip to content

aws-samples/s3-object-lambda-image-transformer

S3 Object Lambda Image Transformer

This repository contains sample code for constructing a Content Delivery Network (CDN) to deliver images from S3. By utilizing S3 Object Lambda, you can transform aspects such as the image size, quality, and format. The implementation of the Lambda function uses Sharp.

Deployment Procedure

Install the npm modules.

npm install

This project uses the AWS CDK. If you haven't completed the bootstrap process, you can do so using the following command:

npx cdk bootstrap

Deploy using CDK.

npx cdk deploy

The URL of the ImageTransformerEndpoint displayed in the output will serve as the CDN's endpoint.

The image files placed in /imgs will be uploaded to S3. By default, a file named test.png is uploaded. You can verify the image display by accessing the URL below:

https://xxxxxxxxxxxxxx.cloudfront.net/test.png

(Please replace 'xxxxxxxxxxxxxx' with the appropriate value)

Supported Query Parameters

  • width Specifies the width
  • height Specifies the height
  • fit Specifies how to resize if both width and height are specified
  • quality Specifies image quality (default=85)
  • format Specifies the format (jpeg, png, gif, webp, avif)
  • auto Convert to specified format by looking at the Accept header (webp, avif)

Example: Set the width to 300px https://xxxxxxxxxxxxxx.cloudfront.net/test.png?width=300

Example: Convert png to jpeg https://xxxxxxxxxxxxxx.cloudfront.net/test.png?format=jpeg

Example: Check the Accept header and convert to webp if possible https://xxxxxxxxxxxxxx.cloudfront.net/test.png?auto=webp

Security

See CONTRIBUTING for more information.

License

This library is licensed under the MIT-0 License. See the LICENSE file.

About

No description, website, or topics provided.

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •