@fy-stack/app-construct 0.0.123 → 0.0.125
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/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -7
- package/dist/lib/deno-api-construct.d.ts.map +1 -1
- package/dist/lib/deno-api-construct.js +2 -4
- package/dist/lib/image-app-construct.d.ts +19 -0
- package/dist/lib/image-app-construct.d.ts.map +1 -0
- package/dist/lib/image-app-construct.js +72 -0
- package/dist/lib/nest-construct.d.ts +1 -1
- package/dist/lib/nest-construct.d.ts.map +1 -1
- package/dist/lib/nest-construct.js +2 -4
- package/dist/lib/next-app-router-construct.d.ts +0 -5
- package/dist/lib/next-app-router-construct.d.ts.map +1 -1
- package/dist/lib/next-app-router-construct.js +17 -33
- package/dist/lib/node-api-construct.d.ts +30 -0
- package/dist/lib/node-api-construct.d.ts.map +1 -0
- package/dist/lib/node-api-construct.js +83 -0
- package/dist/lib/node-app-construct.d.ts +19 -0
- package/dist/lib/node-app-construct.d.ts.map +1 -0
- package/dist/lib/node-app-construct.js +57 -0
- package/dist/lib/types.d.ts +1 -1
- package/dist/lib/types.d.ts.map +1 -1
- package/dist/lib/utils/lambda-api.d.ts +6 -0
- package/dist/lib/utils/lambda-api.d.ts.map +1 -0
- package/dist/lib/utils/lambda-api.js +14 -0
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
1
|
+
export { NodeApiConstruct } from './lib/node-api-construct';
|
|
2
|
+
export { NodeAppConstruct } from './lib/node-app-construct';
|
|
3
3
|
export { NextAppRouterConstruct } from './lib/next-app-router-construct';
|
|
4
|
-
export {
|
|
4
|
+
export { ImageAppConstruct } from './lib/image-app-construct';
|
|
5
5
|
export type { AppConstruct, AppProperties } from "./lib/types";
|
|
6
6
|
export { lambdaAttach } from "./lib/utils/lambda-attach";
|
|
7
7
|
export { lambdaGrant } from "./lib/utils/lambda-grant";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AACzE,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.lambdaGrant = exports.lambdaAttach = exports.
|
|
4
|
-
var
|
|
5
|
-
Object.defineProperty(exports, "
|
|
6
|
-
var
|
|
7
|
-
Object.defineProperty(exports, "
|
|
3
|
+
exports.lambdaGrant = exports.lambdaAttach = exports.ImageAppConstruct = exports.NextAppRouterConstruct = exports.NodeAppConstruct = exports.NodeApiConstruct = void 0;
|
|
4
|
+
var node_api_construct_1 = require("./lib/node-api-construct");
|
|
5
|
+
Object.defineProperty(exports, "NodeApiConstruct", { enumerable: true, get: function () { return node_api_construct_1.NodeApiConstruct; } });
|
|
6
|
+
var node_app_construct_1 = require("./lib/node-app-construct");
|
|
7
|
+
Object.defineProperty(exports, "NodeAppConstruct", { enumerable: true, get: function () { return node_app_construct_1.NodeAppConstruct; } });
|
|
8
8
|
var next_app_router_construct_1 = require("./lib/next-app-router-construct");
|
|
9
9
|
Object.defineProperty(exports, "NextAppRouterConstruct", { enumerable: true, get: function () { return next_app_router_construct_1.NextAppRouterConstruct; } });
|
|
10
|
-
var
|
|
11
|
-
Object.defineProperty(exports, "
|
|
10
|
+
var image_app_construct_1 = require("./lib/image-app-construct");
|
|
11
|
+
Object.defineProperty(exports, "ImageAppConstruct", { enumerable: true, get: function () { return image_app_construct_1.ImageAppConstruct; } });
|
|
12
12
|
var lambda_attach_1 = require("./lib/utils/lambda-attach");
|
|
13
13
|
Object.defineProperty(exports, "lambdaAttach", { enumerable: true, get: function () { return lambda_attach_1.lambdaAttach; } });
|
|
14
14
|
var lambda_grant_1 = require("./lib/utils/lambda-grant");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deno-api-construct.d.ts","sourceRoot":"","sources":["../../src/lib/deno-api-construct.ts"],"names":[],"mappings":"AAAA,OAAO,EAAG,UAAU,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEzD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"deno-api-construct.d.ts","sourceRoot":"","sources":["../../src/lib/deno-api-construct.ts"],"names":[],"mappings":"AAAA,OAAO,EAAG,UAAU,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEzD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACzE,OAAO,EAEL,eAAe,EAKhB,MAAM,4BAA4B,CAAC;AAGpC,OAAO,EAEL,QAAQ,EAIT,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAK5E,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAKtD,qBAAa,gBACX,SAAQ,SACR,YAAW,YAAY;IAEhB,QAAQ,EAAE,QAAQ,CAAC;IACnB,KAAK,EAAE,KAAK,GAAG,SAAS,CAAC;gBAEpB,KAAK,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa;IA2B9D,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,GAAG,IAAI;IAIpD,KAAK,CAAC,GAAG,UAAU,EAAE,SAAS,EAAE,GAAG,IAAI;IAIvC,YAAY,CAAC,KAAK,EAAE,iBAAiB,GAAG,kBAAkB;IAQ1D,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC;IAqBzD,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAC;CAGxD"}
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DenoApiConstruct = void 0;
|
|
4
4
|
const aws_cdk_lib_1 = require("aws-cdk-lib");
|
|
5
|
-
const aws_apigatewayv2_integrations_1 = require("aws-cdk-lib/aws-apigatewayv2-integrations");
|
|
6
5
|
const aws_cloudfront_1 = require("aws-cdk-lib/aws-cloudfront");
|
|
7
6
|
const aws_cloudfront_origins_1 = require("aws-cdk-lib/aws-cloudfront-origins");
|
|
8
7
|
const aws_ecr_assets_1 = require("aws-cdk-lib/aws-ecr-assets");
|
|
@@ -13,6 +12,7 @@ const aws_sqs_1 = require("aws-cdk-lib/aws-sqs");
|
|
|
13
12
|
const constructs_1 = require("constructs");
|
|
14
13
|
const lambda_attach_1 = require("./utils/lambda-attach");
|
|
15
14
|
const lambda_grant_1 = require("./utils/lambda-grant");
|
|
15
|
+
const lambda_api_1 = require("./utils/lambda-api");
|
|
16
16
|
class DenoApiConstruct extends constructs_1.Construct {
|
|
17
17
|
function;
|
|
18
18
|
queue;
|
|
@@ -66,9 +66,7 @@ class DenoApiConstruct extends constructs_1.Construct {
|
|
|
66
66
|
return { [`${path}/*`]: apiBehavior };
|
|
67
67
|
}
|
|
68
68
|
api(path) {
|
|
69
|
-
this.function
|
|
70
|
-
const integration = new aws_apigatewayv2_integrations_1.HttpLambdaIntegration('AppIntegration', this.function);
|
|
71
|
-
return { [`${path}/*`]: integration };
|
|
69
|
+
return (0, lambda_api_1.lambdaApi)(this.function, path);
|
|
72
70
|
}
|
|
73
71
|
}
|
|
74
72
|
exports.DenoApiConstruct = DenoApiConstruct;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Attachable, Grantable } from '@fy-stack/types';
|
|
2
|
+
import type { HttpRouteIntegration } from 'aws-cdk-lib/aws-apigatewayv2';
|
|
3
|
+
import { BehaviorOptions } from 'aws-cdk-lib/aws-cloudfront';
|
|
4
|
+
import { Function } from 'aws-cdk-lib/aws-lambda';
|
|
5
|
+
import { ITopicSubscription, SubscriptionProps } from 'aws-cdk-lib/aws-sns';
|
|
6
|
+
import { Queue } from 'aws-cdk-lib/aws-sqs';
|
|
7
|
+
import { Construct } from 'constructs';
|
|
8
|
+
import { AppConstruct, AppProperties } from './types';
|
|
9
|
+
export declare class ImageAppConstruct extends Construct implements AppConstruct {
|
|
10
|
+
function: Function;
|
|
11
|
+
queue: Queue | undefined;
|
|
12
|
+
constructor(scope: Construct, id: string, props: AppProperties);
|
|
13
|
+
attach(attachable: Record<string, Attachable>): void;
|
|
14
|
+
grant(...grantables: Grantable[]): void;
|
|
15
|
+
subscription(props: SubscriptionProps): ITopicSubscription;
|
|
16
|
+
cloudfront(path: string): Record<string, BehaviorOptions>;
|
|
17
|
+
api(path: string): Record<string, HttpRouteIntegration>;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=image-app-construct.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"image-app-construct.d.ts","sourceRoot":"","sources":["../../src/lib/image-app-construct.ts"],"names":[],"mappings":"AAAA,OAAO,EAAG,UAAU,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEzD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACzE,OAAO,EAEL,eAAe,EAKhB,MAAM,4BAA4B,CAAC;AAGpC,OAAO,EAEL,QAAQ,EAIT,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAK5E,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAKtD,qBAAa,iBACX,SAAQ,SACR,YAAW,YAAY;IAEhB,QAAQ,EAAE,QAAQ,CAAC;IACnB,KAAK,EAAE,KAAK,GAAG,SAAS,CAAC;gBAEpB,KAAK,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa;IA2B9D,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,GAAG,IAAI;IAIpD,KAAK,CAAC,GAAG,UAAU,EAAE,SAAS,EAAE,GAAG,IAAI;IAIvC,YAAY,CAAC,KAAK,EAAE,iBAAiB,GAAG,kBAAkB;IAQ1D,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC;IAqBzD,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAC;CAGxD"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ImageAppConstruct = void 0;
|
|
4
|
+
const aws_cdk_lib_1 = require("aws-cdk-lib");
|
|
5
|
+
const aws_cloudfront_1 = require("aws-cdk-lib/aws-cloudfront");
|
|
6
|
+
const aws_cloudfront_origins_1 = require("aws-cdk-lib/aws-cloudfront-origins");
|
|
7
|
+
const aws_ecr_assets_1 = require("aws-cdk-lib/aws-ecr-assets");
|
|
8
|
+
const aws_lambda_1 = require("aws-cdk-lib/aws-lambda");
|
|
9
|
+
const aws_lambda_event_sources_1 = require("aws-cdk-lib/aws-lambda-event-sources");
|
|
10
|
+
const aws_sns_subscriptions_1 = require("aws-cdk-lib/aws-sns-subscriptions");
|
|
11
|
+
const aws_sqs_1 = require("aws-cdk-lib/aws-sqs");
|
|
12
|
+
const constructs_1 = require("constructs");
|
|
13
|
+
const lambda_attach_1 = require("./utils/lambda-attach");
|
|
14
|
+
const lambda_grant_1 = require("./utils/lambda-grant");
|
|
15
|
+
const lambda_api_1 = require("./utils/lambda-api");
|
|
16
|
+
class ImageAppConstruct extends constructs_1.Construct {
|
|
17
|
+
function;
|
|
18
|
+
queue;
|
|
19
|
+
constructor(scope, id, props) {
|
|
20
|
+
super(scope, id);
|
|
21
|
+
this.function = new aws_lambda_1.Function(this, `AppFunction`, {
|
|
22
|
+
memorySize: 512,
|
|
23
|
+
timeout: aws_cdk_lib_1.Duration.seconds(30),
|
|
24
|
+
code: aws_lambda_1.Code.fromAssetImage(props.output, {
|
|
25
|
+
file: props.buildParams?.dockerFile,
|
|
26
|
+
platform: aws_ecr_assets_1.Platform.LINUX_AMD64,
|
|
27
|
+
}),
|
|
28
|
+
handler: aws_lambda_1.Handler.FROM_IMAGE,
|
|
29
|
+
runtime: aws_lambda_1.Runtime.FROM_IMAGE,
|
|
30
|
+
});
|
|
31
|
+
if (props.queue) {
|
|
32
|
+
this.queue = new aws_sqs_1.Queue(this, 'AppQueue', {
|
|
33
|
+
visibilityTimeout: aws_cdk_lib_1.Duration.seconds(59),
|
|
34
|
+
});
|
|
35
|
+
this.function.addEventSource(new aws_lambda_event_sources_1.SqsEventSource(this.queue, {
|
|
36
|
+
batchSize: props.queue.batchSize,
|
|
37
|
+
}));
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
attach(attachable) {
|
|
41
|
+
return (0, lambda_attach_1.lambdaAttach)(this.function, attachable);
|
|
42
|
+
}
|
|
43
|
+
grant(...grantables) {
|
|
44
|
+
return (0, lambda_grant_1.lambdaGrant)(this.function, grantables);
|
|
45
|
+
}
|
|
46
|
+
subscription(props) {
|
|
47
|
+
if (this.queue) {
|
|
48
|
+
return new aws_sns_subscriptions_1.SqsSubscription(this.queue, props);
|
|
49
|
+
}
|
|
50
|
+
return new aws_sns_subscriptions_1.LambdaSubscription(this.function, props);
|
|
51
|
+
}
|
|
52
|
+
cloudfront(path) {
|
|
53
|
+
this.function.addEnvironment('BASE_PATH', path);
|
|
54
|
+
const apiUrl = this.function.addFunctionUrl({
|
|
55
|
+
authType: aws_lambda_1.FunctionUrlAuthType.NONE,
|
|
56
|
+
});
|
|
57
|
+
const apiBehavior = {
|
|
58
|
+
origin: new aws_cloudfront_origins_1.FunctionUrlOrigin(apiUrl),
|
|
59
|
+
cachePolicy: aws_cloudfront_1.CachePolicy.CACHING_DISABLED,
|
|
60
|
+
allowedMethods: aws_cloudfront_1.AllowedMethods.ALLOW_ALL,
|
|
61
|
+
compress: true,
|
|
62
|
+
viewerProtocolPolicy: aws_cloudfront_1.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
|
|
63
|
+
originRequestPolicy: aws_cloudfront_1.OriginRequestPolicy.ALL_VIEWER_EXCEPT_HOST_HEADER,
|
|
64
|
+
responseHeadersPolicy: aws_cloudfront_1.ResponseHeadersPolicy.CORS_ALLOW_ALL_ORIGINS_WITH_PREFLIGHT_AND_SECURITY_HEADERS,
|
|
65
|
+
};
|
|
66
|
+
return { [`${path}/*`]: apiBehavior };
|
|
67
|
+
}
|
|
68
|
+
api(path) {
|
|
69
|
+
return (0, lambda_api_1.lambdaApi)(this.function, path);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
exports.ImageAppConstruct = ImageAppConstruct;
|
|
@@ -27,7 +27,7 @@ export declare class NestConstruct extends Construct implements AppConstruct {
|
|
|
27
27
|
};
|
|
28
28
|
};
|
|
29
29
|
api(path: string): {
|
|
30
|
-
[x: string]: cdk.aws_apigatewayv2_integrations.
|
|
30
|
+
[x: string]: cdk.aws_apigatewayv2_integrations.HttpUrlIntegration;
|
|
31
31
|
};
|
|
32
32
|
static clean(output: string, name: string, command: string): {
|
|
33
33
|
serverOutput: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nest-construct.d.ts","sourceRoot":"","sources":["../../src/lib/nest-construct.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,KAAK,GAAG,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"nest-construct.d.ts","sourceRoot":"","sources":["../../src/lib/nest-construct.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,KAAK,GAAG,MAAM,aAAa,CAAC;AAGnC,OAAO,KAAK,MAAM,MAAM,wBAAwB,CAAC;AAEjD,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAE5E,OAAO,KAAK,GAAG,MAAM,qBAAqB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAKtD,UAAU,KAAM,SAAQ,aAAa;IACnC,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,qBAAa,aAAc,SAAQ,SAAU,YAAW,YAAY;IAC3D,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC;IAC1B,KAAK,EAAE,GAAG,CAAC,KAAK,GAAG,SAAS,CAAC;gBAExB,KAAK,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK;IAqDtD,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC;IAI7C,KAAK,CAAC,GAAG,MAAM,EAAE,SAAS,EAAE;IAI5B,YAAY,CAAC,KAAK,EAAE,iBAAiB,GAAG,kBAAkB;IAO1D,UAAU,CAAC,IAAI,EAAE,MAAM;;;;;;;;;;;IAqBvB,GAAG,CAAC,IAAI,EAAE,MAAM;;;IAIhB,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;;;CAuB3D"}
|
|
@@ -5,7 +5,6 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
const child_process = tslib_1.__importStar(require("node:child_process"));
|
|
6
6
|
const fs = tslib_1.__importStar(require("node:fs"));
|
|
7
7
|
const cdk = tslib_1.__importStar(require("aws-cdk-lib"));
|
|
8
|
-
const aws_apigatewayv2_integrations_1 = require("aws-cdk-lib/aws-apigatewayv2-integrations");
|
|
9
8
|
const cloudfront = tslib_1.__importStar(require("aws-cdk-lib/aws-cloudfront"));
|
|
10
9
|
const cloudfrontOrigin = tslib_1.__importStar(require("aws-cdk-lib/aws-cloudfront-origins"));
|
|
11
10
|
const lambda = tslib_1.__importStar(require("aws-cdk-lib/aws-lambda"));
|
|
@@ -15,6 +14,7 @@ const sqs = tslib_1.__importStar(require("aws-cdk-lib/aws-sqs"));
|
|
|
15
14
|
const constructs_1 = require("constructs");
|
|
16
15
|
const lambda_attach_1 = require("./utils/lambda-attach");
|
|
17
16
|
const lambda_grant_1 = require("./utils/lambda-grant");
|
|
17
|
+
const lambda_api_1 = require("./utils/lambda-api");
|
|
18
18
|
class NestConstruct extends constructs_1.Construct {
|
|
19
19
|
function;
|
|
20
20
|
queue;
|
|
@@ -81,9 +81,7 @@ class NestConstruct extends constructs_1.Construct {
|
|
|
81
81
|
return { [`${path}/*`]: apiBehavior };
|
|
82
82
|
}
|
|
83
83
|
api(path) {
|
|
84
|
-
this.function
|
|
85
|
-
const integration = new aws_apigatewayv2_integrations_1.HttpLambdaIntegration('AppIntegration', this.function);
|
|
86
|
-
return { [`${path}/*`]: integration };
|
|
84
|
+
return (0, lambda_api_1.lambdaApi)(this.function, path);
|
|
87
85
|
}
|
|
88
86
|
static clean(output, name, command) {
|
|
89
87
|
const destination = `./dist/${name}`;
|
|
@@ -18,10 +18,5 @@ export declare class NextAppRouterConstruct extends Construct implements AppCons
|
|
|
18
18
|
attach(attachable: Record<string, Attachable>): void;
|
|
19
19
|
grant(...grants: Grantable[]): void;
|
|
20
20
|
subscription(): ITopicSubscription;
|
|
21
|
-
static clean(output: string, name: string, command: string): {
|
|
22
|
-
serverOutput: string;
|
|
23
|
-
staticOutput: string;
|
|
24
|
-
staticPath: string;
|
|
25
|
-
};
|
|
26
21
|
}
|
|
27
22
|
//# sourceMappingURL=next-app-router-construct.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"next-app-router-construct.d.ts","sourceRoot":"","sources":["../../src/lib/next-app-router-construct.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"next-app-router-construct.d.ts","sourceRoot":"","sources":["../../src/lib/next-app-router-construct.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,KAAK,GAAG,MAAM,aAAa,CAAC;AACnC,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AAGzE,OAAO,KAAK,MAAM,MAAM,wBAAwB,CAAC;AAIjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,GAAG,MAAM,qBAAqB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAMtD,qBAAa,sBAAuB,SAAQ,SAAU,YAAW,YAAY;IACpE,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC;IAC1B,KAAK,EAAE,GAAG,CAAC,KAAK,GAAG,SAAS,CAAC;IAEpC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAY;gBAEvB,KAAK,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa;IAiE9D,UAAU,CAAC,IAAI,EAAE,MAAM;;;IAwCvB,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAC;IAIvD,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC;IAI7C,KAAK,CAAC,GAAG,MAAM,EAAE,SAAS,EAAE;IAI5B,YAAY,IAAI,kBAAkB;CAGnC"}
|
|
@@ -2,16 +2,18 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.NextAppRouterConstruct = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const fs = tslib_1.__importStar(require("node:fs"));
|
|
6
5
|
const cdk = tslib_1.__importStar(require("aws-cdk-lib"));
|
|
7
6
|
const cloudfront = tslib_1.__importStar(require("aws-cdk-lib/aws-cloudfront"));
|
|
8
7
|
const cloudfrontOrigin = tslib_1.__importStar(require("aws-cdk-lib/aws-cloudfront-origins"));
|
|
9
8
|
const lambda = tslib_1.__importStar(require("aws-cdk-lib/aws-lambda"));
|
|
9
|
+
const aws_lambda_1 = require("aws-cdk-lib/aws-lambda");
|
|
10
10
|
const s3 = tslib_1.__importStar(require("aws-cdk-lib/aws-s3"));
|
|
11
11
|
const s3Deploy = tslib_1.__importStar(require("aws-cdk-lib/aws-s3-deployment"));
|
|
12
12
|
const constructs_1 = require("constructs");
|
|
13
13
|
const lambda_attach_1 = require("./utils/lambda-attach");
|
|
14
14
|
const lambda_grant_1 = require("./utils/lambda-grant");
|
|
15
|
+
const path = tslib_1.__importStar(require("node:path"));
|
|
16
|
+
const fs = tslib_1.__importStar(require("node:fs"));
|
|
15
17
|
class NextAppRouterConstruct extends constructs_1.Construct {
|
|
16
18
|
function;
|
|
17
19
|
queue;
|
|
@@ -19,9 +21,6 @@ class NextAppRouterConstruct extends constructs_1.Construct {
|
|
|
19
21
|
constructor(scope, id, props) {
|
|
20
22
|
super(scope, id);
|
|
21
23
|
const region = cdk.Stack.of(this).region;
|
|
22
|
-
const { serverOutput, staticOutput, staticPath } = props.buildPaths;
|
|
23
|
-
if (!serverOutput || !staticOutput)
|
|
24
|
-
throw new Error('assets not found');
|
|
25
24
|
this.static = new s3.Bucket(this, `StaticBucket`, {
|
|
26
25
|
removalPolicy: cdk.RemovalPolicy.DESTROY,
|
|
27
26
|
autoDeleteObjects: true,
|
|
@@ -39,10 +38,15 @@ class NextAppRouterConstruct extends constructs_1.Construct {
|
|
|
39
38
|
});
|
|
40
39
|
new s3Deploy.BucketDeployment(this, `StaticDeployment`, {
|
|
41
40
|
destinationBucket: this.static,
|
|
42
|
-
sources: [s3Deploy.Source.asset(
|
|
43
|
-
destinationKeyPrefix:
|
|
41
|
+
sources: [s3Deploy.Source.asset(path.join(props.output, "/.next/static")),],
|
|
42
|
+
destinationKeyPrefix: "_next/static",
|
|
43
|
+
retainOnDelete: false,
|
|
44
|
+
});
|
|
45
|
+
new s3Deploy.BucketDeployment(this, `PublicDeployment`, {
|
|
46
|
+
destinationBucket: this.static,
|
|
47
|
+
sources: [s3Deploy.Source.asset(path.join(props.output, "/public"))],
|
|
48
|
+
destinationKeyPrefix: "",
|
|
44
49
|
retainOnDelete: false,
|
|
45
|
-
prune: true,
|
|
46
50
|
});
|
|
47
51
|
const webAdapterLayer = lambda.LayerVersion.fromLayerVersionArn(this, 'WebAdapterLayer', `arn:aws:lambda:${region}:753240598075:layer:LambdaAdapterLayerX86:16`);
|
|
48
52
|
const environment = {
|
|
@@ -51,12 +55,17 @@ class NextAppRouterConstruct extends constructs_1.Construct {
|
|
|
51
55
|
AWS_NODEJS_CONNECTION_REUSE_ENABLED: '1',
|
|
52
56
|
};
|
|
53
57
|
Object.assign(environment, props.env);
|
|
58
|
+
const serverOutput = path.join(props.output, "/.next/standalone");
|
|
59
|
+
if (!props.buildParams?.command)
|
|
60
|
+
throw new Error("command is requires in buildParams");
|
|
61
|
+
fs.writeFileSync(path.join(serverOutput, 'run.sh'), props.buildParams.command);
|
|
54
62
|
this.function = new lambda.Function(this, `AppFunction`, {
|
|
55
63
|
runtime: lambda.Runtime.NODEJS_20_X,
|
|
56
64
|
memorySize: 512,
|
|
57
|
-
handler:
|
|
65
|
+
handler: "run.sh",
|
|
58
66
|
timeout: cdk.Duration.seconds(60),
|
|
59
67
|
code: lambda.Code.fromAsset(serverOutput),
|
|
68
|
+
loggingFormat: aws_lambda_1.LoggingFormat.JSON,
|
|
60
69
|
layers: [webAdapterLayer],
|
|
61
70
|
environment,
|
|
62
71
|
});
|
|
@@ -104,30 +113,5 @@ class NextAppRouterConstruct extends constructs_1.Construct {
|
|
|
104
113
|
subscription() {
|
|
105
114
|
throw new Error(`subscription not supported for ${this}`);
|
|
106
115
|
}
|
|
107
|
-
static clean(output, name, command) {
|
|
108
|
-
const destination = `./dist/${name}`;
|
|
109
|
-
/* Delete previous cleaned files */
|
|
110
|
-
fs.rmSync(destination, { recursive: true, force: true });
|
|
111
|
-
/* Create server and static folders for deployment */
|
|
112
|
-
fs.mkdirSync(`${destination}/server`, { recursive: true });
|
|
113
|
-
fs.mkdirSync(`${destination}/static/_next`, { recursive: true });
|
|
114
|
-
fs.cpSync(`${output}/.next/standalone/`, `${destination}/server`, {
|
|
115
|
-
recursive: true,
|
|
116
|
-
});
|
|
117
|
-
/* Copy public files to static folder */
|
|
118
|
-
fs.cpSync(`${output}/public`, `${destination}/static`, {
|
|
119
|
-
recursive: true,
|
|
120
|
-
});
|
|
121
|
-
/* Copy static files to next static folder */
|
|
122
|
-
fs.cpSync(`${output}/.next/static`, `${destination}/static/_next/static`, {
|
|
123
|
-
recursive: true,
|
|
124
|
-
});
|
|
125
|
-
fs.writeFileSync(`${destination}/server/run.sh`, command);
|
|
126
|
-
return {
|
|
127
|
-
serverOutput: `${destination}/server`,
|
|
128
|
-
staticOutput: `${destination}/static`,
|
|
129
|
-
staticPath: '',
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
116
|
}
|
|
133
117
|
exports.NextAppRouterConstruct = NextAppRouterConstruct;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Attachable, Grantable } from '@fy-stack/types';
|
|
2
|
+
import * as cdk from 'aws-cdk-lib';
|
|
3
|
+
import * as lambda from 'aws-cdk-lib/aws-lambda';
|
|
4
|
+
import { ITopicSubscription, SubscriptionProps } from 'aws-cdk-lib/aws-sns';
|
|
5
|
+
import * as sqs from 'aws-cdk-lib/aws-sqs';
|
|
6
|
+
import { Construct } from 'constructs';
|
|
7
|
+
import { AppConstruct, AppProperties } from './types';
|
|
8
|
+
export declare class NodeApiConstruct extends Construct implements AppConstruct {
|
|
9
|
+
function: lambda.Function;
|
|
10
|
+
queue: sqs.Queue | undefined;
|
|
11
|
+
constructor(scope: Construct, id: string, props: AppProperties);
|
|
12
|
+
attach(attachable: Record<string, Attachable>): void;
|
|
13
|
+
grant(...grants: Grantable[]): void;
|
|
14
|
+
subscription(props: SubscriptionProps): ITopicSubscription;
|
|
15
|
+
cloudfront(path: string): {
|
|
16
|
+
[x: string]: {
|
|
17
|
+
origin: cdk.aws_cloudfront_origins.FunctionUrlOrigin;
|
|
18
|
+
cachePolicy: cdk.aws_cloudfront.ICachePolicy;
|
|
19
|
+
allowedMethods: cdk.aws_cloudfront.AllowedMethods;
|
|
20
|
+
compress: boolean;
|
|
21
|
+
viewerProtocolPolicy: cdk.aws_cloudfront.ViewerProtocolPolicy;
|
|
22
|
+
originRequestPolicy: cdk.aws_cloudfront.IOriginRequestPolicy;
|
|
23
|
+
responseHeadersPolicy: cdk.aws_cloudfront.IResponseHeadersPolicy;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
api(path: string): {
|
|
27
|
+
[x: string]: cdk.aws_apigatewayv2_integrations.HttpUrlIntegration;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=node-api-construct.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-api-construct.d.ts","sourceRoot":"","sources":["../../src/lib/node-api-construct.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,KAAK,GAAG,MAAM,aAAa,CAAC;AAGnC,OAAO,KAAK,MAAM,MAAM,wBAAwB,CAAC;AAEjD,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAC5E,OAAO,KAAK,GAAG,MAAM,qBAAqB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAOtD,qBAAa,gBAAiB,SAAQ,SAAU,YAAW,YAAY;IAC9D,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC;IAC1B,KAAK,EAAE,GAAG,CAAC,KAAK,GAAG,SAAS,CAAC;gBAExB,KAAK,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa;IAgD9D,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC;IAI7C,KAAK,CAAC,GAAG,MAAM,EAAE,SAAS,EAAE;IAI5B,YAAY,CAAC,KAAK,EAAE,iBAAiB,GAAG,kBAAkB;IAI1D,UAAU,CAAC,IAAI,EAAE,MAAM;;;;;;;;;;;IAqBvB,GAAG,CAAC,IAAI,EAAE,MAAM;;;CAGjB"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NodeApiConstruct = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const cdk = tslib_1.__importStar(require("aws-cdk-lib"));
|
|
6
|
+
const cloudfront = tslib_1.__importStar(require("aws-cdk-lib/aws-cloudfront"));
|
|
7
|
+
const cloudfrontOrigin = tslib_1.__importStar(require("aws-cdk-lib/aws-cloudfront-origins"));
|
|
8
|
+
const lambda = tslib_1.__importStar(require("aws-cdk-lib/aws-lambda"));
|
|
9
|
+
const lambdaEventSource = tslib_1.__importStar(require("aws-cdk-lib/aws-lambda-event-sources"));
|
|
10
|
+
const sqs = tslib_1.__importStar(require("aws-cdk-lib/aws-sqs"));
|
|
11
|
+
const constructs_1 = require("constructs");
|
|
12
|
+
const lambda_attach_1 = require("./utils/lambda-attach");
|
|
13
|
+
const lambda_grant_1 = require("./utils/lambda-grant");
|
|
14
|
+
const lambda_api_1 = require("./utils/lambda-api");
|
|
15
|
+
const node_path_1 = tslib_1.__importDefault(require("node:path"));
|
|
16
|
+
const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
|
|
17
|
+
class NodeApiConstruct extends constructs_1.Construct {
|
|
18
|
+
function;
|
|
19
|
+
queue;
|
|
20
|
+
constructor(scope, id, props) {
|
|
21
|
+
super(scope, id);
|
|
22
|
+
const region = cdk.Stack.of(this).region;
|
|
23
|
+
const environment = {};
|
|
24
|
+
Object.assign(environment, props.env);
|
|
25
|
+
const layers = [
|
|
26
|
+
lambda.LayerVersion.fromLayerVersionArn(this, 'WebAdapterLayer', `arn:aws:lambda:${region}:753240598075:layer:LambdaAdapterLayerX86:16`)
|
|
27
|
+
];
|
|
28
|
+
Object.assign(environment, {
|
|
29
|
+
AWS_LAMBDA_EXEC_WRAPPER: '/opt/bootstrap',
|
|
30
|
+
AWS_NODEJS_CONNECTION_REUSE_ENABLED: '1',
|
|
31
|
+
PORT: '8080',
|
|
32
|
+
});
|
|
33
|
+
if (!props.buildParams?.command)
|
|
34
|
+
throw new Error("command is requires in buildParams");
|
|
35
|
+
node_fs_1.default.writeFileSync(node_path_1.default.join(props.output, 'run.sh'), props.buildParams.command);
|
|
36
|
+
this.function = new lambda.Function(this, `AppFunction`, {
|
|
37
|
+
runtime: lambda.Runtime.NODEJS_20_X,
|
|
38
|
+
memorySize: 512,
|
|
39
|
+
handler: 'run.sh',
|
|
40
|
+
layers,
|
|
41
|
+
timeout: cdk.Duration.seconds(30),
|
|
42
|
+
code: lambda.Code.fromAsset(props.output),
|
|
43
|
+
environment,
|
|
44
|
+
});
|
|
45
|
+
if (props.queue) {
|
|
46
|
+
this.queue = new sqs.Queue(this, 'AppQueue', {
|
|
47
|
+
visibilityTimeout: cdk.Duration.seconds(59),
|
|
48
|
+
});
|
|
49
|
+
this.function.addEventSource(new lambdaEventSource.SqsEventSource(this.queue, {
|
|
50
|
+
batchSize: props.queue.batchSize,
|
|
51
|
+
}));
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
attach(attachable) {
|
|
55
|
+
return (0, lambda_attach_1.lambdaAttach)(this.function, attachable);
|
|
56
|
+
}
|
|
57
|
+
grant(...grants) {
|
|
58
|
+
return (0, lambda_grant_1.lambdaGrant)(this.function, grants);
|
|
59
|
+
}
|
|
60
|
+
subscription(props) {
|
|
61
|
+
throw new Error(`subscription is not supported for ${this}`);
|
|
62
|
+
}
|
|
63
|
+
cloudfront(path) {
|
|
64
|
+
const apiUrl = this.function.addFunctionUrl({
|
|
65
|
+
authType: lambda.FunctionUrlAuthType.NONE,
|
|
66
|
+
});
|
|
67
|
+
const apiBehavior = {
|
|
68
|
+
origin: new cloudfrontOrigin.FunctionUrlOrigin(apiUrl),
|
|
69
|
+
cachePolicy: cloudfront.CachePolicy.CACHING_DISABLED,
|
|
70
|
+
allowedMethods: cloudfront.AllowedMethods.ALLOW_ALL,
|
|
71
|
+
compress: true,
|
|
72
|
+
viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
|
|
73
|
+
originRequestPolicy: cloudfront.OriginRequestPolicy.ALL_VIEWER_EXCEPT_HOST_HEADER,
|
|
74
|
+
responseHeadersPolicy: cloudfront.ResponseHeadersPolicy
|
|
75
|
+
.CORS_ALLOW_ALL_ORIGINS_WITH_PREFLIGHT_AND_SECURITY_HEADERS,
|
|
76
|
+
};
|
|
77
|
+
return { [`${path}/*`]: apiBehavior };
|
|
78
|
+
}
|
|
79
|
+
api(path) {
|
|
80
|
+
return (0, lambda_api_1.lambdaApi)(this.function, path);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
exports.NodeApiConstruct = NodeApiConstruct;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Attachable, Grantable } from '@fy-stack/types';
|
|
2
|
+
import * as lambda from 'aws-cdk-lib/aws-lambda';
|
|
3
|
+
import { ITopicSubscription, SubscriptionProps } from 'aws-cdk-lib/aws-sns';
|
|
4
|
+
import * as sqs from 'aws-cdk-lib/aws-sqs';
|
|
5
|
+
import { Construct } from 'constructs';
|
|
6
|
+
import { AppConstruct, AppProperties } from './types';
|
|
7
|
+
import { BehaviorOptions } from 'aws-cdk-lib/aws-cloudfront';
|
|
8
|
+
import type { HttpRouteIntegration } from 'aws-cdk-lib/aws-apigatewayv2';
|
|
9
|
+
export declare class NodeAppConstruct extends Construct implements AppConstruct {
|
|
10
|
+
function: lambda.Function;
|
|
11
|
+
queue: sqs.Queue | undefined;
|
|
12
|
+
constructor(scope: Construct, id: string, props: AppProperties);
|
|
13
|
+
attach(attachable: Record<string, Attachable>): void;
|
|
14
|
+
grant(...grants: Grantable[]): void;
|
|
15
|
+
subscription(props: SubscriptionProps): ITopicSubscription;
|
|
16
|
+
cloudfront(path: string): Record<string, BehaviorOptions>;
|
|
17
|
+
api(path: string): Record<string, HttpRouteIntegration>;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=node-app-construct.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-app-construct.d.ts","sourceRoot":"","sources":["../../src/lib/node-app-construct.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAExD,OAAO,KAAK,MAAM,MAAM,wBAAwB,CAAC;AAGjD,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAE5E,OAAO,KAAK,GAAG,MAAM,qBAAqB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAGtD,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AAEzE,qBAAa,gBAAiB,SAAQ,SAAU,YAAW,YAAY;IAC9D,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC;IAC1B,KAAK,EAAE,GAAG,CAAC,KAAK,GAAG,SAAS,CAAC;gBAExB,KAAK,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa;IA8B9D,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC;IAI7C,KAAK,CAAC,GAAG,MAAM,EAAE,SAAS,EAAE;IAI5B,YAAY,CAAC,KAAK,EAAE,iBAAiB,GAAG,kBAAkB;IAO1D,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC;IAIzD,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAC;CAGxD"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NodeAppConstruct = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const cdk = tslib_1.__importStar(require("aws-cdk-lib"));
|
|
6
|
+
const lambda = tslib_1.__importStar(require("aws-cdk-lib/aws-lambda"));
|
|
7
|
+
const aws_lambda_1 = require("aws-cdk-lib/aws-lambda");
|
|
8
|
+
const lambdaEventSource = tslib_1.__importStar(require("aws-cdk-lib/aws-lambda-event-sources"));
|
|
9
|
+
const snsSubscriptions = tslib_1.__importStar(require("aws-cdk-lib/aws-sns-subscriptions"));
|
|
10
|
+
const sqs = tslib_1.__importStar(require("aws-cdk-lib/aws-sqs"));
|
|
11
|
+
const constructs_1 = require("constructs");
|
|
12
|
+
const lambda_attach_1 = require("./utils/lambda-attach");
|
|
13
|
+
const lambda_grant_1 = require("./utils/lambda-grant");
|
|
14
|
+
class NodeAppConstruct extends constructs_1.Construct {
|
|
15
|
+
function;
|
|
16
|
+
queue;
|
|
17
|
+
constructor(scope, id, props) {
|
|
18
|
+
super(scope, id);
|
|
19
|
+
const environment = {};
|
|
20
|
+
Object.assign(environment, props.env);
|
|
21
|
+
this.function = new lambda.Function(this, `AppFunction`, {
|
|
22
|
+
runtime: lambda.Runtime.NODEJS_20_X,
|
|
23
|
+
memorySize: 512,
|
|
24
|
+
handler: props.buildParams?.handler ?? "index.handler",
|
|
25
|
+
timeout: cdk.Duration.seconds(30),
|
|
26
|
+
code: lambda.Code.fromAsset(props.output),
|
|
27
|
+
loggingFormat: aws_lambda_1.LoggingFormat.JSON,
|
|
28
|
+
environment,
|
|
29
|
+
});
|
|
30
|
+
if (props.queue) {
|
|
31
|
+
this.queue = new sqs.Queue(this, 'AppQueue', {
|
|
32
|
+
visibilityTimeout: cdk.Duration.seconds(59),
|
|
33
|
+
});
|
|
34
|
+
this.function.addEventSource(new lambdaEventSource.SqsEventSource(this.queue, {
|
|
35
|
+
batchSize: props.queue.batchSize,
|
|
36
|
+
}));
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
attach(attachable) {
|
|
40
|
+
return (0, lambda_attach_1.lambdaAttach)(this.function, attachable);
|
|
41
|
+
}
|
|
42
|
+
grant(...grants) {
|
|
43
|
+
return (0, lambda_grant_1.lambdaGrant)(this.function, grants);
|
|
44
|
+
}
|
|
45
|
+
subscription(props) {
|
|
46
|
+
if (this.queue)
|
|
47
|
+
return new snsSubscriptions.SqsSubscription(this.queue, props);
|
|
48
|
+
return new snsSubscriptions.LambdaSubscription(this.function, props);
|
|
49
|
+
}
|
|
50
|
+
cloudfront(path) {
|
|
51
|
+
throw new Error(`cloudfront not supported for ${this}`);
|
|
52
|
+
}
|
|
53
|
+
api(path) {
|
|
54
|
+
throw new Error(`api not supported for ${this}`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.NodeAppConstruct = NodeAppConstruct;
|
package/dist/lib/types.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export type AppProperties = {
|
|
|
6
6
|
batchSize?: number;
|
|
7
7
|
};
|
|
8
8
|
env?: Record<string, string>;
|
|
9
|
-
|
|
9
|
+
buildParams?: Record<string, string>;
|
|
10
10
|
output: string;
|
|
11
11
|
};
|
|
12
12
|
export interface AppConstruct extends Attach, Grant, CDNResource, Event, ApiResource {
|
package/dist/lib/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/lib/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACjF,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAE5C,MAAM,MAAM,aAAa,GAAG;IAC1B,KAAK,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAC/B,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/lib/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACjF,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAE5C,MAAM,MAAM,aAAa,GAAG;IAC1B,KAAK,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAC/B,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACrC,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,WAAW,YAAa,SAAQ,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,WAAW;IAClF,QAAQ,EAAE,QAAQ,CAAC;IACnB,KAAK,CAAC,EAAE,KAAK,CAAA;CACd"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Function } from 'aws-cdk-lib/aws-lambda';
|
|
2
|
+
import { HttpUrlIntegration } from 'aws-cdk-lib/aws-apigatewayv2-integrations';
|
|
3
|
+
export declare function lambdaApi(func: Function, path: string): {
|
|
4
|
+
[x: string]: HttpUrlIntegration;
|
|
5
|
+
};
|
|
6
|
+
//# sourceMappingURL=lambda-api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lambda-api.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/lambda-api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAElD,OAAO,EAAG,kBAAkB,EAAE,MAAM,2CAA2C,CAAC;AAEhF,wBAAgB,SAAS,CAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM;;EAarD"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.lambdaApi = lambdaApi;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const lambda = tslib_1.__importStar(require("aws-cdk-lib/aws-lambda"));
|
|
6
|
+
const aws_apigatewayv2_integrations_1 = require("aws-cdk-lib/aws-apigatewayv2-integrations");
|
|
7
|
+
function lambdaApi(func, path) {
|
|
8
|
+
const apiUrl = func.addFunctionUrl({
|
|
9
|
+
authType: lambda.FunctionUrlAuthType.NONE,
|
|
10
|
+
});
|
|
11
|
+
func.addEnvironment('BASE_PATH', path);
|
|
12
|
+
const integration = new aws_apigatewayv2_integrations_1.HttpUrlIntegration('AppIntegration', apiUrl.url);
|
|
13
|
+
return { [`${path}/*`]: integration };
|
|
14
|
+
}
|
package/package.json
CHANGED