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```
0 commit comments