-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
209 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Introduction | ||
|
||
## What is Serverless Sharp? | ||
Serverless Sharp is a self-hosted image processing solution that uses [Sharp](https://sharp.pixelplumbing.com/) by | ||
Pixel Plumbing. Serverless Sharp requires no database, no server, and no additional services beyond those offered by | ||
AWS. | ||
|
||
## Who is this for? | ||
This software is for people who want to optimize and run basic transformations (crop, scale, convert, etc) on images | ||
from an existing S3 bucket without running computationally expensive processes or servers or paying for expensive | ||
third-party services. | ||
|
||
## How does it work? | ||
After deploying this solution, you'll find yourself with a number of AWS resources (all priced based on usage rather | ||
than monthly cost). The most important of which are: | ||
- **AWS Lambda**: Pulls images from your S3 bucket, runs the transforms, and outputs the image from memory | ||
- **API Gateway**: Acts as a public gateway for requests to your Lambda function | ||
- **Cloudfront Distribution**: Caches the responses from your API Gateway so the Lambda function doesn't re-execute | ||
|
||
Once deployed, a Cloudfront distribution is generated that is directed to the generated API Gateway. This distribution | ||
ensures the Lambda function does not get run multiple times for the same image request. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
# Configuration | ||
Serverless Sharp stores its settings in YAML files. When deploying the application, you specify the YAML file and the | ||
stage (your environment). For example: | ||
|
||
```sh | ||
serverless deploy --settings mysite.com.yml --stage prod | ||
``` | ||
|
||
## Settings File Structure | ||
We use YML files to make use of their inheritance. This allows us to define some defaults and then branch environment | ||
-specific changes off of them. For example: | ||
|
||
|
||
```yml | ||
defaults: &defaults | ||
serviceName: image-handler-test | ||
offlinePort: 80 | ||
region: 'us-east-1' | ||
environment: &defaults.environment | ||
DEFAULT_QUALITY: 75 | ||
DEFAULT_COMPRESS_QUALITY: 45 | ||
SLS_IGNORE: favicon.ico | ||
SLS_VALID_PATH_REGEX: '.*' | ||
MAX_IMAGE_WIDTH: 2000 | ||
MAX_IMAGE_HEIGHT: 1000 | ||
PNGQUANT_SPEED: 10 | ||
DEFAULT_CACHE_CONTROL: 'max-age=2592000' | ||
|
||
stages: | ||
dev: | ||
<<: *defaults | ||
environment: | ||
<<: *defaults.environment | ||
SOURCE_BUCKET: 'my-bucket/prefix/path' | ||
SECURITY_KEY: '' | ||
CUSTOM_DOMAIN: '' | ||
prod: | ||
<<: *defaults | ||
environment: | ||
<<: *defaults.environment | ||
SOURCE_BUCKET: 'random-string-here' | ||
SECURITY_KEY: '' | ||
CUSTOM_DOMAIN: 'my.domain.com' | ||
|
||
``` | ||
|
||
## Environment Settings | ||
The majority of the application and environment specific settings are configured as environment variables that are | ||
passed into the Lambda service handler. | ||
|
||
### `DEFAULT_QUALITY` | ||
|
||
- Type: `integer` | ||
- Default: `75` | ||
|
||
A number between 1 and 100 representing the default image quality. | ||
|
||
### `DEFAULT_COMPRESS_QUALITY` | ||
|
||
- Type: `integer` | ||
- Default: `75` | ||
|
||
A number between 1 and 100 for the default quality when an image is requested to be compressed | ||
|
||
### `SLS_IGNORE` | ||
|
||
- Type: `string` | ||
- Default: `` | ||
|
||
A comma-delineated string of paths that should be ignored (for example, `favicon.ico`) | ||
|
||
### `SLS_VALID_PATH_REGEX` | ||
|
||
- Type: `Regular Expression` | ||
- Default: `.*` | ||
|
||
A regular expression for path validation. Allows you to explicitly control what assets may be handled by the Lambda | ||
function. If the request path fails this test, a 404 response will be served. | ||
|
||
Example: | ||
```yaml | ||
# All requests must start with /images/ | ||
SLS_VALID_PATH_REGEX: ^\/images\/.*` | ||
``` | ||
### `MAX_IMAGE_WIDTH` | ||
|
||
- Type: `integer` | ||
- Default: `2000` | ||
|
||
Images may not be requested with a width larger than this value | ||
|
||
### `MAX_IMAGE_HEIGHT` | ||
|
||
- Type: `integer` | ||
- Default: `2000` | ||
|
||
Images may not be requested with a height larger than this value | ||
|
||
### `PNGQUANT_SPEED` | ||
|
||
- Type: `integer` | ||
- Default: `10` | ||
|
||
The speed value to pass to the `pngquant` optimization program. From the [pngquant website](https://pngquant.org/): | ||
|
||
> Speed/quality trade-off from 1 (brute-force) to 10 (fastest). The default is 3. Speed 10 has 5% lower quality, but is 8 times faster than the default. | ||
|
||
### `DEFAULT_CACHE_CONTROL` | ||
|
||
- Type: `string` | ||
- Default: `` | ||
|
||
By default, Serverless Sharp will serve responses with the same Cache-Control header as the object being served. If | ||
the Cache-Control header is not set, this value will be used. | ||
|
||
|
||
### `SOURCE_BUCKET` | ||
|
||
- Type: `string` | ||
- Default: `` | ||
|
||
### `SECURITY_KEY` | ||
|
||
- Type: `string` | ||
- Default: `` | ||
|
||
### `CUSTOM_DOMAIN` | ||
|
||
- Type: `string` | ||
- Default: `` | ||
|
||
> **NOTE:** This requires deployment in the `us-east-1` region! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Deployment |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> | ||
<title>Serverless Sharp</title> | ||
<link rel="stylesheet" href="https://unpkg.com/docute@4/dist/docute.css"> | ||
</head> | ||
<body> | ||
<div id="docute"></div> | ||
<script src="https://unpkg.com/docute@4/dist/docute.js"></script> | ||
<script> | ||
new Docute({ | ||
title: 'Serverless Sharp', | ||
target: '#docute', | ||
nav: [ | ||
{ | ||
title: 'Home', | ||
link: '/' | ||
}, | ||
{ | ||
title: 'GitHub', | ||
link: 'https://github.com/venveo/serverless-sharp' | ||
} | ||
], | ||
sidebar: [ | ||
// A sidebar item, with child links | ||
{ | ||
title: 'Introduction', | ||
link: '/' | ||
}, | ||
{ | ||
title: 'Configuration', | ||
link: '/configuration' | ||
}, | ||
{ | ||
title: 'Deployment', | ||
link: '/deployment' | ||
}, | ||
{ | ||
title: 'Changelog', | ||
link: 'https://github.com/venveo/serverless-sharp/blob/master/CHANGELOG.md' | ||
} | ||
] | ||
}) | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Integration |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Parameters |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Security |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,8 @@ | |
"email": "[email protected]" | ||
}, | ||
"scripts": { | ||
"test": "jest" | ||
"test": "jest", | ||
"docs": "serve ./docs" | ||
}, | ||
"version": "1.0.0", | ||
"private": false, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters