https://github.com/coderbyheart/rheactor-image-service
An image processing backend running on AWS Lambda.
https://github.com/coderbyheart/rheactor-image-service
Last synced: over 1 year ago
JSON representation
An image processing backend running on AWS Lambda.
- Host: GitHub
- URL: https://github.com/coderbyheart/rheactor-image-service
- Owner: coderbyheart
- License: mit
- Created: 2017-05-22T16:31:12.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2017-05-22T15:04:21.000Z (about 9 years ago)
- Last Synced: 2025-02-01T11:11:12.358Z (over 1 year ago)
- Language: JavaScript
- Size: 43 KB
- Stars: 0
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# rheactor-image-service
[](https://www.npmjs.com/package/@resourcefulhumans/rheactor-image-service)
[](https://travis-ci.org/ResourcefulHumans/rheactor-image-service)
[](http://greenkeeper.io/)
[](http://standardjs.com/)
[](https://github.com/semantic-release/semantic-release)
[](https://codeclimate.com/github/ResourcefulHumans/rheactor-image-service/coverage)
[](https://codeclimate.com/github/ResourcefulHumans/rheactor-image-service)
An image processing backend running on AWS Lambda.
Uses [gm](https://www.npmjs.com/package/gm) with GraphicsMagick (which is available by default)
on AWS lambda.
It takes JPEG or PNG images that are uploaded base64 encoded, crops and resizes them on the fly to
256x256px size, and stores them on an S3 bucket.
| Original | Result |
|:--------:|:-------:|
|  |  |
| JPEG | JPEG |
| 600x300 | 256x256 |
|  |  |
| PNG | JPEG |
| 600x300 | 256x256 |
|  |  |
| JPEG | JPEG |
| 300x600 | 256x256 |
## Request
Users need to provide an [JsonWebToken](https://jwt.io/) which is checked against the configured public key.
POST /upload
Content-Type: application/vnd.resourceful-humans.rheactor-image-service.v1+json
Authorization: Bearer
{
"$context":"https://github.com/ResourcefulHumans/rheactor-image-service#Upload",
"image":"R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7",
"mimeType":"image/png"
}
## Response
Content-Type: application/vnd.resourceful-humans.rheactor-image-service.v1+json
{
"$context":"https://github.com/ResourcefulHumans/rheactor-image-service#UploadResult",
"url":"https://s3.eu-central-1.amazonaws.com/rheactor-image-service/example.com/33f24f55-e435-4198-a148-fdd1095ffa96-user-5.jpg",
"mimeType":"image/jpeg"
}
This implementation expects token's `sub` to be an URL, which will be used to prefix and suffix URLs.
A `sub` value of `https://example.com/user/5` was used in the example above.
## Configuration
These environment variables need to be set on the lambda function:
- `S3_BUCKET`
Name of the S3 bucket, e.g. `rheactor-image-service` to where files are uploaded.
- `S3_REGION`
Region to use.
- `MOUNT_URL`
Public endpoint for the lamba function (as provided by API Gateway)
- `WEB_LOCATION`
Public URL for the bucket
- `PUBLIC_KEY_FILE`
Public key file in the bucket to be used for verifying tokens
## Setup
npm install
# Configure these environment variables
AWS_ROLE=…
AWS_ACCESS_KEY_ID=…
AWS_SECRET_ACCESS_KEY=…
AWS_REGION=…
AWS_FUNCTION_NAME=…
NODE_ENV=…
VERSION=…
# install this as a new lambda function
make install