Resizes images on the fly using Amazon S3, AWS Lambda, and Amazon API Gateway. Using a conventional URL structure and S3 static website hosting with redirection rules, requests for resized images are redirected to a Lambda function via API Gateway which will resize the image, upload it to S3, and redirect the requestor to the resized image. The next request for the resized image will be served from S3 directly.
-
Modify some files
Modify 'REGION' to spacified region name in
bin/deploy
Modify 'ACCOUNT_ID' to your account id inbin/deploy
anddeploy/api.yaml
-
Deploy the CloudFormation stack
Run
bin/deploy
to deploy the CloudFormation stack. It will create a temporary Amazon S3 bucket, package and upload the function, and create the Lambda function, Amazon API Gateway RestApi, and an S3 bucket for images via CloudFormation.The deployment script requires the [AWS CLI][cli] version 1.11.19 or newer to be installed.
-
Modify code package
Download Lambda package from console, and hard code
bucket name
andurl
in index.js, because environment variable is not available. -
Test the function
Upload an image to the S3 bucket and try to resize it via your web browser to different sizes, e.g. with an image uploaded in the bucket called image.png:
- http://[BucketWebsiteHost]/300x300/image.png
- http://[BucketWebsiteHost]/90x90/image.png
- http://[BucketWebsiteHost]/40x40/image.png
You can find the BucketWebsiteUrl in the table of outputs displayed on a successful invocation of the deploy script.
Note: If you create the Lambda function yourself, make sure to select Node.js version 6.10.