https://github.com/gervaiscodes/serverless-python-thumbnail
https://github.com/gervaiscodes/serverless-python-thumbnail
serverless
Last synced: 9 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/gervaiscodes/serverless-python-thumbnail
- Owner: gervaiscodes
- Created: 2025-03-16T16:18:55.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-03-16T16:19:14.000Z (about 1 year ago)
- Last Synced: 2025-03-16T20:38:19.880Z (about 1 year ago)
- Topics: serverless
- Language: Python
- Homepage:
- Size: 104 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Serverless Python Thumbnail Generator
## Overview
This project is a serverless application deployed on AWS using the Serverless Framework. It automatically generates thumbnail images when new images are uploaded to an S3 bucket and stores the URLs in a DynamoDB table.
## Features
- **AWS Lambda-based Thumbnail Generation**: Processes images uploaded to an S3 bucket and generates thumbnails.
- **DynamoDB Storage**: Stores generated thumbnail URLs and metadata in a DynamoDB table.
- **API Endpoints**:
- List all stored thumbnail URLs.
- Retrieve a specific thumbnail by ID.
- Delete a thumbnail entry.
- **Uses AWS Services**:
- **S3**: To store original images and thumbnails.
- **DynamoDB**: To store metadata.
- **Lambda**: For processing images.
- **API Gateway**: For exposing RESTful endpoints.
## Project Structure
- `serverless.yml` - Configuration file for the Serverless Framework.
- `handler.py` - Contains AWS Lambda functions for:
- Image processing.
- Storing metadata.
- Fetching and deleting stored images.
- `package.json` - Manages dependencies and serverless plugins.
- `package-lock.json` - Lock file for Node.js dependencies.
## Requirements
- AWS account with appropriate IAM permissions.
- Node.js and NPM installed.
- Serverless Framework installed (`npm install -g serverless`).
- Python 3.8 environment.
## Setup & Deployment
### Install Dependencies
```sh
npm install
```
### Deploy to AWS
```sh
serverless deploy
```
### Environment Variables
Configured in `serverless.yml`:
- `THUMBNAIL_SIZE`: The size of the generated thumbnail (default: 128x128).
- `REGION_NAME`: AWS region (`eu-west-3`).
- `DYNAMODB_TABLE`: Name of the DynamoDB table (`img-url-table`).
- `S3_BUCKET`: Name of the S3 bucket (`serverless-thumbnails-24f98d7e`).
## API Endpoints
| Method | Endpoint | Description |
|--------|--------------------------|-------------------------------------|
| GET | `/images/all` | Retrieve all stored thumbnails |
| GET | `/images/get/{id}` | Retrieve a specific thumbnail by ID |
| DELETE | `/images/delete/{id}` | Delete a thumbnail entry |
## How It Works
1. Upload a `.png` image to the S3 bucket.
2. The Lambda function is triggered and generates a thumbnail.
3. The thumbnail is stored in the same S3 bucket.
4. The image metadata (including URL) is stored in DynamoDB.
5. API endpoints allow fetching and deleting stored images.
## Plugins Used
- `serverless-python-requirements` - Ensures dependencies are packaged properly.
## Contributing
Feel free to submit pull requests or report issues.
## License
MIT License