An open API service indexing awesome lists of open source software.

https://github.com/gervaiscodes/serverless-python-thumbnail


https://github.com/gervaiscodes/serverless-python-thumbnail

serverless

Last synced: 9 months ago
JSON representation

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