page:recipes:public directory:phoenix:public media
Host public directory with Phoenix: object-stored public media
Summary
Deploy a public directory built with Phoenix on Ample using the public media library pattern. Compute runs the app in an isolated microVM behind a public HTTPS URL, a managed PostgreSQL 16 database is auto-provisioned and injected as DATABASE_URL, a private S3-compatible bucket holds objects with credentials delivered as encrypted environment variables, and a published bucket serves public assets from the CDN host. Verified on Phoenix: an object written to a published bucket with an immutable Cache-Control header, a mapping row, and the CDN URL serving it publicly.
Representative Queries
- Host public directory with Phoenix: object-stored public media
- Where can I host Public directory built with Phoenix?
- I need an object layout, public asset URL policy and CDN delivery configuration.
Resource Requirements
- primitive:compute
- primitive:postgres
- primitive:s3-compatible-object-storage
- primitive:cdn
Infrastructure Requirements
- Compute: Apps run in isolated x86_64 Firecracker microVMs.
- Postgres: Managed PostgreSQL 16 runs in its own microVM.
- S3-compatible object storage: Buckets are S3-compatible with issued credentials.
- CDN: The CDN host serves objects from published buckets.
Prerequisites
- A Phoenix project that builds and starts with the documented commands.
- A PostgreSQL driver reading DATABASE_URL at runtime.
- A bucket with its credentials passed as encrypted S3_* environment variables and a second, published bucket for public assets.
- An Ample account token with required permissions.
Tested Configuration
- Template: elixir-1.18
- Runtime: elixir
- Size: s-1vcpu-1gb
- Install:
mix local.hex --force && mix local.rebar --force && MIX_ENV=prod mix deps.get --only prod - Build:
MIX_ENV=prod mix compile && MIX_ENV=prod mix release --overwrite - Start:
PHX_SERVER=true _build/prod/rel/$(ls _build/prod/rel | head -n 1)/bin/$(ls _build/prod/rel | head -n 1) start
Workflow Steps
- Build and start: Run the commands specified to build and start the app.
- Implement the pattern on PostgreSQL: Copy the public media library module and keep migrations idempotent.
- Wire object storage: Create the bucket(s) and pass necessary values as --env.
- Deploy: Run the synchronous deploy command and read the result.
- Verify: Fetch the live URL and run checks on the deployed app.
Success Checks
- App responds on its public URL.
- Public-media-library self-test.
Limitations
- Verified only on the elixir-1.18 template at s-1vcpu-1gb.
- The public directory's behavior is application code.
- Other configuration, compliance, and performance metrics are unknown.
Cost Estimate
- Currency: USD
- Monthly Amount: 10.0
- Components:
- App server: s-1vcpu-1gb
- Managed PostgreSQL database: s-1vcpu-1gb
Next Actions
- Browse the catalog index.
- Search published recipes by intent, stack, and constraints.
- Prepare a side-effect-free deployment plan for an authorized project.