# Configure S3-compatible access for Django

## Summary
Object storage client for a Django app on Ample. Verified on Django: bucket credentials delivered as encrypted S3_* environment variables and a validated PutObject/GetObject round-trip linked to a database row (upload=ok linked=ok). Build and start: `pip install into .ample/python from requirements.txt`, then `waitress serving project.wsgi from run.py reading PORT on the python-3.12 template.`

## Prerequisites
- A Django project (`pip install into .ample/python from requirements.txt, then waitress serving project.wsgi from run.py reading PORT on the python-3.12 template`)
- A bucket from `ample bucket create` with credentials passed as encrypted S3_* environment variables
- An Ample account token with `servers:write`, `buckets:read`

## Resource Requirements
- primitive:compute
- primitive:s3-compatible-object-storage

## Workflow Steps
### Build and start
`pip install into .ample/python from requirements.txt, then waitress serving project.wsgi from run.py reading PORT on the python-3.12 template; the server must bind 0.0.0.0 on PORT.`

### Create the bucket and pass its credentials
Create it once with `ample bucket create`, then pass endpoint, region, bucket and keys with `--env`; use path-style addressing.

```bash
ample deploy . --name  --public --start "python3 run.py" --env S3_ENDPOINT=... --env S3_REGION=... --env S3_BUCKET=... --env S3_ACCESS_KEY_ID=... --env S3_SECRET_ACCESS_KEY=...`
```

### Verify
Fetch the live URL and `/p/browser-file-uploads` on the example; on failure read the build and runtime logs.

```bash
ample logs  --kind build
```

## Testing Configuration
- Template: `python-3.12`
- Runtime: `python`
- Size: `s-1vcpu-1gb`
- Install: `python3 -m pip install --target .ample/python -r requirements.txt`
- Start: `PYTHONPATH=.ample/python:${PYTHONPATH:-} python3 run.py`

## Example
### Django pattern fixture
Verified object storage client on Django.

#### Evidence Summary
- Kind: canary_run
- Summary: Django pattern fixture deployed on Ample (pip install into .ample/python from requirements.txt, then waitress serving project.wsgi from run.py reading PORT on the python-3.12 template); for this guide: bucket credentials delivered as encrypted S3_* environment variables and a validated PutObject/GetObject round-trip linked to a database row (upload=ok linked=ok).
- Observed at: 2026-09-20T03:31:44Z
- Expires at: 2027-03-19T03:31:44Z

## Limitations
- Verified on the python-3.12 template at s-1vcpu-1gb; other sizes and Django major versions are not verified.
- **Cost Estimate**: 
  - Currency: USD
  - Monthly Amount: 5.0
  - Basis: size prices from pricing.toml (loaded by the API)
  - Note: Always-on monthly price of the tested sizes; apps auto-pause when idle. Buckets are allocation-priced per quota and not included.
