@fy-stack/app-construct 0.0.141 → 0.0.143
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 +8 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -15
- package/dist/lib/ecs/apps/image-app-construct.d.ts +17 -0
- package/dist/lib/ecs/apps/image-app-construct.d.ts.map +1 -0
- package/dist/lib/ecs/apps/image-app-construct.js +55 -0
- package/dist/lib/ecs/apps/next-app-router-construct.d.ts +22 -0
- package/dist/lib/ecs/apps/next-app-router-construct.d.ts.map +1 -0
- package/dist/lib/ecs/apps/next-app-router-construct.js +52 -0
- package/dist/lib/ecs/apps/task-construct.d.ts +16 -0
- package/dist/lib/ecs/apps/task-construct.d.ts.map +1 -0
- package/dist/lib/ecs/apps/task-construct.js +101 -0
- package/dist/lib/ecs/ecs-construct.d.ts +10 -0
- package/dist/lib/ecs/ecs-construct.d.ts.map +1 -0
- package/dist/lib/ecs/ecs-construct.js +42 -0
- package/dist/lib/ecs/ecs-server-construct.d.ts +28 -0
- package/dist/lib/ecs/ecs-server-construct.d.ts.map +1 -0
- package/dist/lib/ecs/ecs-server-construct.js +161 -0
- package/dist/lib/ecs/shared/taskDefinitionImage.d.ts +13 -0
- package/dist/lib/ecs/shared/taskDefinitionImage.d.ts.map +1 -0
- package/dist/lib/ecs/shared/taskDefinitionImage.js +27 -0
- package/dist/lib/ecs/shared/util/ecs-api-gateway.d.ts +2 -0
- package/dist/lib/ecs/shared/util/ecs-api-gateway.d.ts.map +1 -0
- package/dist/lib/ecs/shared/util/ecs-api-gateway.js +5 -0
- package/dist/lib/ecs/types.d.ts +89 -0
- package/dist/lib/ecs/types.d.ts.map +1 -0
- package/dist/lib/ecs/types.js +2 -0
- package/dist/lib/lambda/apps/image-app-construct.d.ts +68 -0
- package/dist/lib/lambda/apps/image-app-construct.d.ts.map +1 -0
- package/dist/lib/lambda/apps/image-app-construct.js +92 -0
- package/dist/lib/lambda/apps/next-app-router-construct.d.ts +33 -0
- package/dist/lib/lambda/apps/next-app-router-construct.d.ts.map +1 -0
- package/dist/lib/lambda/apps/next-app-router-construct.js +77 -0
- package/dist/lib/lambda/apps/node-api-construct.d.ts +43 -0
- package/dist/lib/lambda/apps/node-api-construct.d.ts.map +1 -0
- package/dist/lib/lambda/apps/node-api-construct.js +91 -0
- package/dist/lib/lambda/apps/node-app-construct.d.ts +32 -0
- package/dist/lib/lambda/apps/node-app-construct.d.ts.map +1 -0
- package/dist/lib/lambda/apps/node-app-construct.js +73 -0
- package/dist/lib/lambda/lambda-construct.d.ts +7 -0
- package/dist/lib/lambda/lambda-construct.d.ts.map +1 -0
- package/dist/lib/lambda/lambda-construct.js +34 -0
- package/dist/lib/lambda/types.d.ts +32 -0
- package/dist/lib/lambda/types.d.ts.map +1 -0
- package/dist/lib/lambda/types.js +2 -0
- package/dist/lib/lambda/utils/getDefaultLambda.d.ts +8 -0
- package/dist/lib/lambda/utils/getDefaultLambda.d.ts.map +1 -0
- package/dist/lib/lambda/utils/getDefaultLambda.js +11 -0
- package/dist/lib/lambda/utils/lambda-api.d.ts +6 -0
- package/dist/lib/lambda/utils/lambda-api.d.ts.map +1 -0
- package/dist/lib/lambda/utils/lambda-api.js +17 -0
- package/dist/lib/lambda/utils/lambda-attach.d.ts +4 -0
- package/dist/lib/lambda/utils/lambda-attach.d.ts.map +1 -0
- package/dist/lib/lambda/utils/lambda-attach.js +11 -0
- package/dist/lib/lambda/utils/lambda-grant.d.ts +4 -0
- package/dist/lib/lambda/utils/lambda-grant.d.ts.map +1 -0
- package/dist/lib/lambda/utils/lambda-grant.js +8 -0
- package/dist/lib/next-app-router-construct.d.ts.map +1 -1
- package/dist/lib/next-app-router-construct.js +3 -2
- package/dist/lib/shared/next-app-router.d.ts +12 -0
- package/dist/lib/shared/next-app-router.d.ts.map +1 -0
- package/dist/lib/shared/next-app-router.js +87 -0
- package/dist/lib/shared/util/params-from-attachable.d.ts +5 -0
- package/dist/lib/shared/util/params-from-attachable.d.ts.map +1 -0
- package/dist/lib/shared/util/params-from-attachable.js +11 -0
- package/dist/lib/shared/util/types.d.ts +25 -0
- package/dist/lib/shared/util/types.d.ts.map +1 -0
- package/dist/lib/shared/util/types.js +20 -0
- package/dist/lib/static/apps/next-pages-export-construct.d.ts +16 -0
- package/dist/lib/static/apps/next-pages-export-construct.d.ts.map +1 -0
- package/dist/lib/static/apps/next-pages-export-construct.js +69 -0
- package/dist/lib/static/apps/static-website-construct.d.ts +16 -0
- package/dist/lib/static/apps/static-website-construct.d.ts.map +1 -0
- package/dist/lib/static/apps/static-website-construct.js +62 -0
- package/dist/lib/static/next-pages-export-construct.d.ts +21 -0
- package/dist/lib/static/next-pages-export-construct.d.ts.map +1 -0
- package/dist/lib/static/next-pages-export-construct.js +78 -0
- package/dist/lib/static/static-construct.d.ts +7 -0
- package/dist/lib/static/static-construct.d.ts.map +1 -0
- package/dist/lib/static/static-construct.js +28 -0
- package/dist/lib/static/static-website-construct.d.ts +21 -0
- package/dist/lib/static/static-website-construct.d.ts.map +1 -0
- package/dist/lib/static/static-website-construct.js +71 -0
- package/dist/lib/static/types.d.ts +16 -0
- package/dist/lib/static/types.d.ts.map +1 -0
- package/dist/lib/static/types.js +2 -0
- package/dist/lib/types.d.ts +9 -0
- package/dist/lib/types.d.ts.map +1 -1
- package/dist/lib/util/params-from-attachable.d.ts +5 -0
- package/dist/lib/util/params-from-attachable.d.ts.map +1 -0
- package/dist/lib/util/params-from-attachable.js +11 -0
- package/dist/lib/util/strip-trailing-slash.d.ts +2 -0
- package/dist/lib/util/strip-trailing-slash.d.ts.map +1 -0
- package/dist/lib/util/strip-trailing-slash.js +6 -0
- package/package.json +3 -3
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import type { ApiResource, Attach, CDNResource } from '@fy-stack/types';
|
|
2
|
+
import { AppType } from '@fy-stack/types';
|
|
3
|
+
import type { LoadBalancerV2Origin } from 'aws-cdk-lib/aws-cloudfront-origins';
|
|
4
|
+
import type { IVpc } from 'aws-cdk-lib/aws-ec2';
|
|
5
|
+
import type { AssetImageProps, Cluster, ContainerDefinitionOptions, FargateServiceProps, FargateTaskDefinitionProps, TaskDefinition } from 'aws-cdk-lib/aws-ecs';
|
|
6
|
+
import type { ApplicationLoadBalancerProps } from 'aws-cdk-lib/aws-elasticloadbalancingv2';
|
|
7
|
+
import type { RetentionDays } from 'aws-cdk-lib/aws-logs';
|
|
8
|
+
export type EcsConstructProps = {
|
|
9
|
+
environmentPath: string;
|
|
10
|
+
environment: string;
|
|
11
|
+
vpc: IVpc;
|
|
12
|
+
server?: Omit<FargateServiceProps, 'cluster' | 'taskDefinition' | 'assignPublicIp' | 'vpcSubnets'> & {
|
|
13
|
+
assignPublicIp?: boolean;
|
|
14
|
+
definition?: FargateTaskDefinitionProps;
|
|
15
|
+
apps: Record<string, ServerApp>;
|
|
16
|
+
/**
|
|
17
|
+
* Load balancer config details,
|
|
18
|
+
* a load balancer is required when CDN is attached and will be created if no arn is present in config.
|
|
19
|
+
* */
|
|
20
|
+
loadBalancer?: {
|
|
21
|
+
/**
|
|
22
|
+
* Existing load balancer ARN.
|
|
23
|
+
* used for sharing the same load balancer across various applications
|
|
24
|
+
* */
|
|
25
|
+
arn: string;
|
|
26
|
+
/**
|
|
27
|
+
* This is required as load balancer is shared with other applications.
|
|
28
|
+
* it helps to be able to create unique priority for environment in this app
|
|
29
|
+
* */
|
|
30
|
+
priorityRange: [number, number];
|
|
31
|
+
} | ApplicationLoadBalancerProps;
|
|
32
|
+
};
|
|
33
|
+
tasks?: Record<string, TaskApp>;
|
|
34
|
+
};
|
|
35
|
+
export type ServerApp = {
|
|
36
|
+
type: typeof AppType.NEXT_APP_ROUTER | typeof AppType.IMAGE_APP;
|
|
37
|
+
/** Directory of build output to be deployed */
|
|
38
|
+
output: string;
|
|
39
|
+
env?: Record<string, string>;
|
|
40
|
+
/** Additional parameters that may be required, this varies based on type */
|
|
41
|
+
buildParams?: Record<string, unknown>;
|
|
42
|
+
port: number;
|
|
43
|
+
container?: Omit<ContainerDefinitionOptions, 'image' | 'logging'> & {
|
|
44
|
+
image: AssetImageProps;
|
|
45
|
+
logDuration?: RetentionDays;
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
export type TaskApp = {
|
|
49
|
+
type: typeof AppType.IMAGE_APP;
|
|
50
|
+
/** Directory of build output to be deployed */
|
|
51
|
+
output: string;
|
|
52
|
+
env?: Record<string, string>;
|
|
53
|
+
buildParams?: Record<string, unknown>;
|
|
54
|
+
container?: Omit<ContainerDefinitionOptions, 'image' | 'logging'> & {
|
|
55
|
+
image: AssetImageProps;
|
|
56
|
+
logDuration?: RetentionDays;
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
export type AppProperties<BuildParams = Record<string, unknown>> = {
|
|
60
|
+
appName: string;
|
|
61
|
+
environmentPath: string;
|
|
62
|
+
taskDefinition: TaskDefinition;
|
|
63
|
+
env?: Record<string, string>;
|
|
64
|
+
buildParams: BuildParams;
|
|
65
|
+
serverOrigin: (port: number, containerName: string, appPath: string, healthPath?: string) => {
|
|
66
|
+
basePath: string;
|
|
67
|
+
origin: LoadBalancerV2Origin;
|
|
68
|
+
};
|
|
69
|
+
port: number;
|
|
70
|
+
output: string;
|
|
71
|
+
container?: Omit<ContainerDefinitionOptions, 'image' | 'logging'> & {
|
|
72
|
+
image: AssetImageProps;
|
|
73
|
+
logDuration?: RetentionDays;
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
export type TaskConstructsProps = FargateTaskDefinitionProps & {
|
|
77
|
+
vpc: IVpc;
|
|
78
|
+
cluster: Cluster;
|
|
79
|
+
env?: Record<string, string>;
|
|
80
|
+
/** Directory of build output to be deployed */
|
|
81
|
+
output: string;
|
|
82
|
+
container?: Omit<ContainerDefinitionOptions, 'image' | 'logging'> & {
|
|
83
|
+
image: AssetImageProps;
|
|
84
|
+
logDuration?: RetentionDays;
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
export interface AppConstruct extends Attach, CDNResource, ApiResource {
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/lib/ecs/types.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,68 @@
|
|
|
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 { AssetImageCodeProps, 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 { z } from 'zod';
|
|
9
|
+
import { AppConstruct, AppProperties } from '../types';
|
|
10
|
+
declare const BuildParamsSchema: z.ZodObject<{
|
|
11
|
+
container: z.ZodObject<{
|
|
12
|
+
file: z.ZodOptional<z.ZodString>;
|
|
13
|
+
cmd: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
14
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
15
|
+
file: z.ZodOptional<z.ZodString>;
|
|
16
|
+
cmd: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
17
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
18
|
+
file: z.ZodOptional<z.ZodString>;
|
|
19
|
+
cmd: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
20
|
+
}, z.ZodTypeAny, "passthrough">>;
|
|
21
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
22
|
+
container: z.ZodObject<{
|
|
23
|
+
file: z.ZodOptional<z.ZodString>;
|
|
24
|
+
cmd: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
25
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
26
|
+
file: z.ZodOptional<z.ZodString>;
|
|
27
|
+
cmd: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
28
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
29
|
+
file: z.ZodOptional<z.ZodString>;
|
|
30
|
+
cmd: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
31
|
+
}, z.ZodTypeAny, "passthrough">>;
|
|
32
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
33
|
+
container: z.ZodObject<{
|
|
34
|
+
file: z.ZodOptional<z.ZodString>;
|
|
35
|
+
cmd: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
36
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
37
|
+
file: z.ZodOptional<z.ZodString>;
|
|
38
|
+
cmd: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
39
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
40
|
+
file: z.ZodOptional<z.ZodString>;
|
|
41
|
+
cmd: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
42
|
+
}, z.ZodTypeAny, "passthrough">>;
|
|
43
|
+
}, z.ZodTypeAny, "passthrough">>;
|
|
44
|
+
export declare class ImageAppConstruct extends Construct implements AppConstruct {
|
|
45
|
+
function: Function;
|
|
46
|
+
queue: Queue | undefined;
|
|
47
|
+
constructor(scope: Construct, id: string, props: AppProperties<z.infer<typeof BuildParamsSchema> & AssetImageCodeProps>);
|
|
48
|
+
attach(attachable: Record<string, Attachable>): void;
|
|
49
|
+
grant(...grantables: Grantable[]): void;
|
|
50
|
+
subscription(props: SubscriptionProps): ITopicSubscription;
|
|
51
|
+
cloudfront(path: string): Record<string, BehaviorOptions>;
|
|
52
|
+
cloudfrontPolicy(distributionId: string): void;
|
|
53
|
+
api(path: string): Record<string, HttpRouteIntegration>;
|
|
54
|
+
static parse(params: unknown): z.objectOutputType<{
|
|
55
|
+
container: z.ZodObject<{
|
|
56
|
+
file: z.ZodOptional<z.ZodString>;
|
|
57
|
+
cmd: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
58
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
59
|
+
file: z.ZodOptional<z.ZodString>;
|
|
60
|
+
cmd: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
61
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
62
|
+
file: z.ZodOptional<z.ZodString>;
|
|
63
|
+
cmd: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
64
|
+
}, z.ZodTypeAny, "passthrough">>;
|
|
65
|
+
}, z.ZodTypeAny, "passthrough">;
|
|
66
|
+
}
|
|
67
|
+
export {};
|
|
68
|
+
//# sourceMappingURL=image-app-construct.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"image-app-construct.d.ts","sourceRoot":"","sources":["../../../../src/lib/lambda/apps/image-app-construct.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAExD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACzE,OAAO,EAEL,eAAe,EAKhB,MAAM,4BAA4B,CAAC;AAGpC,OAAO,EACL,mBAAmB,EAEnB,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;AACvC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAMvD,QAAA,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;gCASP,CAAC;AAEjB,qBAAa,iBAAkB,SAAQ,SAAU,YAAW,YAAY;IAC/D,QAAQ,EAAE,QAAQ,CAAC;IACnB,KAAK,EAAE,KAAK,GAAG,SAAS,CAAC;gBAG9B,KAAK,EAAE,SAAS,EAChB,EAAE,EAAE,MAAM,EACV,KAAK,EAAE,aAAa,CAClB,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,GAAG,mBAAmB,CACxD;IA2BH,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;IAW1D,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC;IAqBzD,gBAAgB,CAAC,cAAc,EAAE,MAAM;IAIvC,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAC;IAIvD,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,OAAO;;;;;;;;;;;;CAG7B"}
|
|
@@ -0,0 +1,92 @@
|
|
|
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 zod_1 = require("zod");
|
|
14
|
+
const getDefaultLambda_1 = require("../utils/getDefaultLambda");
|
|
15
|
+
const lambda_api_1 = require("../utils/lambda-api");
|
|
16
|
+
const lambda_attach_1 = require("../utils/lambda-attach");
|
|
17
|
+
const lambda_grant_1 = require("../utils/lambda-grant");
|
|
18
|
+
const BuildParamsSchema = zod_1.z
|
|
19
|
+
.object({
|
|
20
|
+
container: zod_1.z
|
|
21
|
+
.object({
|
|
22
|
+
file: zod_1.z.string().optional(),
|
|
23
|
+
cmd: zod_1.z.string().array().optional(),
|
|
24
|
+
})
|
|
25
|
+
.passthrough(),
|
|
26
|
+
})
|
|
27
|
+
.passthrough();
|
|
28
|
+
class ImageAppConstruct extends constructs_1.Construct {
|
|
29
|
+
function;
|
|
30
|
+
queue;
|
|
31
|
+
constructor(scope, id, props) {
|
|
32
|
+
super(scope, id);
|
|
33
|
+
this.function = new aws_lambda_1.Function(this, `AppFunction`, {
|
|
34
|
+
...(0, getDefaultLambda_1.getDefaultLambda)(props),
|
|
35
|
+
code: aws_lambda_1.Code.fromAssetImage(props.output, {
|
|
36
|
+
platform: aws_ecr_assets_1.Platform.LINUX_AMD64,
|
|
37
|
+
...props.buildParams.container,
|
|
38
|
+
}),
|
|
39
|
+
handler: aws_lambda_1.Handler.FROM_IMAGE,
|
|
40
|
+
runtime: aws_lambda_1.Runtime.FROM_IMAGE,
|
|
41
|
+
});
|
|
42
|
+
if (props.queue) {
|
|
43
|
+
this.queue = new aws_sqs_1.Queue(this, 'AppQueue', {
|
|
44
|
+
visibilityTimeout: aws_cdk_lib_1.Duration.seconds((props.timeout ?? 30) + 30),
|
|
45
|
+
});
|
|
46
|
+
this.function.addEventSource(new aws_lambda_event_sources_1.SqsEventSource(this.queue, {
|
|
47
|
+
batchSize: props.queue.batchSize,
|
|
48
|
+
}));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
attach(attachable) {
|
|
52
|
+
return (0, lambda_attach_1.lambdaAttach)(this.function, attachable);
|
|
53
|
+
}
|
|
54
|
+
grant(...grantables) {
|
|
55
|
+
return (0, lambda_grant_1.lambdaGrant)(this.function, grantables);
|
|
56
|
+
}
|
|
57
|
+
subscription(props) {
|
|
58
|
+
if (this.queue) {
|
|
59
|
+
return new aws_sns_subscriptions_1.SqsSubscription(this.queue, {
|
|
60
|
+
...props,
|
|
61
|
+
rawMessageDelivery: true,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
return new aws_sns_subscriptions_1.LambdaSubscription(this.function, props);
|
|
65
|
+
}
|
|
66
|
+
cloudfront(path) {
|
|
67
|
+
this.function.addEnvironment('BASE_PATH', path);
|
|
68
|
+
const apiUrl = this.function.addFunctionUrl({
|
|
69
|
+
authType: aws_lambda_1.FunctionUrlAuthType.NONE,
|
|
70
|
+
});
|
|
71
|
+
const apiBehavior = {
|
|
72
|
+
origin: new aws_cloudfront_origins_1.FunctionUrlOrigin(apiUrl),
|
|
73
|
+
cachePolicy: aws_cloudfront_1.CachePolicy.CACHING_DISABLED,
|
|
74
|
+
allowedMethods: aws_cloudfront_1.AllowedMethods.ALLOW_ALL,
|
|
75
|
+
compress: true,
|
|
76
|
+
viewerProtocolPolicy: aws_cloudfront_1.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
|
|
77
|
+
originRequestPolicy: aws_cloudfront_1.OriginRequestPolicy.ALL_VIEWER_EXCEPT_HOST_HEADER,
|
|
78
|
+
responseHeadersPolicy: aws_cloudfront_1.ResponseHeadersPolicy.CORS_ALLOW_ALL_ORIGINS_WITH_PREFLIGHT_AND_SECURITY_HEADERS,
|
|
79
|
+
};
|
|
80
|
+
return { [`${path}/*`]: apiBehavior };
|
|
81
|
+
}
|
|
82
|
+
cloudfrontPolicy(distributionId) {
|
|
83
|
+
throw new Error('cloudfrontPolicy not implemented');
|
|
84
|
+
}
|
|
85
|
+
api(path) {
|
|
86
|
+
return (0, lambda_api_1.lambdaApi)(this.function, path);
|
|
87
|
+
}
|
|
88
|
+
static parse(params) {
|
|
89
|
+
return BuildParamsSchema.parse(params);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
exports.ImageAppConstruct = ImageAppConstruct;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Attachable, Grantable } from '@fy-stack/types';
|
|
2
|
+
import type { HttpRouteIntegration } from 'aws-cdk-lib/aws-apigatewayv2';
|
|
3
|
+
import * as cloudfront from 'aws-cdk-lib/aws-cloudfront';
|
|
4
|
+
import * as lambda from 'aws-cdk-lib/aws-lambda';
|
|
5
|
+
import { ITopicSubscription } from 'aws-cdk-lib/aws-sns';
|
|
6
|
+
import * as sqs from 'aws-cdk-lib/aws-sqs';
|
|
7
|
+
import { Construct } from 'constructs';
|
|
8
|
+
import { z } from 'zod';
|
|
9
|
+
import { AppConstruct, AppProperties } from '../types';
|
|
10
|
+
declare const BuildParamsSchema: z.ZodObject<{
|
|
11
|
+
cmd: z.ZodString;
|
|
12
|
+
}, "strip", z.ZodTypeAny, {
|
|
13
|
+
cmd: string;
|
|
14
|
+
}, {
|
|
15
|
+
cmd: string;
|
|
16
|
+
}>;
|
|
17
|
+
export declare class NextAppRouterConstruct extends Construct implements AppConstruct {
|
|
18
|
+
function: lambda.Function;
|
|
19
|
+
queue: sqs.Queue | undefined;
|
|
20
|
+
private readonly static;
|
|
21
|
+
constructor(scope: Construct, id: string, props: AppProperties<z.infer<typeof BuildParamsSchema>>);
|
|
22
|
+
cloudfront(path: string): Record<string, cloudfront.BehaviorOptions>;
|
|
23
|
+
cloudfrontPolicy(distributionId: string): void;
|
|
24
|
+
api(): Record<string, HttpRouteIntegration>;
|
|
25
|
+
attach(attachable: Record<string, Attachable>): void;
|
|
26
|
+
grant(...grants: Grantable[]): void;
|
|
27
|
+
subscription(): ITopicSubscription;
|
|
28
|
+
static parse(params: unknown): {
|
|
29
|
+
cmd: string;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export {};
|
|
33
|
+
//# sourceMappingURL=next-app-router-construct.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"next-app-router-construct.d.ts","sourceRoot":"","sources":["../../../../src/lib/lambda/apps/next-app-router-construct.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAExD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACzE,OAAO,KAAK,UAAU,MAAM,4BAA4B,CAAC;AAEzD,OAAO,KAAK,MAAM,MAAM,wBAAwB,CAAC;AAEjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,GAAG,MAAM,qBAAqB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAOxB,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAIvD,QAAA,MAAM,iBAAiB;;;;;;EAErB,CAAC;AAEH,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;gBAGjC,KAAK,EAAE,SAAS,EAChB,EAAE,EAAE,MAAM,EACV,KAAK,EAAE,aAAa,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;IAqCzD,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,eAAe,CAAC;IAcpE,gBAAgB,CAAC,cAAc,EAAE,MAAM;IAIvC,GAAG,IAAI,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAC;IAI3C,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC;IAI7C,KAAK,CAAC,GAAG,MAAM,EAAE,SAAS,EAAE;IAI5B,YAAY,IAAI,kBAAkB;IAIlC,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,OAAO;;;CAG7B"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NextAppRouterConstruct = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const fs = tslib_1.__importStar(require("node:fs"));
|
|
6
|
+
const path = tslib_1.__importStar(require("node:path"));
|
|
7
|
+
const cdk = tslib_1.__importStar(require("aws-cdk-lib"));
|
|
8
|
+
const cloudfrontOrigin = tslib_1.__importStar(require("aws-cdk-lib/aws-cloudfront-origins"));
|
|
9
|
+
const lambda = tslib_1.__importStar(require("aws-cdk-lib/aws-lambda"));
|
|
10
|
+
const constructs_1 = require("constructs");
|
|
11
|
+
const zod_1 = require("zod");
|
|
12
|
+
const next_app_router_1 = require("../../shared/next-app-router");
|
|
13
|
+
const lambda_attach_1 = require("../utils/lambda-attach");
|
|
14
|
+
const lambda_grant_1 = require("../utils/lambda-grant");
|
|
15
|
+
const BuildParamsSchema = zod_1.z.object({
|
|
16
|
+
cmd: zod_1.z.string(),
|
|
17
|
+
});
|
|
18
|
+
class NextAppRouterConstruct extends constructs_1.Construct {
|
|
19
|
+
function;
|
|
20
|
+
queue;
|
|
21
|
+
static;
|
|
22
|
+
constructor(scope, id, props) {
|
|
23
|
+
super(scope, id);
|
|
24
|
+
const region = cdk.Stack.of(this).region;
|
|
25
|
+
this.static = (0, next_app_router_1.staticDeployment)(this, props.output);
|
|
26
|
+
const webAdapterLayer = lambda.LayerVersion.fromLayerVersionArn(this, 'WebAdapterLayer', `arn:aws:lambda:${region}:753240598075:layer:LambdaAdapterLayerX86:16`);
|
|
27
|
+
const environment = {
|
|
28
|
+
AWS_LAMBDA_EXEC_WRAPPER: '/opt/bootstrap',
|
|
29
|
+
PORT: '8080',
|
|
30
|
+
AWS_NODEJS_CONNECTION_REUSE_ENABLED: '1',
|
|
31
|
+
AWS_LWA_INVOKE_MODE: 'response_stream',
|
|
32
|
+
};
|
|
33
|
+
Object.assign(environment, props.env);
|
|
34
|
+
const serverOutput = path.join(props.output, '/.next/standalone');
|
|
35
|
+
fs.writeFileSync(path.join(serverOutput, 'run.sh'), props.buildParams.cmd);
|
|
36
|
+
this.function = new lambda.Function(this, `AppFunction`, {
|
|
37
|
+
runtime: lambda.Runtime.NODEJS_20_X,
|
|
38
|
+
memorySize: 512,
|
|
39
|
+
handler: 'run.sh',
|
|
40
|
+
timeout: cdk.Duration.seconds(60),
|
|
41
|
+
code: lambda.Code.fromAsset(serverOutput),
|
|
42
|
+
loggingFormat: lambda.LoggingFormat.JSON,
|
|
43
|
+
layers: [webAdapterLayer],
|
|
44
|
+
environment,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
cloudfront(path) {
|
|
48
|
+
const webUrl = this.function.addFunctionUrl({
|
|
49
|
+
authType: lambda.FunctionUrlAuthType.NONE,
|
|
50
|
+
invokeMode: lambda.InvokeMode.RESPONSE_STREAM,
|
|
51
|
+
});
|
|
52
|
+
const serverOrigin = new cloudfrontOrigin.FunctionUrlOrigin(webUrl);
|
|
53
|
+
return {
|
|
54
|
+
...(0, next_app_router_1.serverCloudfrontBehaviour)(this, serverOrigin, path),
|
|
55
|
+
...(0, next_app_router_1.staticCloudfrontBehaviour)(this.static, path),
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
cloudfrontPolicy(distributionId) {
|
|
59
|
+
throw new Error(`cloudfrontPolicy not supported for ${this}`);
|
|
60
|
+
}
|
|
61
|
+
api() {
|
|
62
|
+
throw new Error('api not supported for this construct');
|
|
63
|
+
}
|
|
64
|
+
attach(attachable) {
|
|
65
|
+
return (0, lambda_attach_1.lambdaAttach)(this.function, attachable);
|
|
66
|
+
}
|
|
67
|
+
grant(...grants) {
|
|
68
|
+
return (0, lambda_grant_1.lambdaGrant)(this.function, grants);
|
|
69
|
+
}
|
|
70
|
+
subscription() {
|
|
71
|
+
throw new Error(`subscription not supported for ${this}`);
|
|
72
|
+
}
|
|
73
|
+
static parse(params) {
|
|
74
|
+
return BuildParamsSchema.parse(params);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
exports.NextAppRouterConstruct = NextAppRouterConstruct;
|
|
@@ -0,0 +1,43 @@
|
|
|
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 { z } from 'zod';
|
|
8
|
+
import { AppConstruct, AppProperties } from '../types';
|
|
9
|
+
declare const BuildParamsSchema: z.ZodObject<{
|
|
10
|
+
cmd: z.ZodString;
|
|
11
|
+
}, "strip", z.ZodTypeAny, {
|
|
12
|
+
cmd: string;
|
|
13
|
+
}, {
|
|
14
|
+
cmd: string;
|
|
15
|
+
}>;
|
|
16
|
+
export declare class NodeApiConstruct extends Construct implements AppConstruct {
|
|
17
|
+
function: lambda.Function;
|
|
18
|
+
queue: sqs.Queue | undefined;
|
|
19
|
+
constructor(scope: Construct, id: string, props: AppProperties<z.infer<typeof BuildParamsSchema>>);
|
|
20
|
+
attach(attachable: Record<string, Attachable>): void;
|
|
21
|
+
grant(...grants: Grantable[]): void;
|
|
22
|
+
subscription(props: SubscriptionProps): ITopicSubscription;
|
|
23
|
+
cloudfront(path: string): {
|
|
24
|
+
[x: string]: {
|
|
25
|
+
origin: cdk.aws_cloudfront_origins.FunctionUrlOrigin;
|
|
26
|
+
cachePolicy: cdk.aws_cloudfront.ICachePolicy;
|
|
27
|
+
allowedMethods: cdk.aws_cloudfront.AllowedMethods;
|
|
28
|
+
compress: boolean;
|
|
29
|
+
viewerProtocolPolicy: cdk.aws_cloudfront.ViewerProtocolPolicy;
|
|
30
|
+
originRequestPolicy: cdk.aws_cloudfront.IOriginRequestPolicy;
|
|
31
|
+
responseHeadersPolicy: cdk.aws_cloudfront.IResponseHeadersPolicy;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
cloudfrontPolicy(distributionId: string): void;
|
|
35
|
+
api(path: string): {
|
|
36
|
+
[x: string]: cdk.aws_apigatewayv2_integrations.HttpUrlIntegration;
|
|
37
|
+
};
|
|
38
|
+
static parse(params: unknown): {
|
|
39
|
+
cmd: string;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
export {};
|
|
43
|
+
//# sourceMappingURL=node-api-construct.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-api-construct.d.ts","sourceRoot":"","sources":["../../../../src/lib/lambda/apps/node-api-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;AAC5E,OAAO,KAAK,GAAG,MAAM,qBAAqB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAKvD,QAAA,MAAM,iBAAiB;;;;;;EAErB,CAAA;AAEF,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,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;IA+CjG,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,gBAAgB,CAAC,cAAc,EAAE,MAAM;IAIvC,GAAG,CAAC,IAAI,EAAE,MAAM;;;IAIhB,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,OAAO;;;CAG7B"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NodeApiConstruct = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
|
|
6
|
+
const node_path_1 = tslib_1.__importDefault(require("node:path"));
|
|
7
|
+
const cdk = tslib_1.__importStar(require("aws-cdk-lib"));
|
|
8
|
+
const cloudfront = tslib_1.__importStar(require("aws-cdk-lib/aws-cloudfront"));
|
|
9
|
+
const cloudfrontOrigin = tslib_1.__importStar(require("aws-cdk-lib/aws-cloudfront-origins"));
|
|
10
|
+
const lambda = tslib_1.__importStar(require("aws-cdk-lib/aws-lambda"));
|
|
11
|
+
const lambdaEventSource = tslib_1.__importStar(require("aws-cdk-lib/aws-lambda-event-sources"));
|
|
12
|
+
const sqs = tslib_1.__importStar(require("aws-cdk-lib/aws-sqs"));
|
|
13
|
+
const constructs_1 = require("constructs");
|
|
14
|
+
const zod_1 = require("zod");
|
|
15
|
+
const lambda_api_1 = require("../utils/lambda-api");
|
|
16
|
+
const lambda_attach_1 = require("../utils/lambda-attach");
|
|
17
|
+
const lambda_grant_1 = require("../utils/lambda-grant");
|
|
18
|
+
const BuildParamsSchema = zod_1.z.object({
|
|
19
|
+
cmd: zod_1.z.string(),
|
|
20
|
+
});
|
|
21
|
+
class NodeApiConstruct extends constructs_1.Construct {
|
|
22
|
+
function;
|
|
23
|
+
queue;
|
|
24
|
+
constructor(scope, id, props) {
|
|
25
|
+
super(scope, id);
|
|
26
|
+
const region = cdk.Stack.of(this).region;
|
|
27
|
+
const environment = {};
|
|
28
|
+
Object.assign(environment, props.env);
|
|
29
|
+
const layers = [
|
|
30
|
+
lambda.LayerVersion.fromLayerVersionArn(this, 'WebAdapterLayer', `arn:aws:lambda:${region}:753240598075:layer:LambdaAdapterLayerX86:16`)
|
|
31
|
+
];
|
|
32
|
+
Object.assign(environment, {
|
|
33
|
+
AWS_LAMBDA_EXEC_WRAPPER: '/opt/bootstrap',
|
|
34
|
+
AWS_NODEJS_CONNECTION_REUSE_ENABLED: '1',
|
|
35
|
+
PORT: '8080',
|
|
36
|
+
});
|
|
37
|
+
node_fs_1.default.writeFileSync(node_path_1.default.join(props.output, 'run.sh'), props.buildParams.cmd);
|
|
38
|
+
this.function = new lambda.Function(this, `AppFunction`, {
|
|
39
|
+
runtime: lambda.Runtime.NODEJS_20_X,
|
|
40
|
+
memorySize: 512,
|
|
41
|
+
handler: 'run.sh',
|
|
42
|
+
layers,
|
|
43
|
+
timeout: cdk.Duration.seconds(30),
|
|
44
|
+
code: lambda.Code.fromAsset(props.output),
|
|
45
|
+
environment,
|
|
46
|
+
});
|
|
47
|
+
if (props.queue) {
|
|
48
|
+
this.queue = new sqs.Queue(this, 'AppQueue', {
|
|
49
|
+
visibilityTimeout: cdk.Duration.seconds(59),
|
|
50
|
+
});
|
|
51
|
+
this.function.addEventSource(new lambdaEventSource.SqsEventSource(this.queue, {
|
|
52
|
+
batchSize: props.queue.batchSize,
|
|
53
|
+
}));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
attach(attachable) {
|
|
57
|
+
return (0, lambda_attach_1.lambdaAttach)(this.function, attachable);
|
|
58
|
+
}
|
|
59
|
+
grant(...grants) {
|
|
60
|
+
return (0, lambda_grant_1.lambdaGrant)(this.function, grants);
|
|
61
|
+
}
|
|
62
|
+
subscription(props) {
|
|
63
|
+
throw new Error(`subscription is not supported for ${this}`);
|
|
64
|
+
}
|
|
65
|
+
cloudfront(path) {
|
|
66
|
+
const apiUrl = this.function.addFunctionUrl({
|
|
67
|
+
authType: lambda.FunctionUrlAuthType.NONE,
|
|
68
|
+
});
|
|
69
|
+
const apiBehavior = {
|
|
70
|
+
origin: new cloudfrontOrigin.FunctionUrlOrigin(apiUrl),
|
|
71
|
+
cachePolicy: cloudfront.CachePolicy.CACHING_DISABLED,
|
|
72
|
+
allowedMethods: cloudfront.AllowedMethods.ALLOW_ALL,
|
|
73
|
+
compress: true,
|
|
74
|
+
viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
|
|
75
|
+
originRequestPolicy: cloudfront.OriginRequestPolicy.ALL_VIEWER_EXCEPT_HOST_HEADER,
|
|
76
|
+
responseHeadersPolicy: cloudfront.ResponseHeadersPolicy
|
|
77
|
+
.CORS_ALLOW_ALL_ORIGINS_WITH_PREFLIGHT_AND_SECURITY_HEADERS,
|
|
78
|
+
};
|
|
79
|
+
return { [`${path}/*`]: apiBehavior };
|
|
80
|
+
}
|
|
81
|
+
cloudfrontPolicy(distributionId) {
|
|
82
|
+
throw new Error(`cloudfrontPolicy not supported for ${this}`);
|
|
83
|
+
}
|
|
84
|
+
api(path) {
|
|
85
|
+
return (0, lambda_api_1.lambdaApi)(this.function, path);
|
|
86
|
+
}
|
|
87
|
+
static parse(params) {
|
|
88
|
+
return BuildParamsSchema.parse(params);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
exports.NodeApiConstruct = NodeApiConstruct;
|
|
@@ -0,0 +1,32 @@
|
|
|
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 * as lambda from 'aws-cdk-lib/aws-lambda';
|
|
5
|
+
import { ITopicSubscription, SubscriptionProps } from 'aws-cdk-lib/aws-sns';
|
|
6
|
+
import * as sqs from 'aws-cdk-lib/aws-sqs';
|
|
7
|
+
import { Construct } from 'constructs';
|
|
8
|
+
import { z } from 'zod';
|
|
9
|
+
import { AppConstruct, AppProperties } from '../types';
|
|
10
|
+
declare const BuildParamsSchema: z.ZodObject<{
|
|
11
|
+
handler: z.ZodOptional<z.ZodString>;
|
|
12
|
+
}, "strip", z.ZodTypeAny, {
|
|
13
|
+
handler?: string | undefined;
|
|
14
|
+
}, {
|
|
15
|
+
handler?: string | undefined;
|
|
16
|
+
}>;
|
|
17
|
+
export declare class NodeAppConstruct extends Construct implements AppConstruct {
|
|
18
|
+
function: lambda.Function;
|
|
19
|
+
queue: sqs.Queue | undefined;
|
|
20
|
+
constructor(scope: Construct, id: string, props: AppProperties<z.infer<typeof BuildParamsSchema>>);
|
|
21
|
+
attach(attachable: Record<string, Attachable>): void;
|
|
22
|
+
grant(...grants: Grantable[]): void;
|
|
23
|
+
subscription(props: SubscriptionProps): ITopicSubscription;
|
|
24
|
+
cloudfront(path: string): Record<string, BehaviorOptions>;
|
|
25
|
+
cloudfrontPolicy(distributionId: string): void;
|
|
26
|
+
api(path: string): Record<string, HttpRouteIntegration>;
|
|
27
|
+
static parse(params: unknown): {
|
|
28
|
+
handler?: string | undefined;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
export {};
|
|
32
|
+
//# sourceMappingURL=node-app-construct.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-app-construct.d.ts","sourceRoot":"","sources":["../../../../src/lib/lambda/apps/node-app-construct.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAExD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AAEzE,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,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;AACvC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAIvD,QAAA,MAAM,iBAAiB;;;;;;EAErB,CAAA;AAEF,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,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;IA8BjG,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,gBAAgB,CAAC,cAAc,EAAE,MAAM;IAIvC,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAC;IAcvD,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,OAAO;;;CAG7B"}
|
|
@@ -0,0 +1,73 @@
|
|
|
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 aws_apigatewayv2_integrations_1 = require("aws-cdk-lib/aws-apigatewayv2-integrations");
|
|
7
|
+
const lambda = tslib_1.__importStar(require("aws-cdk-lib/aws-lambda"));
|
|
8
|
+
const aws_lambda_1 = require("aws-cdk-lib/aws-lambda");
|
|
9
|
+
const lambdaEventSource = tslib_1.__importStar(require("aws-cdk-lib/aws-lambda-event-sources"));
|
|
10
|
+
const snsSubscriptions = tslib_1.__importStar(require("aws-cdk-lib/aws-sns-subscriptions"));
|
|
11
|
+
const sqs = tslib_1.__importStar(require("aws-cdk-lib/aws-sqs"));
|
|
12
|
+
const constructs_1 = require("constructs");
|
|
13
|
+
const zod_1 = require("zod");
|
|
14
|
+
const lambda_attach_1 = require("../utils/lambda-attach");
|
|
15
|
+
const lambda_grant_1 = require("../utils/lambda-grant");
|
|
16
|
+
const BuildParamsSchema = zod_1.z.object({
|
|
17
|
+
handler: zod_1.z.string().optional(),
|
|
18
|
+
});
|
|
19
|
+
class NodeAppConstruct extends constructs_1.Construct {
|
|
20
|
+
function;
|
|
21
|
+
queue;
|
|
22
|
+
constructor(scope, id, props) {
|
|
23
|
+
super(scope, id);
|
|
24
|
+
const environment = {};
|
|
25
|
+
Object.assign(environment, props.env);
|
|
26
|
+
this.function = new lambda.Function(this, `AppFunction`, {
|
|
27
|
+
runtime: lambda.Runtime.NODEJS_20_X,
|
|
28
|
+
memorySize: 512,
|
|
29
|
+
handler: props.buildParams.handler ?? "index.handler",
|
|
30
|
+
timeout: cdk.Duration.seconds(30),
|
|
31
|
+
code: lambda.Code.fromAsset(props.output),
|
|
32
|
+
loggingFormat: aws_lambda_1.LoggingFormat.JSON,
|
|
33
|
+
environment,
|
|
34
|
+
});
|
|
35
|
+
if (props.queue) {
|
|
36
|
+
this.queue = new sqs.Queue(this, 'AppQueue', {
|
|
37
|
+
visibilityTimeout: cdk.Duration.seconds(59),
|
|
38
|
+
});
|
|
39
|
+
this.function.addEventSource(new lambdaEventSource.SqsEventSource(this.queue, {
|
|
40
|
+
batchSize: props.queue.batchSize,
|
|
41
|
+
}));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
attach(attachable) {
|
|
45
|
+
return (0, lambda_attach_1.lambdaAttach)(this.function, attachable);
|
|
46
|
+
}
|
|
47
|
+
grant(...grants) {
|
|
48
|
+
return (0, lambda_grant_1.lambdaGrant)(this.function, grants);
|
|
49
|
+
}
|
|
50
|
+
subscription(props) {
|
|
51
|
+
if (this.queue)
|
|
52
|
+
return new snsSubscriptions.SqsSubscription(this.queue, { ...props, rawMessageDelivery: true });
|
|
53
|
+
return new snsSubscriptions.LambdaSubscription(this.function, props);
|
|
54
|
+
}
|
|
55
|
+
cloudfront(path) {
|
|
56
|
+
throw new Error(`cloudfront not supported for ${this}`);
|
|
57
|
+
}
|
|
58
|
+
cloudfrontPolicy(distributionId) {
|
|
59
|
+
throw new Error(`cloudfrontPolicy not supported for ${this}`);
|
|
60
|
+
}
|
|
61
|
+
api(path) {
|
|
62
|
+
this.function.addEnvironment('BASE_PATH', path);
|
|
63
|
+
const integration = new aws_apigatewayv2_integrations_1.HttpLambdaIntegration('AppIntegration', this.function);
|
|
64
|
+
return {
|
|
65
|
+
[path]: integration,
|
|
66
|
+
[`${path}/{proxy+}`]: integration
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
static parse(params) {
|
|
70
|
+
return BuildParamsSchema.parse(params);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
exports.NodeAppConstruct = NodeAppConstruct;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Construct } from 'constructs';
|
|
2
|
+
import { AppConstruct, LambdaConstructProps } from './types';
|
|
3
|
+
export declare class LambdaConstruct extends Construct {
|
|
4
|
+
apps: Record<string, AppConstruct>;
|
|
5
|
+
constructor(scope: Construct, id: string, props: LambdaConstructProps);
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=lambda-construct.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lambda-construct.d.ts","sourceRoot":"","sources":["../../../src/lib/lambda/lambda-construct.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAMvC,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAS7D,qBAAa,eAAgB,SAAQ,SAAS;IAC5C,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAM;gBAE5B,KAAK,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,oBAAoB;CAsBtE"}
|