A lightweight Go service for processing and serving images with YAML-configurable storage options and S3 integration.
- Original Image Serving:
/originals/{type}/{image_id}
- serve original images directly from storage - Thumbnail Generation:
/thumb/{type}/{image_id}
- on-demand thumbnail generation - YAML Configuration: Different processing rules per image type (avatar, photo, banner)
- Multiple Formats: Convert images to WebP, JPEG, PNG with configurable quality
- S3 Integration: Fetch and store images in AWS S3 with folder organization
- CDN-Optimized: Cache-Control and ETag headers for optimal CDN performance
- Graceful Shutdown: Production-ready server lifecycle management
- Other media support (currently on images)
- Server level caching of high frequency media
GET /thumb/{type}/{image_id}?width=512
Generates and serves thumbnails with configurable dimensions.
Parameters:
type
: Image category (avatar, photo, banner, or any configured type)image_id
: Unique identifier for the imagewidth
: Image width in pixels (optional, defaults to the type'sdefault_size
from storage config)
GET /originals/{type}/{image_id}
Serves original images directly from storage.
Parameters:
type
: Image category (avatar, photo, banner, or any configured type)image_id
: Unique identifier for the image
GET /health
Returns service health status.
MediaFlow uses YAML configuration to define processing rules per image type:
storage_options:
avatar:
origin_folder: "originals/avatars"
thumb_folder: "thumbnails/avatars"
sizes: ["128", "256"]
default_size: "256"
quality: 90
convert_to: "webp"
photo:
origin_folder: "originals/photos"
thumb_folder: "thumbnails/photos"
sizes: ["256", "512", "1024"]
default_size: "256"
quality: 90
convert_to: "webp"
banner:
origin_folder: "originals/banners"
thumb_folder: "thumbnails/banners"
sizes: ["512", "1024", "2048"]
default_size: "512"
quality: 95
convert_to: "webp"
default:
origin_folder: "originals"
thumb_folder: "thumbnails"
sizes: ["256", "512"]
default_size: "256"
quality: 90
convert_to: "webp"
Create a .env
file for local development:
# Required
S3_BUCKET=your-bucket-name
# AWS Credentials (use one of the following methods)
# Method 1: Direct credentials (local development)
AWS_ACCESS_KEY_ID=your-access-key
AWS_SECRET_ACCESS_KEY=your-secret-key
# Method 2: IAM Role (recommended for ECS/EC2)
# No credentials needed - uses IAM role attached to ECS task/EC2 instance
# Optional
S3_REGION=us-east-1
PORT=8080
CACHE_MAX_AGE=86400
STORAGE_CONFIG_PATH=storage-config.yaml
# Pull and run the latest image
docker run -p 8080:8080 \
-e S3_BUCKET=your-bucket-name \
-e AWS_ACCESS_KEY_ID=your-key \
-e AWS_SECRET_ACCESS_KEY=your-secret \
-v $(pwd)/storage-config.yaml:/app/storage-config.yaml \
syntaxsdev/mediaflow:latest
make build-image
- Create an IAM role with S3 permissions (see AWS S3 IAM Integration section)
- Create an ECS task definition using
syntaxsdev/mediaflow:latest
- Attach the IAM role to your ECS task
- Set environment variables:
S3_BUCKET
,S3_REGION
,PORT
- Mount or include your
storage-config.yaml
file - Configure your Application Load Balancer to forward requests to the ECS service
- Set environment variables for your deployment platform
- Ensure
storage-config.yaml
is available to the container - Configure your load balancer to forward requests to the service
- Set up appropriate S3 bucket policies and IAM roles
- Consider using a CDN (CloudFront) for better performance and caching
- Attach the same IAM role to your EC2 instance
- MediaFlow will use the instance's IAM role credentials automatically
MediaFlow supports automatic AWS S3 authentication through IAM roles, making it ideal for ECS deployments:
- Create an IAM role with S3 permissions:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:GetObject",
"s3:PutObject",
"s3:DeleteObject",
"s3:ListBucket"
],
"Resource": [
"arn:aws:s3:::your-bucket-name",
"arn:aws:s3:::your-bucket-name/*"
]
}
]
}
- Attach the IAM role to your ECS task definition
- Remove
AWS_ACCESS_KEY_ID
andAWS_SECRET_ACCESS_KEY
from environment variables - MediaFlow will automatically use the ECS task's IAM role credentials
- Go 1.24.5+
- Air for hot reloading (optional)
# Clone and setup
git clone https://github.com/syntaxsdev/mediaflow
cd mediaflow
cp .env.example .env # Edit with your AWS credentials
# Install dependencies
go mod download
# Development with hot reload
make run-air
# Or build and run
make run
make run
- Build and run the servermake run-air
- Run with Air for hot reloading during developmentmake build
- Build the binarymake clean
- Remove built binary
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
MIT License