Image Gateway provides an API endpoint which creates resized versions of images stored inside an S3 bucket.
It uses a combination of S3 bucket, Lambda function, API Gateway and Cloudfront.
- Lifecycle policy should be matched with CloudFront cache, as it is possible for CloudFront to redirect the user to a cached image after this image has been removed. Therefore it is advised that Maximum TTL for S3 origin should be set to 1209600 seconds (14 days).
- Pillow Python module is required
- To create a ready to use package, you have to package the lambda source file (
lambda.py
) with the Pillow module. To do so, follow instructions here: http://docs.aws.amazon.com/lambda/latest/dg/lambda-python-how-to-create-deployment-package.html
- Upload Lambda function ZIP (see above) into an S3 bucket.
- Upload
infrastructure/templates/stack.json
into CloudFormation. - Fill out parameters:
BucketName
- name of the bucket for storage that will be createdLambdaSourceBucket
- name of the S3 bucket where you uploaded the Lambda function ZIPLambdaFileName
- name of the Lambda function ZIP file inside the above S3 bucket
- Ta-dah! You'll find your CloudFront URL inside Outputs in CloudFormation.
Lambda function is not updated by CloudFormation unless you change the parameters. So you can change the LambdaSourceBucket
or LambdaFileName
OR update
the Lambda manually:
- Get pre-compiled libraries (as above)
- Unzip the archive
- Copy
lambda.py
into the unpacked directory - Zip the contents (not the directory) back.
- Upload to AWS Lambda or S3 bucket.