Skip to content

A lambda function that resizes images on the fly using Sharp library and TypeScript as a language. The lambda function is triggered by CloudFront origin request and it resizes the image based on the query string parameters.

Notifications You must be signed in to change notification settings

darklight147/Terraform-AWS-lambda-image-resizing-on-the-fly

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Image Resizer Lambda with Terraform, Sharp, and TypeScript and AWS Lambda

This project deploys a lambda function that resizes images on the fly using Sharp library and TypeScript as a language. The lambda function is triggered by CloudFront origin request and it resizes the image based on the query string parameters.

Prerequisites

Before you can deploy this project, you need to have the following prerequisites:

  • aws CLI tool installed and configured with your AWS credentials. You can download the CLI tool from here.
  • sam CLI tool installed. You can download the CLI tool from here.
  • terraform CLI tool installed. You can download the CLI tool from here.
  • A source S3 bucket which contains the original images that you want to resize.
  • A CloudFront distribution which points to the source S3 bucket.

Getting Started

To get started with this project, clone the repository and navigate to the root directory of the project.

git clone https://github.com/darklight147/Terraform-AWS-lambda-image-resizing-on-the-fly.git terraform-image-resize


cd terraform-image-resize

Project structure

~/Documents/workspace/terraform-image-resize main* ❯ tree -I node_modules
.
├── README.md
├── deploy.sh
├── destroy.sh
├── infra
│   ├── production
│   └── staging
│       ├── lambda.zip
│       ├── lib
│       │   └── sharp-layer.zip
│       ├── main.tf
│       ├── outputs.tf
│       ├── terraform.tfstate
│       ├── terraform.tfstate.backup
│       ├── terraform.tfvars
│       └── variables.tf
└── lambda-resizer
    ├── README.md
    ├── events
    │   └── event.json
    ├── resizer
    │   ├── app.ts
    │   ├── jest.config.ts
    │   ├── package-lock.json
    │   ├── package.json
    │   ├── tests
    │   │   └── unit
    │   │       └── test-handler.test.ts
    │   └── tsconfig.json
    ├── samconfig.toml
    └── template.yaml

10 directories, 21 files

You'll need to give execution access to the .sh files

chmod +x *.sh

Running the project

./deploy.sh

PS: you can fill in your custom variables by creating a terraform.tfvars at ./infra/staging/terraform.tfvars

Destroying the created resources

./destroy.sh

Contribution Guide

About

A lambda function that resizes images on the fly using Sharp library and TypeScript as a language. The lambda function is triggered by CloudFront origin request and it resizes the image based on the query string parameters.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published