AWS Lambda (Python)
AWS Lambda functions can speak to Filebase via boto3 — the same SDK they use for AWS S3.
Setup
pip install boto3 -t ./package
cd package && zip -r ../function.zip . && cd ..
zip -g function.zip handler.py
Or attach a Lambda layer that contains boto3 (note: the AWS-managed Python runtimes already include boto3, but the version may be older than what you want).
Environment variables
| Variable | Value |
|---|---|
FILEBASE_KEY | Your access key ID |
FILEBASE_SECRET | Your secret access key |
FILEBASE_BUCKET | Your bucket name |
For production, retrieve secrets from AWS Secrets Manager or Systems Manager Parameter Store rather than plain env vars.
Lambda handler — write to Filebase
handler.py
import json
import os
import time
import boto3
from botocore.config import Config
# Initialize at module scope so warm invocations reuse it
filebase = boto3.client(
's3',
endpoint_url='https://s3.filebase.io',
region_name='auto',
aws_access_key_id=os.environ['FILEBASE_KEY'],
aws_secret_access_key=os.environ['FILEBASE_SECRET'],
config=Config(signature_version='s3v4'),
)
BUCKET = os.environ['FILEBASE_BUCKET']
def handler(event, context):
key = f'events/{int(time.time() * 1000)}.json'
filebase.put_object(
Bucket=BUCKET,
Key=key,
Body=json.dumps(event, indent=2).encode(),
ContentType='application/json',
)
return {'statusCode': 200, 'body': json.dumps({'key': key})}
Pattern: thumbnail generation
Generate thumbnails when an object lands in Filebase:
import os
import io
import boto3
from PIL import Image
from botocore.config import Config
filebase = boto3.client(
's3',
endpoint_url='https://s3.filebase.io',
region_name='auto',
aws_access_key_id=os.environ['FILEBASE_KEY'],
aws_secret_access_key=os.environ['FILEBASE_SECRET'],
config=Config(signature_version='s3v4'),
)
BUCKET = os.environ['FILEBASE_BUCKET']
def handler(event, context):
# Triggered manually (Filebase doesn't fire AWS Lambda events directly).
# Pass the source key in `event['key']` from your application.
src_key = event['key']
# Download the source image
obj = filebase.get_object(Bucket=BUCKET, Key=src_key)
image = Image.open(io.BytesIO(obj['Body'].read()))
# Generate a thumbnail
image.thumbnail((512, 512))
buf = io.BytesIO()
image.save(buf, format='JPEG', quality=85)
buf.seek(0)
thumb_key = src_key.replace('original/', 'thumbnails/').rsplit('.', 1)[0] + '.jpg'
filebase.put_object(
Bucket=BUCKET,
Key=thumb_key,
Body=buf,
ContentType='image/jpeg',
CacheControl='public, max-age=31536000',
)
return {'thumbnail_key': thumb_key}
Trigger this Lambda from your application's upload-completion handler.
Triggering options
Filebase doesn't fire AWS Lambda events directly. Common patterns:
- Application-triggered. Your app uploads to Filebase, then invokes Lambda via AWS SDK / API Gateway.
- AWS S3 → Lambda → Filebase. Use AWS S3 as the trigger surface and mirror objects onto Filebase from the Lambda.
- Scheduled. Use EventBridge to invoke Lambda periodically — useful for backups, cleanup, reporting.