---
title: Shipping SQLite to Lambda (with Laravel Vapor)
url: "https://aaronfrancis.com/writing/shipping-sqlite-to-lambda-with-laravel-vapor"
path: "/writing/shipping-sqlite-to-lambda-with-laravel-vapor"
type: technical_article
author: Aaron Francis
published: 2023-12-19
updated: 2026-11-10
topic: Databases
description: Using a SQLite database on AWS Lambda.
keywords: [sqlite, lambda, serverless, laravel vapor, read-only database, ephemeral filesystem, eloquent, content distribution, database deployment, aws lambda, litefs, turso]
site_index: "/llms.txt"
keyword_index: "/llms/keywords.txt"
---

# Shipping SQLite to Lambda (with Laravel Vapor)

The first question you may ask is, "Why would I ever want to use SQLite on a serverless platform? That makes no sense."
Good question!

If you know anything about a serverless platform, you know that the file system is ephemeral. You can mount a persistent
file system with Lambda, but by default, it's ephemeral. And since SQLite is a database-in-a-file, you're shipping your
database to a filesystem designed to be blown away.

Lambda can spin up as many copies of your application as it needs to satisfy requests, which leads to a bunch of
different copies of your database that aren't in sync. Each time a new Lambda container boots up, there's a new copy of
your database that doesn't speak to any of the other copies.

This means that if you write to the database in Lambda, the writes basically just disappear when a new container is
booted. The containers can be reused, but eventually, they'll be destroyed.

There are some solutions for that. You could use something like [LiteFS](https://fly.io/docs/litefs/)
or [Turso](https://turso.tech/). If I needed something like that, I'm just gonna use a regular MySQL database (through [PlanetScale](https://planetscale.com), of course.)

## SQLite as a read-only database

The reason that I use SQLite on Vapor is that it's an excellent read-only distribution mechanism. For this website, I
write all of the content to the database either locally or in CI, and then I commit and ship the database out to
production to be read from.

I don't ever write to the database in production, which is weird. I use it as a content repository, similar to a
pre-warmed cache. I put all my articles, videos, and podcasts into the database. In production, I still get to use
Eloquent to pull items out of the database, but my site is static content. Every time I deploy a new version of my
website, I deploy a new version of my database.

## SQLite on Vapor

For your database to be deployed to Laravel Vapor, you can't put your `database.sqlite` file in the `database`
directory.
The [vapor-cli `BuildProcess`](https://github.com/laravel/vapor-cli/blob/7cdf6de6b76a5e23a89e7a815269be6331998574/src/BuildProcess/RemoveIgnoredFiles.php#L65)
command ignores sqlite files in the database directory:

```php
$files = (new Finder())
    ->in(Path::app().'/database')
    ->depth('== 0')
    ->name('*.sqlite');
```

Instead, I put mine in the root directory. You'll need to update your `database.php` as well:

```php
'sqlite' => [
    'driver' => 'sqlite',
    'url' => env('DATABASE_URL'),
    'database' => base_path('database.sqlite'),
    'prefix' => '',
    'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
],
```

## Building the database

I populate the database by running several commands to gather items from across the internet. I have a command that
looks at YouTube and pulls down all of the videos. I have a command that looks at podcast feeds
and pulls down all of the episodes. For my articles, it looks at the markdown on the disk and write it into the database. 

I can build the database locally, or I can build it in CI. I can also delete it altogether and rebuild it from scratch!

I don't ever have to back up the database or worry about git conflicts or messing anything up because all of the data is available externally and I'm just pulling it in and putting it into a database for easier usage.

All of those commands are wrapped up into a single Artisan command called `sync:all`, which looks for all `sync:*`
commands and runs them:

```php
public function handle()
{
    collect(Artisan::all())
        ->keys()
        ->filter(function ($command) {
            return Str::startsWith($command, 'sync:') && $command !== 'sync:all';
        })
        ->each(function ($command) {
            Artisan::call($command, [
                '--no-interaction' => $this->option('no-interaction')
            ]);
        });
}
```

In GitHub, I have a workflow that runs that command and commits the content to git.

```yaml
jobs:
  deploy:
    name: Sync content
    runs-on: ubuntu-latest
    steps:
      - name: Sync Content
        id: sync_content
        env:
          YOUTUBE_API_KEY: ${{ secrets.YOUTUBE_API_KEY }}
        run: php artisan sync:all --no-interaction

      - name: Commit content
        uses: stefanzweifel/git-auto-commit-action@v4
        with:
          commit_message: "Sync content"
```

This ensures that I always have the most up to date content right before I deploy. I also run this workflow on a schedule so that every night at midnight the site updates itself.

## Conclusion

This is a bit of a strange use case for SQLite, but I find it really easy to reason about. It makes my site fully self-contained and reduces the number of services I have to rely on. 

## As a YouTube video

If you want to see more about my site, I've recorded a YouTube video on it!

> Watch on YouTube: https://www.youtube.com/watch?v=QiocnnlcXIU

---

## Related on aaronfrancis.com

- [Deploying Torchlight](/podcast/deploying-torchlight-gkdczl) *(Podcast · 2022-10-05 · shared: eloquent, laravel vapor, serverless)*
- [Static site generators & personal websites](/podcast/static-site-generators-personal-websites-knj6zl) *(Podcast · 2023-12-14 · shared: sqlite, eloquent, planetscale)*
- [SSG is dead. Long live cache.](/videos/ssg-is-dead-long-live-cache) *(Video · 2023-11-08 · shared: sqlite, serverless, laravel vapor)*
- [Aaron Francis on Torchlight](/podcast/aaron-francis-on-torchlight-jy1c4a) *(Podcast · 2022-09-16 · shared: aws lambda, serverless, planetscale)*
- [A little bit of Lambda](/about/speaking/a-little-bit-of-lambda) *(Talk · 2021-09-28 · shared: lambda, aws lambda, serverless)*

## Relevant Resources from Aaron Francis

- **[Solo](https://soloterm.com)** (overview on site: [/software](/software)): All-in-one agentic development platform and terminal workspace built by Aaron Francis for orchestrating processes and AI coding agents.
- **[MySQL for Developers](https://databaseschool.com)** (overview on site: [/courses](/courses)): Full video course covering MySQL indexing, deferred joins, pagination, query plans, and schema design for application developers.

## Search aaronfrancis.com (2-Hop Static Keyword Index)

Pick the alphabetical shard matching any topic to find exact pages across all articles, newsletters, videos, talks, and podcast transcripts (every shard is < 40 KB):
[A-B](/llms/keywords/a-b.txt) · [C](/llms/keywords/c.txt) · [D-E](/llms/keywords/d-e.txt) · [F-G](/llms/keywords/f-g.txt) · [H-J](/llms/keywords/h-j.txt) · [K-L](/llms/keywords/k-l.txt) · [M-N](/llms/keywords/m-n.txt) · [O-P](/llms/keywords/o-p.txt) · [Q-R](/llms/keywords/q-r.txt) · [S](/llms/keywords/s.txt) · [T-Z](/llms/keywords/t-z.txt) · [Directory](/llms/keywords.txt) · [Site Map](/llms.txt)

Shards for this page's topics: `sqlite` ([S](/llms/keywords/s.txt)), `lambda` ([K-L](/llms/keywords/k-l.txt)), `read-only database` ([Q-R](/llms/keywords/q-r.txt)), `ephemeral filesystem` ([D-E](/llms/keywords/d-e.txt)).

## About Aaron Francis (Current Context)

Aaron Francis is VP of Marketing and Community at [Laravel](https://laravel.com), founder of [Try Hard Studios](https://tryhardstudios.com), creator of [Solo](https://soloterm.com), co-host of [Mostly Technical](/podcast), and author of [Mastering Postgres](/courses), [High Performance SQLite](/courses), [MySQL for Developers](/courses), and [Screencasting.com](/courses). Full bio: [/about](/about) · Current focus: [/now](/now).
