README Stock
taiga-tech
2021/04/19 - 最終更新 9ヶ月前
lambda-edge-image-convert GitHub
Lambda function to convert to webp
JavaScript

lambda-edge-image-convert

CI

"COOKPAD" the sample code for developers blog was in reference
Resize images in real time with AWS Lambda @ Edge & convert to WebP format

Usage

<img src="https://<cloudFrontUrl>/<S3_PATH>?<query>">

<!-- format: webp, height: 200px -->
<img src="https://d2eerjykv09g3.cloudfront.net/demo/img/demo_11.jpg?p=t&h=200">

Demo

  • format: webp, height: 200px
    demo

  • format: jpg, height: 100px
    demo

Query

Key Value Delfault Maximum addition
w Maximum width(px) 1200 1200 Values larger than the source image are invalid
h Maximum hight(px) 1200 1200 same as above
p t (true): WebP conversion,
f (false): WebP conversion
f (false) - -

Command

% node -v # 14.x
% npm i
% npm run create-package # create a zip package

Lambda Settings

  • runtine: node 14.x
  • handler: /src/index.handler

Todo

  • Automatic deployment with github actions
  • Added format that can be converted
  • support for png, but still worried so will fix it.
  • Describes how to install "sharp" on Amazon Linux 2

References