@flightdev/adapter-aws 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024-2026 Flight Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,167 @@
1
+ # @flight-framework/adapter-aws
2
+
3
+ AWS Lambda deployment adapter for Flight Framework. Deploy to Lambda with API Gateway or Lambda URLs.
4
+
5
+ ## Table of Contents
6
+
7
+ - [Installation](#installation)
8
+ - [Quick Start](#quick-start)
9
+ - [Configuration](#configuration)
10
+ - [Deployment Options](#deployment-options)
11
+ - [Build Output](#build-output)
12
+ - [Deployment](#deployment)
13
+ - [License](#license)
14
+
15
+ ---
16
+
17
+ ## Installation
18
+
19
+ ```bash
20
+ npm install @flight-framework/adapter-aws
21
+ ```
22
+
23
+ ---
24
+
25
+ ## Quick Start
26
+
27
+ ```typescript
28
+ // flight.config.ts
29
+ import { defineConfig } from '@flight-framework/core';
30
+ import aws from '@flight-framework/adapter-aws';
31
+
32
+ export default defineConfig({
33
+ adapter: aws(),
34
+ });
35
+ ```
36
+
37
+ ---
38
+
39
+ ## Configuration
40
+
41
+ ```typescript
42
+ aws({
43
+ // Lambda runtime
44
+ runtime: 'nodejs20.x',
45
+
46
+ // Memory allocation (MB)
47
+ memory: 512,
48
+
49
+ // Timeout (seconds)
50
+ timeout: 30,
51
+
52
+ // Architecture
53
+ architecture: 'arm64', // or 'x86_64'
54
+
55
+ // Region
56
+ region: 'us-east-1',
57
+
58
+ // Use Lambda URLs (simpler, no API Gateway)
59
+ lambdaUrl: true,
60
+
61
+ // Streaming responses
62
+ streaming: true,
63
+ });
64
+ ```
65
+
66
+ ---
67
+
68
+ ## Deployment Options
69
+
70
+ ### Lambda Function URLs
71
+
72
+ Simplest option, no API Gateway needed:
73
+
74
+ ```typescript
75
+ aws({
76
+ lambdaUrl: true,
77
+ });
78
+ ```
79
+
80
+ ### API Gateway HTTP API
81
+
82
+ For custom domains and API features:
83
+
84
+ ```typescript
85
+ aws({
86
+ apiGateway: 'http', // HTTP API (v2)
87
+ });
88
+ ```
89
+
90
+ ### API Gateway REST API
91
+
92
+ Full control with request/response transformations:
93
+
94
+ ```typescript
95
+ aws({
96
+ apiGateway: 'rest', // REST API (v1)
97
+ });
98
+ ```
99
+
100
+ ---
101
+
102
+ ## Build Output
103
+
104
+ ```
105
+ .aws/
106
+ ├── lambda/
107
+ │ ├── index.mjs # Lambda handler
108
+ │ └── chunks/ # Code-split chunks
109
+ ├── static/ # S3 static assets
110
+ └── template.yaml # SAM template (optional)
111
+ ```
112
+
113
+ ---
114
+
115
+ ## Deployment
116
+
117
+ ### AWS SAM
118
+
119
+ ```bash
120
+ # Install SAM CLI
121
+ brew install aws-sam-cli
122
+
123
+ # Build
124
+ npm run build
125
+
126
+ # Deploy
127
+ sam deploy --guided
128
+ ```
129
+
130
+ ### SST (Recommended)
131
+
132
+ ```typescript
133
+ // sst.config.ts
134
+ export default {
135
+ config() {
136
+ return { name: 'my-flight-app', region: 'us-east-1' };
137
+ },
138
+ stacks(app) {
139
+ app.stack(({ stack }) => {
140
+ const site = new SsrSite(stack, 'Site', {
141
+ path: '.',
142
+ });
143
+ stack.addOutputs({ URL: site.url });
144
+ });
145
+ },
146
+ };
147
+ ```
148
+
149
+ ### Terraform
150
+
151
+ ```hcl
152
+ resource "aws_lambda_function" "app" {
153
+ filename = ".aws/lambda.zip"
154
+ function_name = "my-flight-app"
155
+ role = aws_iam_role.lambda.arn
156
+ handler = "index.handler"
157
+ runtime = "nodejs20.x"
158
+ memory_size = 512
159
+ timeout = 30
160
+ }
161
+ ```
162
+
163
+ ---
164
+
165
+ ## License
166
+
167
+ MIT
@@ -0,0 +1,60 @@
1
+ import { FlightAdapter } from '@flightdev/core/adapters';
2
+
3
+ /**
4
+ * Flight Adapter - AWS
5
+ *
6
+ * Deploy to AWS Lambda, Amplify Hosting, or API Gateway.
7
+ * Full AWS ecosystem integration with zero lock-in.
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * import { defineConfig } from '@flightdev/core';
12
+ * import aws from '@flightdev/adapter-aws';
13
+ *
14
+ * export default defineConfig({
15
+ * adapter: aws({
16
+ * target: 'lambda', // 'lambda' | 'amplify' | 'lambda-streaming'
17
+ * region: 'us-east-1',
18
+ * }),
19
+ * });
20
+ * ```
21
+ */
22
+
23
+ interface AWSAdapterOptions {
24
+ /**
25
+ * Deployment target
26
+ * - 'lambda': Standard AWS Lambda
27
+ * - 'lambda-streaming': Lambda with response streaming (Node 18+)
28
+ * - 'amplify': AWS Amplify Hosting
29
+ * @default 'lambda'
30
+ */
31
+ target?: 'lambda' | 'lambda-streaming' | 'amplify';
32
+ /**
33
+ * AWS Region
34
+ * @default 'us-east-1'
35
+ */
36
+ region?: string;
37
+ /**
38
+ * Lambda memory size in MB
39
+ * @default 1024
40
+ */
41
+ memory?: number;
42
+ /**
43
+ * Lambda timeout in seconds
44
+ * @default 10
45
+ */
46
+ timeout?: number;
47
+ /**
48
+ * Lambda architecture
49
+ * @default 'x86_64'
50
+ */
51
+ architecture?: 'x86_64' | 'arm64';
52
+ /**
53
+ * Enable Lambda@Edge for CloudFront
54
+ * @default false
55
+ */
56
+ edge?: boolean;
57
+ }
58
+ declare function awsAdapter(options?: AWSAdapterOptions): FlightAdapter;
59
+
60
+ export { type AWSAdapterOptions, awsAdapter, awsAdapter as default };
package/dist/index.js ADDED
@@ -0,0 +1,245 @@
1
+ // src/index.ts
2
+ import { createAdapter } from "@flightdev/core/adapters";
3
+ function awsAdapter(options = {}) {
4
+ const {
5
+ target = "lambda",
6
+ region = "us-east-1",
7
+ memory = 1024,
8
+ timeout = 10,
9
+ architecture = "x86_64",
10
+ edge = false
11
+ } = options;
12
+ return createAdapter({
13
+ name: "@flightdev/adapter-aws",
14
+ async adapt(builder) {
15
+ const { outDir, log } = builder;
16
+ log.info(`Generating AWS ${target} output...`);
17
+ switch (target) {
18
+ case "amplify":
19
+ await adaptForAmplify(builder, options);
20
+ break;
21
+ case "lambda-streaming":
22
+ await adaptForLambdaStreaming(builder, options);
23
+ break;
24
+ default:
25
+ await adaptForLambda(builder, options);
26
+ }
27
+ await builder.copy(`${outDir}/client`, `${outDir}/public`);
28
+ const samTemplate = generateSAMTemplate({ region, memory, timeout, architecture, edge });
29
+ await builder.writeFile("template.yaml", samTemplate);
30
+ log.info("Created SAM template.yaml");
31
+ log.info(`
32
+ AWS adapter complete!
33
+
34
+ Output: ${outDir}
35
+
36
+ To deploy with SAM:
37
+ sam build
38
+ sam deploy --guided
39
+
40
+ To deploy with CDK:
41
+ cdk deploy
42
+
43
+ To deploy with Amplify:
44
+ amplify push
45
+ `);
46
+ },
47
+ emulate: () => ({
48
+ env: {
49
+ AWS_REGION: region,
50
+ AWS_LAMBDA_FUNCTION_NAME: "flight-local",
51
+ _HANDLER: "index.handler"
52
+ }
53
+ }),
54
+ supports: {
55
+ read: () => true,
56
+ streaming: () => target === "lambda-streaming",
57
+ websockets: () => false,
58
+ node: () => true,
59
+ edge: () => edge
60
+ }
61
+ });
62
+ }
63
+ async function adaptForLambda(builder, _options) {
64
+ const { log } = builder;
65
+ log.info("Generating Lambda handler...");
66
+ const handler = `
67
+ // Flight + AWS Lambda Handler
68
+ // Compatible with API Gateway v2 (HTTP API) and v1 (REST API)
69
+
70
+ export const handler = async (event, context) => {
71
+ const path = event.rawPath || event.path || '/';
72
+ const method = event.requestContext?.http?.method || event.httpMethod || 'GET';
73
+ const headers = event.headers || {};
74
+ const body = event.body;
75
+ const isBase64 = event.isBase64Encoded;
76
+
77
+ // Create Web API Request
78
+ const url = new URL(path, 'http://localhost');
79
+ if (event.queryStringParameters) {
80
+ Object.entries(event.queryStringParameters).forEach(([k, v]) => {
81
+ url.searchParams.set(k, v);
82
+ });
83
+ }
84
+
85
+ const request = new Request(url.toString(), {
86
+ method,
87
+ headers,
88
+ body: body ? (isBase64 ? Buffer.from(body, 'base64') : body) : undefined,
89
+ });
90
+
91
+ // TODO: Integrate with Flight render engine
92
+
93
+ return {
94
+ statusCode: 200,
95
+ headers: {
96
+ 'Content-Type': 'text/html',
97
+ },
98
+ body: \`
99
+ <!DOCTYPE html>
100
+ <html>
101
+ <head><title>Flight on AWS Lambda</title></head>
102
+ <body>
103
+ <h1>Flight \u2708\uFE0F + AWS Lambda</h1>
104
+ <p>Path: \${path}</p>
105
+ <p>Region: \${context.invokedFunctionArn?.split(':')[3] || 'local'}</p>
106
+ </body>
107
+ </html>
108
+ \`,
109
+ isBase64Encoded: false,
110
+ };
111
+ };
112
+ `;
113
+ await builder.writeFile(".output/server/index.mjs", handler);
114
+ log.info("Created .output/server/index.mjs");
115
+ }
116
+ async function adaptForLambdaStreaming(builder, _options) {
117
+ const { log } = builder;
118
+ log.info("Generating Lambda Streaming handler...");
119
+ const handler = `
120
+ // Flight + AWS Lambda Streaming Handler
121
+ // Uses Lambda Web Adapter for streaming responses
122
+
123
+ import { Readable } from 'stream';
124
+ import { pipeline } from 'stream/promises';
125
+
126
+ export const handler = awslambda.streamifyResponse(async (event, responseStream, context) => {
127
+ const path = event.rawPath || '/';
128
+
129
+ // Set response metadata
130
+ const metadata = {
131
+ statusCode: 200,
132
+ headers: {
133
+ 'Content-Type': 'text/html',
134
+ 'Transfer-Encoding': 'chunked',
135
+ },
136
+ };
137
+
138
+ responseStream = awslambda.HttpResponseStream.from(responseStream, metadata);
139
+
140
+ // TODO: Integrate with Flight render engine for streaming
141
+
142
+ responseStream.write('<!DOCTYPE html><html><body>');
143
+ responseStream.write('<h1>Flight \u2708\uFE0F + Lambda Streaming</h1>');
144
+ responseStream.write('<p>Path: ' + path + '</p>');
145
+ responseStream.write('</body></html>');
146
+ responseStream.end();
147
+ });
148
+ `;
149
+ await builder.writeFile(".output/server/index.mjs", handler);
150
+ log.info("Created streaming handler");
151
+ }
152
+ async function adaptForAmplify(builder, _options) {
153
+ const { log } = builder;
154
+ log.info("Generating Amplify configuration...");
155
+ const amplifyConfig = {
156
+ version: 1,
157
+ applications: [{
158
+ frontend: {
159
+ phases: {
160
+ build: {
161
+ commands: ["npm ci", "npm run build"]
162
+ }
163
+ },
164
+ artifacts: {
165
+ baseDirectory: ".output/public",
166
+ files: ["**/*"]
167
+ },
168
+ cache: {
169
+ paths: ["node_modules/**/*"]
170
+ }
171
+ }
172
+ }]
173
+ };
174
+ await builder.writeFile("amplify.yml", JSON.stringify(amplifyConfig, null, 2));
175
+ const handler = `
176
+ export async function handler(event) {
177
+ const path = event.rawPath || '/';
178
+
179
+ return {
180
+ statusCode: 200,
181
+ headers: { 'Content-Type': 'text/html' },
182
+ body: '<h1>Flight + Amplify</h1>',
183
+ };
184
+ }
185
+ `;
186
+ await builder.writeFile(".output/server/index.mjs", handler);
187
+ log.info("Created Amplify handler");
188
+ }
189
+ function generateSAMTemplate(options) {
190
+ return `# Flight + AWS SAM Template
191
+ # Generated by @flightdev/adapter-aws
192
+
193
+ AWSTemplateFormatVersion: '2010-09-09'
194
+ Transform: AWS::Serverless-2016-10-31
195
+ Description: Flight Framework Application
196
+
197
+ Globals:
198
+ Function:
199
+ Timeout: ${options.timeout}
200
+ MemorySize: ${options.memory}
201
+ Runtime: nodejs20.x
202
+ Architectures:
203
+ - ${options.architecture}
204
+
205
+ Resources:
206
+ FlightFunction:
207
+ Type: AWS::Serverless::Function
208
+ Properties:
209
+ Handler: index.handler
210
+ CodeUri: .output/server/
211
+ Description: Flight Framework SSR Handler
212
+ Events:
213
+ Api:
214
+ Type: HttpApi
215
+ Properties:
216
+ Path: /{proxy+}
217
+ Method: ANY
218
+ Root:
219
+ Type: HttpApi
220
+ Properties:
221
+ Path: /
222
+ Method: ANY
223
+
224
+ StaticAssets:
225
+ Type: AWS::S3::Bucket
226
+ Properties:
227
+ BucketName: !Sub '\${AWS::StackName}-assets'
228
+ PublicAccessBlockConfiguration:
229
+ BlockPublicAcls: false
230
+ WebsiteConfiguration:
231
+ IndexDocument: index.html
232
+
233
+ Outputs:
234
+ ApiUrl:
235
+ Description: "API Gateway endpoint URL"
236
+ Value: !Sub "https://\${ServerlessHttpApi}.execute-api.\${AWS::Region}.amazonaws.com/"
237
+ FunctionArn:
238
+ Description: "Lambda Function ARN"
239
+ Value: !GetAtt FlightFunction.Arn
240
+ `;
241
+ }
242
+ export {
243
+ awsAdapter,
244
+ awsAdapter as default
245
+ };
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@flightdev/adapter-aws",
3
+ "version": "0.0.6",
4
+ "description": "AWS adapter for Flight Framework - deploy to Lambda, Amplify, or API Gateway",
5
+ "keywords": [
6
+ "flight",
7
+ "adapter",
8
+ "aws",
9
+ "lambda",
10
+ "amplify",
11
+ "serverless"
12
+ ],
13
+ "license": "MIT",
14
+ "type": "module",
15
+ "exports": {
16
+ ".": {
17
+ "types": "./dist/index.d.ts",
18
+ "import": "./dist/index.js"
19
+ }
20
+ },
21
+ "main": "./dist/index.js",
22
+ "types": "./dist/index.d.ts",
23
+ "files": [
24
+ "dist"
25
+ ],
26
+ "dependencies": {
27
+ "@flightdev/core": "0.6.7"
28
+ },
29
+ "devDependencies": {
30
+ "@types/node": "^22.0.0",
31
+ "rimraf": "^6.0.0",
32
+ "tsup": "^8.0.0",
33
+ "typescript": "^5.7.0"
34
+ },
35
+ "scripts": {
36
+ "build": "tsup",
37
+ "dev": "tsup --watch",
38
+ "clean": "rimraf dist",
39
+ "typecheck": "tsc --noEmit"
40
+ }
41
+ }