|
2 | 2 |
|
3 | 3 | ## Description
|
4 | 4 |
|
5 |
| -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. |
| 5 | +Resizes images on the fly using Amazon S3, AWS Lambda, and Amazon API Gateway. |
| 6 | +Using a conventional URL structure and S3 static website hosting with |
| 7 | +redirection rules, requests for resized images are redirected to a Lambda |
| 8 | +function via API Gateway which will resize the image, upload it to S3, and |
| 9 | +redirect the requestor to the resized image. The next request for the resized |
| 10 | +image will be served from S3 directly. |
6 | 11 |
|
7 | 12 | ## Usage
|
8 | 13 |
|
9 | 14 | 1. Build the Lambda function
|
10 | 15 |
|
11 |
| - The Lambda function uses [sharp][sharp] for image resizing which requires native extensions. In order to run on Lambda, it must be packaged on Amazon Linux. You can accomplish this in one of two ways: |
| 16 | + The Lambda function uses [sharp][sharp] for image resizing which requires |
| 17 | + native extensions. In order to run on Lambda, it must be packaged on Amazon |
| 18 | + Linux. You can accomplish this in one of two ways: |
12 | 19 |
|
13 |
| - - Upload the contents of the `lambda` subdirectory to a [Amazon EC2 instance running Amazon Linux][amazon-linux] and run `npm install`, or |
| 20 | + - Upload the contents of the `lambda` subdirectory to an [Amazon EC2 instance |
| 21 | + running Amazon Linux][amazon-linux] and run `npm install`, or |
14 | 22 |
|
15 |
| - - Use the Amazon Linux Docker container image to build the package using your local system. This repo includes Makefile that will download Amazon Linux, install Node.js and developer tools, and build the extensions using Docker. Run `make all`. |
| 23 | + - Use the Amazon Linux Docker container image to build the package using your |
| 24 | + local system. This repo includes Makefile that will download Amazon Linux, |
| 25 | + install Node.js and developer tools, and build the extensions using Docker. |
| 26 | + Run `make all`. |
16 | 27 |
|
17 | 28 | 2. Deploy the CloudFormation stack
|
18 | 29 |
|
19 |
| - 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. |
| 30 | + Run `bin/deploy` to deploy the CloudFormation stack. It will create a |
| 31 | + temporary Amazon S3 bucket, package and upload the function, and create the |
| 32 | + Lambda function, Amazon API Gateway RestApi, and an S3 bucket for images via |
| 33 | + CloudFormation. |
20 | 34 |
|
21 |
| - The deployment script requires the [AWS CLI][cli] version 1.11.19 or newer to be installed. |
| 35 | + The deployment script requires the [AWS CLI][cli] version 1.11.19 or newer to |
| 36 | + be installed. |
22 | 37 |
|
23 | 38 | 3. Test the function
|
24 | 39 |
|
25 |
| - 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: |
| 40 | + Upload an image to the S3 bucket and try to resize it via your web browser to |
| 41 | + different sizes, e.g. with an image uploaded in the bucket called image.png: |
26 | 42 |
|
27 |
| - - http://[BucketWebsiteHost]/300x300/path/to/image.png |
28 |
| - - http://[BucketWebsiteHost]/90x90/path/to/image.png |
29 |
| - - http://[BucketWebsiteHost]/40x40/path/to/image.png |
| 43 | + - http://[BucketWebsiteHost]/300x300/path/to/image.png |
| 44 | + - http://[BucketWebsiteHost]/90x90/path/to/image.png |
| 45 | + - http://[BucketWebsiteHost]/40x40/path/to/image.png |
30 | 46 |
|
31 |
| - You can find the BucketWebsiteUrl in the table of outputs displayed on a successful invocation of the deploy script. |
| 47 | + You can find the `BucketWebsiteUrl` in the table of outputs displayed on a |
| 48 | + successful invocation of the deploy script. |
32 | 49 |
|
33 |
| -**Note:** If you create the Lambda function yourself, make sure to select Node.js version 6.10. |
| 50 | +4. (Optional) Restrict resize dimensions |
34 | 51 |
|
35 |
| -4. Restrict resize dimensions |
36 |
| - |
37 |
| - To restrict the resolutions client services can convert images to, set the environment variable ```ALLOWED_DIMENSIONS``` to a string in the format *(HEIGHT)x(WIDTH),(HEIGHT)x(WIDTH),...(HEIGHT)x(WIDTH)*. |
38 |
| - For example: *300x300,90x90,40x40*. |
| 52 | + To restrict the dimensions the function will create, set the environment |
| 53 | + variable `ALLOWED_DIMENSIONS` to a string in the format |
| 54 | + *(HEIGHT)x(WIDTH),(HEIGHT)x(WIDTH),...*. |
39 | 55 |
|
| 56 | + For example: *300x300,90x90,40x40*. |
40 | 57 |
|
41 | 58 | ## License
|
42 | 59 |
|
|
0 commit comments