Name | Version |
---|---|
aws | >= 5.31.0, < 6.0 |
- Install AWS SAM CLI
- Build source code
make build
- Provision Instructions: Copy and paste into your Terraform configuration, insert the variables, and run
terraform init
.module "image_resize" { source = "git::https://github.com/ahiho/terraform-aws-image-resize.git?ref=v1.0.0" --- variables --- }
- Set
create_new_bucket=false
- Make sure that your s3 bucket delegates all needed permissions to the s3 access point created by this stack. Example: `
statement { sid = "AccessPoint" effect = "Allow" principals { type = "AWS" identifiers = ["*"] } actions = ["*"] resources = [<your s3 bucket ARN>] condition { test = "StringEquals" variable = "s3:DataAccessPointAccount" values = [<your account id>] } }
Headers | Description | Valid Values | Type | Default |
---|---|---|---|---|
t | image transformation mode | fit, crop | string | crop |
w | specifies image width | 100..4100 | int | 640 |
h | specifies image height | 100..4100 | int | 400 |
o | get the original image | true, false | boolean | false |
b | specifies image blur | 0..50 | boolean | 0 |
q | specifies image quality | low, medium, high, best | string | high |
- | - | l, m, med, h, b | - | - |
The Lambda function using these environments
- IMAGE_BUCKET_REGION (required): The region where the image bucket is located.
- IMAGE_BUCKET_NAME (required): The name of the image bucket.
- ROUNDING_VALUE: The rounding value to be used during image resizing.
- LOG_LEVEL: The log level of the Lambda function. Valid values are
DEBUG
. - MIN_WIDTH: The default min width value
- MIN_HEIGHT: The default min height value
- MAX_WIDTH: The default max width value
- MAX_HEIGHT: The default max width value
- DEFAULT_WIDTH: The default width value
- DEFAULT_HEIGHT: The default height value
- DEFAULT_QUALITY: The default quality value. Valid values are
l
,m
,h
,b
. - DEFAULT_TRANSFORM: The default width value. Valid values are
f
',c
.
The Lambda function follows a structured workflow to process image resizing:
- Extracts the S3 URL from the event object.
- Retrieves the original image from the S3 URL.
- Checks if a resized image already exists. If it does, the returns the resized image; otherwise, it proceeds to the next step.
- Applies the requested image transformation (e.g., fit, crop) based on the provided query parameters.
- Puts the resized image to S3 bucket.
- Returns the resized image.
- Get distribution URL from AWS console. Example
https://xxxxxxxxxxxxxx.cloudfront.net
- Put image to S3 bucket. Example
test.png
- Combine distribution URL and image key together. Example
https://xxxxxxxxxxxxxx.cloudfront.net/test.png