Skip to content

Commit c9e0511

Browse files
committed
docs(changeset): Add AWS Lambda option
1 parent 81a4fb3 commit c9e0511

File tree

11 files changed

+313
-171
lines changed

11 files changed

+313
-171
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@storybooker/aws": minor
3+
"@storybooker/azure": patch
4+
---
5+
6+
Add AWS Lambda option

apps/aws-lambda-app/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// @ts-check
2+
3+
import { AwsDynamoDatabaseService } from "@storybooker/aws/dynamo-db";
4+
import { createStoryBookerRouterHandler } from "@storybooker/aws/lambda";
5+
import { AwsS3StorageService } from "@storybooker/aws/s3";
6+
7+
export const handler = createStoryBookerRouterHandler({
8+
database: new AwsDynamoDatabaseService({}),
9+
storage: new AwsS3StorageService({}),
10+
});

apps/aws-lambda-app/package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "aws-lambda-app",
3+
"type": "module",
4+
"main": "index.js",
5+
"dependencies": {
6+
"@storybooker/aws": "workspace:*"
7+
}
8+
}

packages/aws/README.md

Lines changed: 39 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,71 @@
1-
# StoryBooker adapter for Azure Storage
1+
# StoryBooker adapters for AWS
22

3-
Create service adapters for Azure Storage.
3+
Create service adapters for AWS services.
44

55
## Auth
66

7-
The Azure EasyAuth provides quick way to setup auth for Azure Functions
8-
9-
```ts
10-
import {
11-
AzureEasyAuthService,
12-
type AuthServiceAuthorise,
13-
} from "@storybooker/azure/easy-auth";
14-
15-
const authorize: AuthServiceAuthorise = async (permission, { user }) => {
16-
// check permission against user (roles)
17-
return true; // or false
18-
};
19-
const auth = new AzureEasyAuthService(authorise);
20-
21-
// use as auth in StoryBooker options.
22-
```
7+
> Currently no auth adapter available for AWS.
238
249
## Database
2510

26-
The Azure Storage provides 2 options which can be used as database for StoryBooker.
27-
28-
### Data Tables
29-
30-
```ts
31-
import { AzureDataTablesDatabaseService } from "@storybooker/azure/data-tables";
32-
33-
const connectionString = process.env["AZURE_STORAGE_CONNECTION_STRING"];
34-
const database = new AzureDataTablesDatabaseService(connectionString);
35-
36-
// use as database in StoryBooker options.
37-
```
11+
### DynamoDB
3812

39-
### Cosmos DB
13+
The adapter constructor accepts either a pre-configured `DynamoDBClient` instance or a configuration object for the client.
4014

4115
```ts
42-
import { AzureCosmosDatabaseService } from "@storybooker/azure/cosmos-db";
16+
import { AwsDynamoDatabaseService } from "@storybooker/aws/dynamo-db";
4317

44-
const connectionString = process.env["AZURE_COSMOS_DB_CONNECTION_STRING"];
45-
const database = new AzureCosmosDatabaseService(connectionString);
18+
const database = new AwsDynamoDatabaseService({
19+
region: process.env["AWS_REGION"],
20+
credentials: {
21+
accessKeyId: process.env["AWS_ACCESS_KEY_ID"],
22+
secretAccessKey: process.env["AWS_SECRET_ACCESS_KEY"],
23+
},
24+
});
4625

4726
// use as database in StoryBooker options.
4827
```
4928

5029
## Storage
5130

52-
The Azure Storage provides BlobStorage which can be used as storage for StoryBooker.
31+
The AWS S3 provides BlobStorage which can be used as storage for StoryBooker.
5332

5433
```ts
55-
import { AzureBlobStorageService } from "@storybooker/azure/blob-storage";
56-
57-
const connectionString = process.env["AZURE_STORAGE_CONNECTION_STRING"];
58-
const storage = new AzureBlobStorageService(connectionString);
34+
import { AwsS3StorageService } from "@storybooker/aws/s3";
35+
36+
const bucketName = process.env["AWS_S3_BUCKET_NAME"];
37+
const storage = new AwsS3StorageService({
38+
region: process.env["AWS_REGION"],
39+
credentials: {
40+
accessKeyId: process.env["AWS_ACCESS_KEY_ID"]!,
41+
secretAccessKey: process.env["AWS_SECRET_ACCESS_KEY"]!,
42+
},
43+
});
5944

6045
// use as storage in StoryBooker options.
6146
```
6247

63-
## Hosting StoryBooker in Azure Functions
48+
## Hosting StoryBooker via AWS Lambda + API Gateway
6449

6550
> For deploying:
6651
>
67-
> - Set Azure Functions runtime to `Node` and version to `22 LTS` or higher.
68-
> - Set environment variable in deployment for `AzureWebJobsStorage` if not already done.
52+
> - The AWS Lambda function should be have a HTTP API Gateway trigger.
53+
> - The Trigger should have `/{proxy+}` route with ANY method.
6954
70-
Create following files in your Azure Functions project.
55+
Create following files in your AWS Lambda project.
7156

7257
### `index.js`
7358

7459
```js
75-
import { AzureBlobStorageService } from "@storybooker/azure/blob-storage";
76-
import { AzureDataTablesDatabaseService } from "@storybooker/azure/data-tables";
77-
import { AzureEasyAuthService } from "@storybooker/azure/easy-auth";
78-
import { registerStoryBookerRouter } from "@storybooker/azure/functions";
79-
80-
const storageConnectionString = process.env["AzureWebJobsStorage"];
81-
if (!storageConnectionString) {
82-
throw new Error(
83-
`The storage connectionString is required to connect with Azure Storage resource.`,
84-
);
85-
}
60+
// @ts-check
8661

87-
registerStoryBookerRouter({
88-
auth: new AzureEasyAuthService(), // optional auth adapter
89-
database: new AzureDataTablesDatabaseService(storageConnectionString),
90-
storage: new AzureBlobStorageService(storageConnectionString),
62+
import { AwsDynamoDatabaseService } from "@storybooker/aws/dynamo-db";
63+
import { createStoryBookerRouterHandler } from "@storybooker/aws/lambda";
64+
import { AwsS3StorageService } from "@storybooker/aws/s3";
65+
66+
export const handler = createStoryBookerRouterHandler({
67+
database: new AwsDynamoDatabaseService({}),
68+
storage: new AwsS3StorageService({}),
9169
});
9270
```
9371

@@ -99,37 +77,9 @@ registerStoryBookerRouter({
9977
"type": "module",
10078
"main": "index.js",
10179
"dependencies": {
102-
"@azure/functions": "^4.0.0",
103-
"@azure/data-tables": "^13.0.0",
104-
"@azure/storage-blob": "^12.0.0",
105-
"@storybooker/azure": "latest"
106-
}
107-
}
108-
```
109-
110-
### `host.json`
111-
112-
```json
113-
{
114-
"version": "2.0",
115-
"extensionBundle": {
116-
"id": "Microsoft.Azure.Functions.ExtensionBundle",
117-
"version": "[4.*, 5.0.0)"
118-
},
119-
"extensions": { "http": { "routePrefix": "" } }
120-
}
121-
```
122-
123-
### `local.settings.json` (for local dev only)
124-
125-
> Must not be committed to source control (git).
126-
127-
```json
128-
{
129-
"IsEncrypted": false,
130-
"Values": {
131-
"FUNCTIONS_WORKER_RUNTIME": "node",
132-
"AzureWebJobsStorage": "UseDevelopmentStorage=true"
80+
"@aws-sdk/client-dynamodb": "^3.0.0",
81+
"@aws-sdk/client-s3": "^3.0.0",
82+
"@storybooker/aws": "latest"
13383
}
13484
}
13585
```

packages/aws/package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@
4848
"import": "./dist/dynamo-db.js",
4949
"require": "./dist/dynamo-db.cjs"
5050
},
51+
"./lambda": {
52+
"source": "./src/lambda.ts",
53+
"import": "./dist/lambda.js",
54+
"require": "./dist/lambda.cjs"
55+
},
5156
"./s3": {
5257
"source": "./src/s3.ts",
5358
"import": "./dist/s3.js",
@@ -68,6 +73,7 @@
6873
"@aws-sdk/client-dynamodb": "^3.895.0",
6974
"@aws-sdk/client-s3": "^3.895.0",
7075
"@storybooker/core": "workspace:^",
76+
"@types/aws-lambda": "^8.10.152",
7177
"@types/node": "^22.0.0",
7278
"@typescript/native-preview": "^7.0.0-dev.20250823.8",
7379
"oxlint": "^1.12.0",
@@ -97,6 +103,10 @@
97103
"import": "./dist/dynamo-db.js",
98104
"require": "./dist/dynamo-db.cjs"
99105
},
106+
"./lambda": {
107+
"import": "./dist/lambda.js",
108+
"require": "./dist/lambda.cjs"
109+
},
100110
"./s3": {
101111
"import": "./dist/s3.js",
102112
"require": "./dist/s3.cjs"

0 commit comments

Comments
 (0)