Skip to content

Commit 2c33cb8

Browse files
committed
Update readme and small clean-ups
1 parent fd42099 commit 2c33cb8

File tree

4 files changed

+19
-15
lines changed

4 files changed

+19
-15
lines changed

README.md

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
# Serverless Sharp Image Processor
2-
A solution to dynamically optimize and transform images on the fly, utilizing [Sharp](https://sharp.pixelplumbing.com/en/stable/).
2+
A solution to dynamically optimize and transform images on the fly, utilizing [Sharp](https://sharp.pixelplumbing.com/en/stable/) and AWS Lambda.
33

44
## Who is this for?
5-
This software is for people who want to optimize and transform (crop, scale, convert, etc) images from an existing S3
5+
This software is for people who want to optimize and run basic transformations (crop, scale, convert, etc) on images from an existing S3
66
bucket without running computationally expensive processes or servers or paying for expensive third-party services.
77

8+
Serverless Sharp is written to be a drop-in replacement for most essential features of Imgix and costs magnitudes less for
9+
most users.
10+
811
## How does it work?
912
After deploying this solution, you'll find yourself with a number of AWS resources (all priced based on usage rather
1013
than monthly cost). The most important of which are:
@@ -24,6 +27,10 @@ For example: `mybucket/images`
2427
- `SECURITY_KEY` See security section
2528
- `SLS_IGNORE` A comma-delineated string of paths that should be ignored (for example, `favicon.ico`)
2629

30+
You can define multiple environments, each of which will inherit your default settings. This is useful if you have
31+
different buckets for staging & production, for example. You may also wish to create an environment without a sign-key
32+
for local development.
33+
2734
## API & Usage
2835
We chose to base our API around the [Imgix service](https://docs.imgix.com/apis/url) to allow for backwards compatibility
2936
with the already popular service. The idea is that all CMS plugins should be able to seamlessly use this service in-place of
@@ -120,14 +127,9 @@ This package uses Serverless to allow for local development by simulating API Ga
120127
5. Run `serverless offline`
121128

122129
## Deploying to AWS
123-
First, we need to procure sharp/libvips binaries compiled for Amazon Linux. We can do this by running the following:
124-
125-
```
126-
npm run sharp:linux
127-
```
128-
129-
This will remove any existing Sharp binaries and then reinstall them with Linux x64 in mind.
130-
131-
Ensure your `settings.yml` file is properly configured as shown in the previous steps
130+
Ensure your `settings.yml` file is properly configured as shown in the previous steps.
132131

133132
Run: `serverless deploy [--stage=dev] [--settings=settings.yml]`
133+
134+
If you need to deploy using a specific AWS profile, you should run:
135+
`AWS_SDK_LOAD_CONFIG=true serverless deploy [--stage=dev] [--settings=settings.yml] --aws-profile PROFILE_NAME `

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
"email": "[email protected]"
88
},
99
"scripts": {
10-
"sharp:linux": "npm ci --arch=x64 --platform=linux --target=10.15.0 sharp",
1110
"test": "jest"
1211
},
1312
"version": "1.0.0",

src/ImageHandler.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,10 @@ class ImageHandler {
6464
case 'gif':
6565
contentType = 'image/gif'
6666
break
67+
case 'input':
68+
break
6769
default:
68-
console.warn('Unexpected output content type encountered')
70+
console.warn('Unexpected output content type encountered: ' + contentType)
6971
}
7072
}
7173

@@ -136,7 +138,7 @@ class ImageHandler {
136138
if (autoVals.includes('format')) {
137139
// If the browser supports webp, use webp for everything but gifs
138140
if (headers && 'Accept' in headers) {
139-
if (fm !== 'gif' && headers['Accept'].indexOf('image/webp') !== -1) {
141+
if (fm !== 'gif' && headers.Accept.indexOf('image/webp') !== -1) {
140142
fm = 'webp'
141143
}
142144
}
@@ -190,7 +192,7 @@ class ImageHandler {
190192
* @returns {string}
191193
*/
192194
findBin (binName) {
193-
process.env['PATH'] = process.env['PATH'] + ':' + process.env['LAMBDA_TASK_ROOT']
195+
process.env.PATH = process.env.PATH + ':' + process.env.LAMBDA_TASK_ROOT
194196
const binPath = path.resolve('./bin/', process.platform, binName)
195197

196198
if (!fs.existsSync(binPath)) {

src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const ImageHandler = require('./ImageHandler.js')
33
const security = require('./helpers/security')
44

55
exports.handler = async (event) => {
6+
// console.log('EVENT\n' + JSON.stringify(event, null, 2))
67
const beforeHandle = beforeHandleRequest(event)
78

89
if (!beforeHandle.allowed) {

0 commit comments

Comments
 (0)