added aws adapter docs

This commit is contained in:
dswbx
2025-03-03 16:56:48 +01:00
parent 675a39ad5c
commit ad353e59c9
11 changed files with 3972 additions and 1402 deletions

View File

@@ -19,6 +19,7 @@ const config = {
node: "Node.js", node: "Node.js",
bun: "Bun", bun: "Bun",
cloudflare: "Cloudflare", cloudflare: "Cloudflare",
aws: "AWS Lambda",
}, },
framework: { framework: {
nextjs: "Next.js", nextjs: "Next.js",

3824
bun.lock

File diff suppressed because it is too large Load Diff

1378
docs/bun.lock Normal file

File diff suppressed because it is too large Load Diff

Binary file not shown.

107
docs/integration/aws.mdx Normal file
View File

@@ -0,0 +1,107 @@
---
title: 'AWS Lambda'
description: 'Run bknd inside AWS Lambda'
---
import InstallBknd from '/snippets/install-bknd.mdx';
## Installation
To get started with AWS Lambda and bknd you can either install the package manually and follow the descriptions below, or use the CLI starter:
<Tabs>
<Tab title="CLI Starter">
Create a new Bun CLI starter project by running the following command:
```sh
npx bknd create -i aws
```
</Tab>
<Tab title="Manual">
Create a new AWS Lambda project and then install bknd as a dependency:
<InstallBknd />
</Tab>
</Tabs>
## Serve the API
To serve the API, you can use the `serveLambda` function of the AWS Lambda adapter.
```tsx index.mjs
import { serveLambda } from "bknd/adapter/aws";
export const handler = serveLambda({
connection: {
url: process.env.DB_URL!,
authToken: process.env.DB_AUTH_TOKEN!
}
});
```
Although the runtime would support database as a file, we don't recommend it. You'd need to also bundle the native dependencies which increases the deployment size and cold start time.
## Serve the Admin UI
Lambda functions should be as small as possible. Therefore, the static files for the admin panel should not be served from node_modules like with the Node adapter.
Instead, we recommend to copy the static files and bundle them with the lambda function. To copy the static files, you can use the `copy-assets` command:
```bash
npx bknd copy-assets --out static
```
This will copy the static files to the `static` directory and then serve them from there:
```tsx index.mjs {8-11}
import { serveLambda } from "bknd/adapter/aws";
export const handler = serveLambda({
connection: {
url: process.env.DB_URL!,
authToken: process.env.DB_AUTH_TOKEN!
},
assets: {
mode: "local",
root: "./static"
}
});
```
## Deployment
To deploy a lambda function, you could follow these steps:
1. Create an IAM role with a trust policy that allows lambda to assume the role.
2. Attach the `AWSLambdaBasicExecutionRole` policy to the role.
3. Bundle the lambda function with the static files (e.g. using esbuild)
4. Create a zip file with the bundled lambda function
5. Create a lambda function
6. Create a function URL for the lambda function & make it publicly accessible (optional)
Depending on your use case, you may want to skip step 6 and use the AWS API Gateway to serve the lambda function. Here is an [example deployment script](https://github.com/bknd-io/bknd/blob/main/examples/aws-lambda/deploy.sh) which creates the AWS resources described above, bundles the lambda function and uploads it.
### Using the CLI starter
The CLI starter example includes a basic build script that creates the required AWS resources, copies the static files, bundles the lambda function and uploads it. To deploy the lambda function, you can run:
```bash
npm run deploy
```
To make adjustments to the lambda function created (e.g. architecture, memory, timeout, etc.) you can edit the head section of the `deploy.sh` script.
```sh deploy.sh
# cat deploy.sh | head -12
FUNCTION_NAME="bknd-lambda"
ROLE_NAME="bknd-lambda-execution-role"
RUNTIME="nodejs22.x"
HANDLER="index.handler"
ARCHITECTURE="arm64" # or "x86_64"
MEMORY="1024" # in MB, 128 is the minimum
TIMEOUT="30"
ENTRY_FILE="index.mjs"
ZIP_FILE="lambda.zip"
# ...
```
To clean up AWS resources created by the deployment script, you can run:
```bash
npm run clean
```

View File

@@ -3,7 +3,7 @@ title: 'Introduction'
description: 'Integrate bknd into your runtime/framework of choice' description: 'Integrate bknd into your runtime/framework of choice'
--- ---
import { cloudflare, nextjs, remix, astro, bun, node, docker, vite } from "/snippets/integration-icons.mdx" import { cloudflare, nextjs, remix, astro, bun, node, docker, vite, aws } from "/snippets/integration-icons.mdx"
## Start with a Framework ## Start with a Framework
bknd seamlessly integrates with popular frameworks, allowing you to use what you're already familar with. The following guides will help you get started with your framework of choice. bknd seamlessly integrates with popular frameworks, allowing you to use what you're already familar with. The following guides will help you get started with your framework of choice.
@@ -52,6 +52,11 @@ If you prefer to use a runtime instead of a framework, you can choose from the f
icon={<div className="text-primary-light">{cloudflare}</div>} icon={<div className="text-primary-light">{cloudflare}</div>}
href="/integration/cloudflare" href="/integration/cloudflare"
/> />
<Card
title="AWS Lambda"
icon={<div className="text-primary-light">{aws}</div>}
href="/integration/aws"
/>
<Card <Card
title="Vite" title="Vite"
icon={<div className="text-primary-light">{vite}</div>} icon={<div className="text-primary-light">{vite}</div>}
@@ -62,6 +67,7 @@ If you prefer to use a runtime instead of a framework, you can choose from the f
icon={<div className="text-primary-light">{docker}</div>} icon={<div className="text-primary-light">{docker}</div>}
href="/integration/docker" href="/integration/docker"
/> />
<div style={{ gridColumn: "span 2" }}>
<Card <Card
horizontal horizontal
title="Yours missing?" title="Yours missing?"
@@ -69,6 +75,7 @@ If you prefer to use a runtime instead of a framework, you can choose from the f
> >
Create a new issue to request a guide for your runtime. Create a new issue to request a guide for your runtime.
</Card> </Card>
</div>
</CardGroup> </CardGroup>
## Overview ## Overview

View File

@@ -2,16 +2,12 @@
title: Introduction title: Introduction
--- ---
import { cloudflare, nextjs, remix, astro, bun, node, docker, vite } from "/snippets/integration-icons.mdx" import { cloudflare, nextjs, remix, astro, bun, node, docker, vite, aws } from "/snippets/integration-icons.mdx"
import { Stackblitz, examples } from "/snippets/stackblitz.mdx" import { Stackblitz, examples } from "/snippets/stackblitz.mdx"
Glad you're here! This is about **bknd**, a feature-rich backend that is so lightweight it could Glad you're here! This is about **bknd**, a feature-rich backend that is so lightweight it could
run on your toaster (probably). run on your toaster (probably).
<Note>
The documentation is currently a work in progress and not complete. Updates will be made regularily.
</Note>
## Preview ## Preview
Here is a preview of **bknd** in StackBlitz: Here is a preview of **bknd** in StackBlitz:
<Stackblitz {...examples.adminRich} /> <Stackblitz {...examples.adminRich} />
@@ -72,6 +68,11 @@ in the future, so stay tuned!
icon={<div className="text-primary-light">{bun}</div>} icon={<div className="text-primary-light">{bun}</div>}
href="/integration/bun" href="/integration/bun"
/> />
<Card
title="AWS Lambda"
icon={<div className="text-primary-light">{aws}</div>}
href="/integration/aws"
/>
<Card <Card
title="Vite" title="Vite"
icon={<div className="text-primary-light">{vite}</div>} icon={<div className="text-primary-light">{vite}</div>}
@@ -82,4 +83,11 @@ in the future, so stay tuned!
icon={<div className="text-primary-light">{docker}</div>} icon={<div className="text-primary-light">{docker}</div>}
href="/integration/docker" href="/integration/docker"
/> />
<Card
horizontal
title="Yours missing?"
href="https://github.com/bknd-io/bknd/issues/new"
>
Create a new issue to request a guide for your runtime or framework.
</Card>
</CardGroup> </CardGroup>

View File

@@ -94,6 +94,7 @@
"integration/bun", "integration/bun",
"integration/cloudflare", "integration/cloudflare",
"integration/deno", "integration/deno",
"integration/aws",
"integration/docker" "integration/docker"
] ]
} }
@@ -110,20 +111,6 @@
"modules/flows" "modules/flows"
] ]
}, },
{
"group": "Deployment",
"pages": [
"deployment/overview",
{
"group": "Providers",
"pages": [
"deployment/providers/cloudflare",
"deployment/providers/vercel",
"deployment/providers/aws"
]
}
]
},
{ {
"group": "User Guide", "group": "User Guide",
"pages": ["guide/introduction", "guide/setup", "guide/admin UI"] "pages": ["guide/introduction", "guide/setup", "guide/admin UI"]

View File

@@ -1,5 +1,5 @@
{ {
"name": "@bknd/docs", "name": "bknd-docs",
"private": true, "private": true,
"scripts": { "scripts": {
"dev": "mintlify dev" "dev": "mintlify dev"

View File

@@ -29,3 +29,5 @@ export const vite = <svg xmlns="http://www.w3.org/2000/svg" width="28" height="2
export const docker = <svg xmlns="http://www.w3.org/2000/svg" width={30} height={30} viewBox="0 0 24 24"><path export const docker = <svg xmlns="http://www.w3.org/2000/svg" width={30} height={30} viewBox="0 0 24 24"><path
fill="currentColor" d="M21.81 10.25c-.06-.04-.56-.43-1.64-.43c-.28 0-.56.03-.84.08c-.21-1.4-1.38-2.11-1.43-2.14l-.29-.17l-.18.27c-.24.36-.43.77-.51 1.19c-.2.8-.08 1.56.33 2.21c-.49.28-1.29.35-1.46.35H2.62c-.34 0-.62.28-.62.63c0 1.15.18 2.3.58 3.38c.45 1.19 1.13 2.07 2 2.61c.98.6 2.59.94 4.42.94c.79 0 1.61-.07 2.42-.22c1.12-.2 2.2-.59 3.19-1.16A8.3 8.3 0 0 0 16.78 16c1.05-1.17 1.67-2.5 2.12-3.65h.19c1.14 0 1.85-.46 2.24-.85c.26-.24.45-.53.59-.87l.08-.24zm-17.96.99h1.76c.08 0 .16-.07.16-.16V9.5c0-.08-.07-.16-.16-.16H3.85c-.09 0-.16.07-.16.16v1.58c.01.09.07.16.16.16m2.43 0h1.76c.08 0 .16-.07.16-.16V9.5c0-.08-.07-.16-.16-.16H6.28c-.09 0-.16.07-.16.16v1.58c.01.09.07.16.16.16m2.47 0h1.75c.1 0 .17-.07.17-.16V9.5c0-.08-.06-.16-.17-.16H8.75c-.08 0-.15.07-.15.16v1.58c0 .09.06.16.15.16m2.44 0h1.77c.08 0 .15-.07.15-.16V9.5c0-.08-.06-.16-.15-.16h-1.77c-.08 0-.15.07-.15.16v1.58c0 .09.07.16.15.16M6.28 9h1.76c.08 0 .16-.09.16-.18V7.25c0-.09-.07-.16-.16-.16H6.28c-.09 0-.16.06-.16.16v1.57c.01.09.07.18.16.18m2.47 0h1.75c.1 0 .17-.09.17-.18V7.25c0-.09-.06-.16-.17-.16H8.75c-.08 0-.15.06-.15.16v1.57c0 .09.06.18.15.18m2.44 0h1.77c.08 0 .15-.09.15-.18V7.25c0-.09-.07-.16-.15-.16h-1.77c-.08 0-.15.06-.15.16v1.57c0 .09.07.18.15.18m0-2.28h1.77c.08 0 .15-.07.15-.16V5c0-.1-.07-.17-.15-.17h-1.77c-.08 0-.15.06-.15.17v1.56c0 .08.07.16.15.16m2.46 4.52h1.76c.09 0 .16-.07.16-.16V9.5c0-.08-.07-.16-.16-.16h-1.76c-.08 0-.15.07-.15.16v1.58c0 .09.07.16.15.16"></path></svg> fill="currentColor" d="M21.81 10.25c-.06-.04-.56-.43-1.64-.43c-.28 0-.56.03-.84.08c-.21-1.4-1.38-2.11-1.43-2.14l-.29-.17l-.18.27c-.24.36-.43.77-.51 1.19c-.2.8-.08 1.56.33 2.21c-.49.28-1.29.35-1.46.35H2.62c-.34 0-.62.28-.62.63c0 1.15.18 2.3.58 3.38c.45 1.19 1.13 2.07 2 2.61c.98.6 2.59.94 4.42.94c.79 0 1.61-.07 2.42-.22c1.12-.2 2.2-.59 3.19-1.16A8.3 8.3 0 0 0 16.78 16c1.05-1.17 1.67-2.5 2.12-3.65h.19c1.14 0 1.85-.46 2.24-.85c.26-.24.45-.53.59-.87l.08-.24zm-17.96.99h1.76c.08 0 .16-.07.16-.16V9.5c0-.08-.07-.16-.16-.16H3.85c-.09 0-.16.07-.16.16v1.58c.01.09.07.16.16.16m2.43 0h1.76c.08 0 .16-.07.16-.16V9.5c0-.08-.07-.16-.16-.16H6.28c-.09 0-.16.07-.16.16v1.58c.01.09.07.16.16.16m2.47 0h1.75c.1 0 .17-.07.17-.16V9.5c0-.08-.06-.16-.17-.16H8.75c-.08 0-.15.07-.15.16v1.58c0 .09.06.16.15.16m2.44 0h1.77c.08 0 .15-.07.15-.16V9.5c0-.08-.06-.16-.15-.16h-1.77c-.08 0-.15.07-.15.16v1.58c0 .09.07.16.15.16M6.28 9h1.76c.08 0 .16-.09.16-.18V7.25c0-.09-.07-.16-.16-.16H6.28c-.09 0-.16.06-.16.16v1.57c.01.09.07.18.16.18m2.47 0h1.75c.1 0 .17-.09.17-.18V7.25c0-.09-.06-.16-.17-.16H8.75c-.08 0-.15.06-.15.16v1.57c0 .09.06.18.15.18m2.44 0h1.77c.08 0 .15-.09.15-.18V7.25c0-.09-.07-.16-.15-.16h-1.77c-.08 0-.15.06-.15.16v1.57c0 .09.07.18.15.18m0-2.28h1.77c.08 0 .15-.07.15-.16V5c0-.1-.07-.17-.15-.17h-1.77c-.08 0-.15.06-.15.17v1.56c0 .08.07.16.15.16m2.46 4.52h1.76c.09 0 .16-.07.16-.16V9.5c0-.08-.07-.16-.16-.16h-1.76c-.08 0-.15.07-.15.16v1.58c0 .09.07.16.15.16"></path></svg>
export const aws = <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path fill="currentColor" d="M4.986 0a.545.545 0 0 0-.534.548l-.006 4.908c0 .145.06.283.159.39a.53.53 0 0 0 .38.155h3.429l8.197 17.68a.54.54 0 0 0 .488.319h5.811a.547.547 0 0 0 .543-.548v-4.908a.543.543 0 0 0-.543-.548h-2.013L12.739.316A.55.55 0 0 0 12.245 0H4.991Zm.54 1.09h6.367l8.16 17.681a.54.54 0 0 0 .489.318h1.817v3.817h-4.922L9.24 5.226a.54.54 0 0 0-.488-.318h-3.23Zm2.013 8.237a.54.54 0 0 0-.486.31L.6 23.213a.55.55 0 0 0 .032.528a.53.53 0 0 0 .454.25h6.169a.55.55 0 0 0 .497-.31l3.38-7.165a.54.54 0 0 0-.003-.469l-3.093-6.41a.55.55 0 0 0-.494-.31Zm.006 1.804l2.488 5.152l-3.122 6.62H1.947Z" stroke-width="0.5" stroke="currentColor"/></svg>

View File

@@ -44,6 +44,6 @@
}, },
"workspaces": [ "workspaces": [
"app", "app",
"docs" "packages/*"
] ]
} }