@incloodsolutions/devkit 0.0.2 → 0.0.4
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/README.md +150 -41
- package/dist/aws-cdk/api-gateway-v2.cjs +77 -0
- package/dist/aws-cdk/api-gateway-v2.cjs.map +1 -0
- package/dist/aws-cdk/api-gateway-v2.d.cts +55 -0
- package/dist/aws-cdk/api-gateway-v2.d.ts +55 -0
- package/dist/aws-cdk/api-gateway-v2.js +75 -0
- package/dist/aws-cdk/api-gateway-v2.js.map +1 -0
- package/dist/aws-cdk/api-gateway-websocket.cjs +77 -0
- package/dist/aws-cdk/api-gateway-websocket.cjs.map +1 -0
- package/dist/aws-cdk/api-gateway-websocket.d.cts +73 -0
- package/dist/aws-cdk/api-gateway-websocket.d.ts +73 -0
- package/dist/aws-cdk/api-gateway-websocket.js +75 -0
- package/dist/aws-cdk/api-gateway-websocket.js.map +1 -0
- package/dist/aws-cdk/api-gateway.cjs +98 -0
- package/dist/aws-cdk/api-gateway.cjs.map +1 -0
- package/dist/aws-cdk/api-gateway.d.cts +80 -0
- package/dist/aws-cdk/api-gateway.d.ts +80 -0
- package/dist/aws-cdk/api-gateway.js +96 -0
- package/dist/aws-cdk/api-gateway.js.map +1 -0
- package/dist/aws-cdk/cloudfront.cjs +68 -0
- package/dist/aws-cdk/cloudfront.cjs.map +1 -0
- package/dist/aws-cdk/cloudfront.d.cts +36 -0
- package/dist/aws-cdk/cloudfront.d.ts +36 -0
- package/dist/aws-cdk/cloudfront.js +66 -0
- package/dist/aws-cdk/cloudfront.js.map +1 -0
- package/dist/aws-cdk/cloudwatch.cjs +43 -0
- package/dist/aws-cdk/cloudwatch.cjs.map +1 -0
- package/dist/aws-cdk/cloudwatch.d.cts +36 -0
- package/dist/aws-cdk/cloudwatch.d.ts +36 -0
- package/dist/aws-cdk/cloudwatch.js +41 -0
- package/dist/aws-cdk/cloudwatch.js.map +1 -0
- package/dist/aws-cdk/dynamo-db.cjs +113 -0
- package/dist/aws-cdk/dynamo-db.cjs.map +1 -0
- package/dist/aws-cdk/dynamo-db.d.cts +53 -0
- package/dist/aws-cdk/dynamo-db.d.ts +53 -0
- package/dist/aws-cdk/dynamo-db.js +111 -0
- package/dist/aws-cdk/dynamo-db.js.map +1 -0
- package/dist/aws-cdk/event-bridge.cjs +47 -0
- package/dist/aws-cdk/event-bridge.cjs.map +1 -0
- package/dist/aws-cdk/event-bridge.d.cts +41 -0
- package/dist/aws-cdk/event-bridge.d.ts +41 -0
- package/dist/aws-cdk/event-bridge.js +45 -0
- package/dist/aws-cdk/event-bridge.js.map +1 -0
- package/dist/aws-cdk/lambda-authorizer-v2.cjs +50 -0
- package/dist/aws-cdk/lambda-authorizer-v2.cjs.map +1 -0
- package/dist/aws-cdk/lambda-authorizer-v2.d.cts +45 -0
- package/dist/aws-cdk/lambda-authorizer-v2.d.ts +45 -0
- package/dist/aws-cdk/lambda-authorizer-v2.js +48 -0
- package/dist/aws-cdk/lambda-authorizer-v2.js.map +1 -0
- package/dist/aws-cdk/lambda-authorizer.cjs +37 -0
- package/dist/aws-cdk/lambda-authorizer.cjs.map +1 -0
- package/dist/aws-cdk/lambda-authorizer.d.cts +44 -0
- package/dist/aws-cdk/lambda-authorizer.d.ts +44 -0
- package/dist/aws-cdk/lambda-authorizer.js +35 -0
- package/dist/aws-cdk/lambda-authorizer.js.map +1 -0
- package/dist/aws-cdk/lambda-layer.cjs +69 -0
- package/dist/aws-cdk/lambda-layer.cjs.map +1 -0
- package/dist/aws-cdk/lambda-layer.d.cts +52 -0
- package/dist/aws-cdk/lambda-layer.d.ts +52 -0
- package/dist/aws-cdk/lambda-layer.js +67 -0
- package/dist/aws-cdk/lambda-layer.js.map +1 -0
- package/dist/aws-cdk/lambda.cjs +82 -0
- package/dist/aws-cdk/lambda.cjs.map +1 -0
- package/dist/aws-cdk/lambda.d.cts +37 -0
- package/dist/aws-cdk/lambda.d.ts +37 -0
- package/dist/aws-cdk/lambda.js +80 -0
- package/dist/aws-cdk/lambda.js.map +1 -0
- package/dist/aws-cdk/role-policy.cjs +53 -0
- package/dist/aws-cdk/role-policy.cjs.map +1 -0
- package/dist/aws-cdk/role-policy.d.cts +44 -0
- package/dist/aws-cdk/role-policy.d.ts +44 -0
- package/dist/aws-cdk/role-policy.js +51 -0
- package/dist/aws-cdk/role-policy.js.map +1 -0
- package/dist/aws-cdk/s3-deployment.cjs +177 -0
- package/dist/aws-cdk/s3-deployment.cjs.map +1 -0
- package/dist/aws-cdk/s3-deployment.d.cts +72 -0
- package/dist/aws-cdk/s3-deployment.d.ts +72 -0
- package/dist/aws-cdk/s3-deployment.js +175 -0
- package/dist/aws-cdk/s3-deployment.js.map +1 -0
- package/dist/aws-cdk/s3.cjs +38 -0
- package/dist/aws-cdk/s3.cjs.map +1 -0
- package/dist/aws-cdk/s3.d.cts +36 -0
- package/dist/aws-cdk/s3.d.ts +36 -0
- package/dist/aws-cdk/s3.js +36 -0
- package/dist/aws-cdk/s3.js.map +1 -0
- package/dist/aws-cdk/sns.cjs +43 -0
- package/dist/aws-cdk/sns.cjs.map +1 -0
- package/dist/aws-cdk/sns.d.cts +45 -0
- package/dist/aws-cdk/sns.d.ts +45 -0
- package/dist/aws-cdk/sns.js +41 -0
- package/dist/aws-cdk/sns.js.map +1 -0
- package/dist/aws-cdk/sqs.cjs +55 -0
- package/dist/aws-cdk/sqs.cjs.map +1 -0
- package/dist/aws-cdk/sqs.d.cts +52 -0
- package/dist/aws-cdk/sqs.d.ts +52 -0
- package/dist/aws-cdk/sqs.js +53 -0
- package/dist/aws-cdk/sqs.js.map +1 -0
- package/dist/aws-cdk/vpc.cjs +33 -0
- package/dist/aws-cdk/vpc.cjs.map +1 -0
- package/dist/aws-cdk/vpc.d.cts +34 -0
- package/dist/aws-cdk/vpc.d.ts +34 -0
- package/dist/aws-cdk/vpc.js +31 -0
- package/dist/aws-cdk/vpc.js.map +1 -0
- package/dist/aws-cdk.cjs +905 -0
- package/dist/aws-cdk.cjs.map +1 -0
- package/dist/aws-cdk.d.cts +34 -0
- package/dist/aws-cdk.d.ts +34 -0
- package/dist/aws-cdk.js +887 -0
- package/dist/aws-cdk.js.map +1 -0
- package/dist/aws-types.cjs +4 -0
- package/dist/aws-types.cjs.map +1 -0
- package/dist/aws-types.d.cts +42 -0
- package/dist/aws-types.d.ts +42 -0
- package/dist/aws-types.js +3 -0
- package/dist/aws-types.js.map +1 -0
- package/dist/aws.cjs +905 -0
- package/dist/aws.cjs.map +1 -0
- package/dist/aws.d.cts +34 -0
- package/dist/aws.d.ts +34 -0
- package/dist/aws.js +887 -0
- package/dist/aws.js.map +1 -0
- package/dist/index.cjs +43 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +34 -755
- package/dist/index.d.ts +34 -755
- package/dist/index.js +43 -19
- package/dist/index.js.map +1 -1
- package/package.json +181 -19
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Construct } from 'constructs';
|
|
2
|
+
import { Function } from 'aws-cdk-lib/aws-lambda';
|
|
3
|
+
import { TokenAuthorizer, TokenAuthorizerProps } from 'aws-cdk-lib/aws-apigateway';
|
|
4
|
+
import { IBaseCdkConstructProps } from '../aws-types.js';
|
|
5
|
+
import '@incloodsolutions/toolkit';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Props for BaseLambdaAuthoriserConstruct
|
|
9
|
+
*
|
|
10
|
+
* Provides configuration for:
|
|
11
|
+
* - Lambda token authorizer
|
|
12
|
+
* - Authorizer behaviour and settings
|
|
13
|
+
*/
|
|
14
|
+
interface ILambdaAuthoriserConstructProps extends Omit<IBaseCdkConstructProps<{
|
|
15
|
+
/** Token authorizer configuration options */
|
|
16
|
+
readonly authorizerOptions: TokenAuthorizerProps;
|
|
17
|
+
}>, 'appName' | 'stage' | 'stackName'> {
|
|
18
|
+
/**
|
|
19
|
+
* Lambda function used as the authorizer handler
|
|
20
|
+
*
|
|
21
|
+
* This function is invoked to validate incoming requests
|
|
22
|
+
*/
|
|
23
|
+
readonly handlerFunction: Function;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* CDK construct for Lambda Token Authorizer (API Gateway v1)
|
|
27
|
+
*
|
|
28
|
+
* Responsibilities:
|
|
29
|
+
* - Creates a Token Authorizer backed by a Lambda function
|
|
30
|
+
* - Applies optional configuration overrides
|
|
31
|
+
* - Exposes the authorizer ARN as a CloudFormation output
|
|
32
|
+
*/
|
|
33
|
+
declare class BaseLambdaAuthoriserConstruct extends Construct {
|
|
34
|
+
/** The created Token Authorizer instance */
|
|
35
|
+
readonly authoriser: TokenAuthorizer;
|
|
36
|
+
/**
|
|
37
|
+
* @param scope Parent construct
|
|
38
|
+
* @param id Unique construct identifier
|
|
39
|
+
* @param props Configuration for authorizer and handler function
|
|
40
|
+
*/
|
|
41
|
+
constructor(scope: Construct, id: string, props: ILambdaAuthoriserConstructProps);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export { BaseLambdaAuthoriserConstruct };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Construct } from 'constructs';
|
|
2
|
+
import { CfnOutput } from 'aws-cdk-lib';
|
|
3
|
+
import { TokenAuthorizer } from 'aws-cdk-lib/aws-apigateway';
|
|
4
|
+
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
+
var BaseLambdaAuthoriserConstruct = class extends Construct {
|
|
8
|
+
static {
|
|
9
|
+
__name(this, "BaseLambdaAuthoriserConstruct");
|
|
10
|
+
}
|
|
11
|
+
/** The created Token Authorizer instance */
|
|
12
|
+
authoriser;
|
|
13
|
+
/**
|
|
14
|
+
* @param scope Parent construct
|
|
15
|
+
* @param id Unique construct identifier
|
|
16
|
+
* @param props Configuration for authorizer and handler function
|
|
17
|
+
*/
|
|
18
|
+
constructor(scope, id, props) {
|
|
19
|
+
super(scope, id);
|
|
20
|
+
this.authoriser = new TokenAuthorizer(this, id, {
|
|
21
|
+
...props.options?.authorizerOptions,
|
|
22
|
+
/**
|
|
23
|
+
* Lambda handler responsible for request authorization
|
|
24
|
+
*/
|
|
25
|
+
handler: props.handlerFunction
|
|
26
|
+
});
|
|
27
|
+
new CfnOutput(this, "LambdaAuthorizerArn", {
|
|
28
|
+
value: this.authoriser.authorizerArn
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export { BaseLambdaAuthoriserConstruct };
|
|
34
|
+
//# sourceMappingURL=lambda-authorizer.js.map
|
|
35
|
+
//# sourceMappingURL=lambda-authorizer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/aws/cdk/constructs/lambda-authorizer-construct.ts"],"names":[],"mappings":";;;;;;AAwCO,IAAM,6BAAA,GAAN,cAA4C,SAAA,CAAU;AAAA,EAxC7D;AAwC6D,IAAA,MAAA,CAAA,IAAA,EAAA,+BAAA,CAAA;AAAA;AAAA;AAAA,EAEnD,UAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOT,WAAA,CACC,KAAA,EACA,EAAA,EACA,KAAA,EACC;AACD,IAAA,KAAA,CAAM,OAAO,EAAE,CAAA;AAEf,IAAA,IAAA,CAAK,UAAA,GAAa,IAAI,eAAA,CAAgB,IAAA,EAAM,EAAA,EAAI;AAAA,MAC/C,GAAG,MAAM,OAAA,EAAS,iBAAA;AAAA;AAAA;AAAA;AAAA,MAKlB,SAAS,KAAA,CAAM;AAAA,KACf,CAAA;AAKD,IAAA,IAAI,SAAA,CAAU,MAAM,qBAAA,EAAuB;AAAA,MAC1C,KAAA,EAAO,KAAK,UAAA,CAAW;AAAA,KACvB,CAAA;AAAA,EACF;AACD","file":"lambda-authorizer.js","sourcesContent":["import { Construct } from 'constructs';\nimport { CfnOutput } from 'aws-cdk-lib';\nimport { Function } from 'aws-cdk-lib/aws-lambda';\nimport {\n\tTokenAuthorizer,\n\tTokenAuthorizerProps,\n} from 'aws-cdk-lib/aws-apigateway';\n\nimport { IBaseCdkConstructProps } from '../../types';\n\n/**\n * Props for BaseLambdaAuthoriserConstruct\n *\n * Provides configuration for:\n * - Lambda token authorizer\n * - Authorizer behaviour and settings\n */\ninterface ILambdaAuthoriserConstructProps extends Omit<\n\tIBaseCdkConstructProps<{\n\t\t/** Token authorizer configuration options */\n\t\treadonly authorizerOptions: TokenAuthorizerProps;\n\t}>,\n\t'appName' | 'stage' | 'stackName'\n> {\n\t/**\n\t * Lambda function used as the authorizer handler\n\t *\n\t * This function is invoked to validate incoming requests\n\t */\n\treadonly handlerFunction: Function;\n}\n\n/**\n * CDK construct for Lambda Token Authorizer (API Gateway v1)\n *\n * Responsibilities:\n * - Creates a Token Authorizer backed by a Lambda function\n * - Applies optional configuration overrides\n * - Exposes the authorizer ARN as a CloudFormation output\n */\nexport class BaseLambdaAuthoriserConstruct extends Construct {\n\t/** The created Token Authorizer instance */\n\treadonly authoriser: TokenAuthorizer;\n\n\t/**\n\t * @param scope Parent construct\n\t * @param id Unique construct identifier\n\t * @param props Configuration for authorizer and handler function\n\t */\n\tconstructor(\n\t\tscope: Construct,\n\t\tid: string,\n\t\tprops: ILambdaAuthoriserConstructProps,\n\t) {\n\t\tsuper(scope, id);\n\n\t\tthis.authoriser = new TokenAuthorizer(this, id, {\n\t\t\t...props.options?.authorizerOptions,\n\n\t\t\t/**\n\t\t\t * Lambda handler responsible for request authorization\n\t\t\t */\n\t\t\thandler: props.handlerFunction,\n\t\t});\n\n\t\t/**\n\t\t * CloudFormation output exposing the authorizer ARN\n\t\t */\n\t\tnew CfnOutput(this, 'LambdaAuthorizerArn', {\n\t\t\tvalue: this.authoriser.authorizerArn,\n\t\t});\n\t}\n}\n"]}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var constructs = require('constructs');
|
|
4
|
+
var awsCdkLib = require('aws-cdk-lib');
|
|
5
|
+
var awsLambda = require('aws-cdk-lib/aws-lambda');
|
|
6
|
+
|
|
7
|
+
var __defProp = Object.defineProperty;
|
|
8
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
9
|
+
var BaseLambdaLayerConstruct = class extends constructs.Construct {
|
|
10
|
+
static {
|
|
11
|
+
__name(this, "BaseLambdaLayerConstruct");
|
|
12
|
+
}
|
|
13
|
+
/** Newly created Lambda Layer (null if importing existing layer) */
|
|
14
|
+
layer;
|
|
15
|
+
/** Imported Lambda Layer reference (null if creating new layer) */
|
|
16
|
+
existingLayer;
|
|
17
|
+
/**
|
|
18
|
+
* @param scope Parent construct
|
|
19
|
+
* @param id Unique construct identifier
|
|
20
|
+
* @param props Configuration for layer creation or import
|
|
21
|
+
*/
|
|
22
|
+
constructor(scope, id, props) {
|
|
23
|
+
super(scope, id);
|
|
24
|
+
if (props?.options?.fromExistingLayerArn) {
|
|
25
|
+
this.existingLayer = awsLambda.LayerVersion.fromLayerVersionArn(
|
|
26
|
+
this,
|
|
27
|
+
`${id}-Arn`,
|
|
28
|
+
props?.options?.fromExistingLayerArn
|
|
29
|
+
);
|
|
30
|
+
} else if (props?.options?.fromExistingLayerAttribute) {
|
|
31
|
+
this.existingLayer = awsLambda.LayerVersion.fromLayerVersionAttributes(
|
|
32
|
+
this,
|
|
33
|
+
`${id}-Attribute`,
|
|
34
|
+
props?.options?.fromExistingLayerAttribute
|
|
35
|
+
);
|
|
36
|
+
} else {
|
|
37
|
+
this.layer = new awsLambda.LayerVersion(this, id, {
|
|
38
|
+
...props.options?.layerOptions,
|
|
39
|
+
/**
|
|
40
|
+
* Default layer code asset
|
|
41
|
+
*/
|
|
42
|
+
code: props?.options?.layerOptions?.code || awsLambda.Code.fromAsset("./dist-layer"),
|
|
43
|
+
/**
|
|
44
|
+
* Layer description
|
|
45
|
+
*/
|
|
46
|
+
description: props?.options?.layerOptions?.description || "Lambda Layer written in NodeJS, NestJS, NodeJS-express, serverless-express",
|
|
47
|
+
/**
|
|
48
|
+
* Supported CPU architectures
|
|
49
|
+
*/
|
|
50
|
+
compatibleArchitectures: [awsLambda.Architecture.ARM_64, awsLambda.Architecture.X86_64],
|
|
51
|
+
/**
|
|
52
|
+
* Supported runtimes
|
|
53
|
+
*/
|
|
54
|
+
compatibleRuntimes: [
|
|
55
|
+
awsLambda.Runtime.NODEJS_22_X,
|
|
56
|
+
awsLambda.Runtime.NODEJS_24_X,
|
|
57
|
+
awsLambda.Runtime.NODEJS_LATEST
|
|
58
|
+
]
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
new awsCdkLib.CfnOutput(this, "LambdaLayerArn", {
|
|
62
|
+
value: props.options?.fromExistingLayerArn || props.options?.fromExistingLayerAttribute ? this.existingLayer.layerVersionArn : this.layer.layerVersionArn
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
exports.BaseLambdaLayerConstruct = BaseLambdaLayerConstruct;
|
|
68
|
+
//# sourceMappingURL=lambda-layer.cjs.map
|
|
69
|
+
//# sourceMappingURL=lambda-layer.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/aws/cdk/constructs/lambda-layer-construct.ts"],"names":["Construct","LayerVersion","Code","Architecture","Runtime","CfnOutput"],"mappings":";;;;;;;;AAsDO,IAAM,wBAAA,GAAN,cAAuCA,oBAAA,CAAU;AAAA,EAtDxD;AAsDwD,IAAA,MAAA,CAAA,IAAA,EAAA,0BAAA,CAAA;AAAA;AAAA;AAAA,EAE9C,KAAA;AAAA;AAAA,EAGA,aAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOT,WAAA,CACC,KAAA,EACA,EAAA,EACA,KAAA,EACC;AACD,IAAA,KAAA,CAAM,OAAO,EAAE,CAAA;AAKf,IAAA,IAAI,KAAA,EAAO,SAAS,oBAAA,EAAsB;AACzC,MAAA,IAAA,CAAK,gBAAgBC,sBAAA,CAAa,mBAAA;AAAA,QACjC,IAAA;AAAA,QACA,GAAG,EAAE,CAAA,IAAA,CAAA;AAAA,QACL,OAAO,OAAA,EAAS;AAAA,OACjB;AAAA,IAKD,CAAA,MAAA,IAAW,KAAA,EAAO,OAAA,EAAS,0BAAA,EAA4B;AACtD,MAAA,IAAA,CAAK,gBAAgBA,sBAAA,CAAa,0BAAA;AAAA,QACjC,IAAA;AAAA,QACA,GAAG,EAAE,CAAA,UAAA,CAAA;AAAA,QACL,OAAO,OAAA,EAAS;AAAA,OACjB;AAAA,IAKD,CAAA,MAAO;AACN,MAAA,IAAA,CAAK,KAAA,GAAQ,IAAIA,sBAAA,CAAa,IAAA,EAAM,EAAA,EAAI;AAAA,QACvC,GAAG,MAAM,OAAA,EAAS,YAAA;AAAA;AAAA;AAAA;AAAA,QAKlB,MACC,KAAA,EAAO,OAAA,EAAS,cAAc,IAAA,IAAQC,cAAA,CAAK,UAAU,cAAc,CAAA;AAAA;AAAA;AAAA;AAAA,QAKpE,WAAA,EACC,KAAA,EAAO,OAAA,EAAS,YAAA,EAAc,WAAA,IAC9B,4EAAA;AAAA;AAAA;AAAA;AAAA,QAKD,uBAAA,EAAyB,CAACC,sBAAA,CAAa,MAAA,EAAQA,uBAAa,MAAM,CAAA;AAAA;AAAA;AAAA;AAAA,QAKlE,kBAAA,EAAoB;AAAA,UACnBC,iBAAA,CAAQ,WAAA;AAAA,UACRA,iBAAA,CAAQ,WAAA;AAAA,UACRA,iBAAA,CAAQ;AAAA;AACT,OACqB,CAAA;AAAA,IACvB;AAMA,IAAA,IAAIC,mBAAA,CAAU,MAAM,gBAAA,EAAkB;AAAA,MACrC,KAAA,EACC,KAAA,CAAM,OAAA,EAAS,oBAAA,IACf,KAAA,CAAM,OAAA,EAAS,0BAAA,GACZ,IAAA,CAAK,aAAA,CAAc,eAAA,GACnB,IAAA,CAAK,KAAA,CAAM;AAAA,KACf,CAAA;AAAA,EACF;AACD","file":"lambda-layer.cjs","sourcesContent":["import { Construct } from 'constructs';\nimport { CfnOutput } from 'aws-cdk-lib';\nimport {\n\tArchitecture,\n\tCode,\n\tILayerVersion,\n\tLayerVersion,\n\tLayerVersionProps,\n\tRuntime,\n} from 'aws-cdk-lib/aws-lambda';\n\nimport { IBaseCdkConstructProps } from '../../types';\n\n/**\n * Props for BaseLambdaLayerConstruct\n *\n * Provides configuration for:\n * - Creating a new Lambda Layer\n * - Importing an existing layer by ARN or attributes\n */\ninterface ILambdaLayerConstructProps extends Omit<\n\tIBaseCdkConstructProps<{\n\t\t/**\n\t\t * Configuration for creating a new Lambda layer\n\t\t *\n\t\t * Note:\n\t\t * - `layerVersionName` is required\n\t\t * - `compatibleArchitectures` is managed internally\n\t\t */\n\t\treadonly layerOptions?: Partial<\n\t\t\tOmit<LayerVersionProps, 'layerVersionName' | 'compatibleArchitectures'>\n\t\t> &\n\t\t\tRequired<Pick<LayerVersionProps, 'layerVersionName'>>;\n\n\t\t/** Import an existing layer by ARN */\n\t\treadonly fromExistingLayerArn?: string;\n\n\t\t/** Import an existing layer using attributes */\n\t\treadonly fromExistingLayerAttribute?: {\n\t\t\treadonly layerVersionArn: string;\n\t\t\treadonly compatibleRuntimes?: Runtime[];\n\t\t};\n\t}>,\n\t'appName' | 'stage' | 'stackName'\n> {}\n\n/**\n * CDK construct for Lambda Layer\n *\n * Responsibilities:\n * - Creates a new Lambda layer or imports an existing one\n * - Applies default runtime and architecture compatibility\n * - Exposes the layer ARN as a CloudFormation output\n */\nexport class BaseLambdaLayerConstruct extends Construct {\n\t/** Newly created Lambda Layer (null if importing existing layer) */\n\treadonly layer: LayerVersion;\n\n\t/** Imported Lambda Layer reference (null if creating new layer) */\n\treadonly existingLayer: ILayerVersion;\n\n\t/**\n\t * @param scope Parent construct\n\t * @param id Unique construct identifier\n\t * @param props Configuration for layer creation or import\n\t */\n\tconstructor(\n\t\tscope: Construct,\n\t\tid: string,\n\t\tprops?: ILambdaLayerConstructProps,\n\t) {\n\t\tsuper(scope, id);\n\n\t\t/**\n\t\t * Import layer by ARN\n\t\t */\n\t\tif (props?.options?.fromExistingLayerArn) {\n\t\t\tthis.existingLayer = LayerVersion.fromLayerVersionArn(\n\t\t\t\tthis,\n\t\t\t\t`${id}-Arn`,\n\t\t\t\tprops?.options?.fromExistingLayerArn,\n\t\t\t);\n\n\t\t\t/**\n\t\t\t * Import layer using attributes\n\t\t\t */\n\t\t} else if (props?.options?.fromExistingLayerAttribute) {\n\t\t\tthis.existingLayer = LayerVersion.fromLayerVersionAttributes(\n\t\t\t\tthis,\n\t\t\t\t`${id}-Attribute`,\n\t\t\t\tprops?.options?.fromExistingLayerAttribute,\n\t\t\t);\n\n\t\t\t/**\n\t\t\t * Create new Lambda layer\n\t\t\t */\n\t\t} else {\n\t\t\tthis.layer = new LayerVersion(this, id, {\n\t\t\t\t...props.options?.layerOptions,\n\n\t\t\t\t/**\n\t\t\t\t * Default layer code asset\n\t\t\t\t */\n\t\t\t\tcode:\n\t\t\t\t\tprops?.options?.layerOptions?.code || Code.fromAsset('./dist-layer'),\n\n\t\t\t\t/**\n\t\t\t\t * Layer description\n\t\t\t\t */\n\t\t\t\tdescription:\n\t\t\t\t\tprops?.options?.layerOptions?.description ||\n\t\t\t\t\t'Lambda Layer written in NodeJS, NestJS, NodeJS-express, serverless-express',\n\n\t\t\t\t/**\n\t\t\t\t * Supported CPU architectures\n\t\t\t\t */\n\t\t\t\tcompatibleArchitectures: [Architecture.ARM_64, Architecture.X86_64],\n\n\t\t\t\t/**\n\t\t\t\t * Supported runtimes\n\t\t\t\t */\n\t\t\t\tcompatibleRuntimes: [\n\t\t\t\t\tRuntime.NODEJS_22_X,\n\t\t\t\t\tRuntime.NODEJS_24_X,\n\t\t\t\t\tRuntime.NODEJS_LATEST,\n\t\t\t\t],\n\t\t\t} as LayerVersionProps);\n\t\t}\n\n\t\t/**\n\t\t * CloudFormation output exposing the layer ARN\n\t\t * Resolves to either created or imported layer\n\t\t */\n\t\tnew CfnOutput(this, 'LambdaLayerArn', {\n\t\t\tvalue:\n\t\t\t\tprops.options?.fromExistingLayerArn ||\n\t\t\t\tprops.options?.fromExistingLayerAttribute\n\t\t\t\t\t? this.existingLayer.layerVersionArn\n\t\t\t\t\t: this.layer.layerVersionArn,\n\t\t});\n\t}\n}\n"]}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Construct } from 'constructs';
|
|
2
|
+
import { LayerVersion, ILayerVersion, LayerVersionProps, Runtime } from 'aws-cdk-lib/aws-lambda';
|
|
3
|
+
import { IBaseCdkConstructProps } from '../aws-types.cjs';
|
|
4
|
+
import '@incloodsolutions/toolkit';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Props for BaseLambdaLayerConstruct
|
|
8
|
+
*
|
|
9
|
+
* Provides configuration for:
|
|
10
|
+
* - Creating a new Lambda Layer
|
|
11
|
+
* - Importing an existing layer by ARN or attributes
|
|
12
|
+
*/
|
|
13
|
+
interface ILambdaLayerConstructProps extends Omit<IBaseCdkConstructProps<{
|
|
14
|
+
/**
|
|
15
|
+
* Configuration for creating a new Lambda layer
|
|
16
|
+
*
|
|
17
|
+
* Note:
|
|
18
|
+
* - `layerVersionName` is required
|
|
19
|
+
* - `compatibleArchitectures` is managed internally
|
|
20
|
+
*/
|
|
21
|
+
readonly layerOptions?: Partial<Omit<LayerVersionProps, 'layerVersionName' | 'compatibleArchitectures'>> & Required<Pick<LayerVersionProps, 'layerVersionName'>>;
|
|
22
|
+
/** Import an existing layer by ARN */
|
|
23
|
+
readonly fromExistingLayerArn?: string;
|
|
24
|
+
/** Import an existing layer using attributes */
|
|
25
|
+
readonly fromExistingLayerAttribute?: {
|
|
26
|
+
readonly layerVersionArn: string;
|
|
27
|
+
readonly compatibleRuntimes?: Runtime[];
|
|
28
|
+
};
|
|
29
|
+
}>, 'appName' | 'stage' | 'stackName'> {
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* CDK construct for Lambda Layer
|
|
33
|
+
*
|
|
34
|
+
* Responsibilities:
|
|
35
|
+
* - Creates a new Lambda layer or imports an existing one
|
|
36
|
+
* - Applies default runtime and architecture compatibility
|
|
37
|
+
* - Exposes the layer ARN as a CloudFormation output
|
|
38
|
+
*/
|
|
39
|
+
declare class BaseLambdaLayerConstruct extends Construct {
|
|
40
|
+
/** Newly created Lambda Layer (null if importing existing layer) */
|
|
41
|
+
readonly layer: LayerVersion;
|
|
42
|
+
/** Imported Lambda Layer reference (null if creating new layer) */
|
|
43
|
+
readonly existingLayer: ILayerVersion;
|
|
44
|
+
/**
|
|
45
|
+
* @param scope Parent construct
|
|
46
|
+
* @param id Unique construct identifier
|
|
47
|
+
* @param props Configuration for layer creation or import
|
|
48
|
+
*/
|
|
49
|
+
constructor(scope: Construct, id: string, props?: ILambdaLayerConstructProps);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export { BaseLambdaLayerConstruct };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Construct } from 'constructs';
|
|
2
|
+
import { LayerVersion, ILayerVersion, LayerVersionProps, Runtime } from 'aws-cdk-lib/aws-lambda';
|
|
3
|
+
import { IBaseCdkConstructProps } from '../aws-types.js';
|
|
4
|
+
import '@incloodsolutions/toolkit';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Props for BaseLambdaLayerConstruct
|
|
8
|
+
*
|
|
9
|
+
* Provides configuration for:
|
|
10
|
+
* - Creating a new Lambda Layer
|
|
11
|
+
* - Importing an existing layer by ARN or attributes
|
|
12
|
+
*/
|
|
13
|
+
interface ILambdaLayerConstructProps extends Omit<IBaseCdkConstructProps<{
|
|
14
|
+
/**
|
|
15
|
+
* Configuration for creating a new Lambda layer
|
|
16
|
+
*
|
|
17
|
+
* Note:
|
|
18
|
+
* - `layerVersionName` is required
|
|
19
|
+
* - `compatibleArchitectures` is managed internally
|
|
20
|
+
*/
|
|
21
|
+
readonly layerOptions?: Partial<Omit<LayerVersionProps, 'layerVersionName' | 'compatibleArchitectures'>> & Required<Pick<LayerVersionProps, 'layerVersionName'>>;
|
|
22
|
+
/** Import an existing layer by ARN */
|
|
23
|
+
readonly fromExistingLayerArn?: string;
|
|
24
|
+
/** Import an existing layer using attributes */
|
|
25
|
+
readonly fromExistingLayerAttribute?: {
|
|
26
|
+
readonly layerVersionArn: string;
|
|
27
|
+
readonly compatibleRuntimes?: Runtime[];
|
|
28
|
+
};
|
|
29
|
+
}>, 'appName' | 'stage' | 'stackName'> {
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* CDK construct for Lambda Layer
|
|
33
|
+
*
|
|
34
|
+
* Responsibilities:
|
|
35
|
+
* - Creates a new Lambda layer or imports an existing one
|
|
36
|
+
* - Applies default runtime and architecture compatibility
|
|
37
|
+
* - Exposes the layer ARN as a CloudFormation output
|
|
38
|
+
*/
|
|
39
|
+
declare class BaseLambdaLayerConstruct extends Construct {
|
|
40
|
+
/** Newly created Lambda Layer (null if importing existing layer) */
|
|
41
|
+
readonly layer: LayerVersion;
|
|
42
|
+
/** Imported Lambda Layer reference (null if creating new layer) */
|
|
43
|
+
readonly existingLayer: ILayerVersion;
|
|
44
|
+
/**
|
|
45
|
+
* @param scope Parent construct
|
|
46
|
+
* @param id Unique construct identifier
|
|
47
|
+
* @param props Configuration for layer creation or import
|
|
48
|
+
*/
|
|
49
|
+
constructor(scope: Construct, id: string, props?: ILambdaLayerConstructProps);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export { BaseLambdaLayerConstruct };
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { Construct } from 'constructs';
|
|
2
|
+
import { CfnOutput } from 'aws-cdk-lib';
|
|
3
|
+
import { LayerVersion, Runtime, Architecture, Code } from 'aws-cdk-lib/aws-lambda';
|
|
4
|
+
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
+
var BaseLambdaLayerConstruct = class extends Construct {
|
|
8
|
+
static {
|
|
9
|
+
__name(this, "BaseLambdaLayerConstruct");
|
|
10
|
+
}
|
|
11
|
+
/** Newly created Lambda Layer (null if importing existing layer) */
|
|
12
|
+
layer;
|
|
13
|
+
/** Imported Lambda Layer reference (null if creating new layer) */
|
|
14
|
+
existingLayer;
|
|
15
|
+
/**
|
|
16
|
+
* @param scope Parent construct
|
|
17
|
+
* @param id Unique construct identifier
|
|
18
|
+
* @param props Configuration for layer creation or import
|
|
19
|
+
*/
|
|
20
|
+
constructor(scope, id, props) {
|
|
21
|
+
super(scope, id);
|
|
22
|
+
if (props?.options?.fromExistingLayerArn) {
|
|
23
|
+
this.existingLayer = LayerVersion.fromLayerVersionArn(
|
|
24
|
+
this,
|
|
25
|
+
`${id}-Arn`,
|
|
26
|
+
props?.options?.fromExistingLayerArn
|
|
27
|
+
);
|
|
28
|
+
} else if (props?.options?.fromExistingLayerAttribute) {
|
|
29
|
+
this.existingLayer = LayerVersion.fromLayerVersionAttributes(
|
|
30
|
+
this,
|
|
31
|
+
`${id}-Attribute`,
|
|
32
|
+
props?.options?.fromExistingLayerAttribute
|
|
33
|
+
);
|
|
34
|
+
} else {
|
|
35
|
+
this.layer = new LayerVersion(this, id, {
|
|
36
|
+
...props.options?.layerOptions,
|
|
37
|
+
/**
|
|
38
|
+
* Default layer code asset
|
|
39
|
+
*/
|
|
40
|
+
code: props?.options?.layerOptions?.code || Code.fromAsset("./dist-layer"),
|
|
41
|
+
/**
|
|
42
|
+
* Layer description
|
|
43
|
+
*/
|
|
44
|
+
description: props?.options?.layerOptions?.description || "Lambda Layer written in NodeJS, NestJS, NodeJS-express, serverless-express",
|
|
45
|
+
/**
|
|
46
|
+
* Supported CPU architectures
|
|
47
|
+
*/
|
|
48
|
+
compatibleArchitectures: [Architecture.ARM_64, Architecture.X86_64],
|
|
49
|
+
/**
|
|
50
|
+
* Supported runtimes
|
|
51
|
+
*/
|
|
52
|
+
compatibleRuntimes: [
|
|
53
|
+
Runtime.NODEJS_22_X,
|
|
54
|
+
Runtime.NODEJS_24_X,
|
|
55
|
+
Runtime.NODEJS_LATEST
|
|
56
|
+
]
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
new CfnOutput(this, "LambdaLayerArn", {
|
|
60
|
+
value: props.options?.fromExistingLayerArn || props.options?.fromExistingLayerAttribute ? this.existingLayer.layerVersionArn : this.layer.layerVersionArn
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export { BaseLambdaLayerConstruct };
|
|
66
|
+
//# sourceMappingURL=lambda-layer.js.map
|
|
67
|
+
//# sourceMappingURL=lambda-layer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/aws/cdk/constructs/lambda-layer-construct.ts"],"names":[],"mappings":";;;;;;AAsDO,IAAM,wBAAA,GAAN,cAAuC,SAAA,CAAU;AAAA,EAtDxD;AAsDwD,IAAA,MAAA,CAAA,IAAA,EAAA,0BAAA,CAAA;AAAA;AAAA;AAAA,EAE9C,KAAA;AAAA;AAAA,EAGA,aAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOT,WAAA,CACC,KAAA,EACA,EAAA,EACA,KAAA,EACC;AACD,IAAA,KAAA,CAAM,OAAO,EAAE,CAAA;AAKf,IAAA,IAAI,KAAA,EAAO,SAAS,oBAAA,EAAsB;AACzC,MAAA,IAAA,CAAK,gBAAgB,YAAA,CAAa,mBAAA;AAAA,QACjC,IAAA;AAAA,QACA,GAAG,EAAE,CAAA,IAAA,CAAA;AAAA,QACL,OAAO,OAAA,EAAS;AAAA,OACjB;AAAA,IAKD,CAAA,MAAA,IAAW,KAAA,EAAO,OAAA,EAAS,0BAAA,EAA4B;AACtD,MAAA,IAAA,CAAK,gBAAgB,YAAA,CAAa,0BAAA;AAAA,QACjC,IAAA;AAAA,QACA,GAAG,EAAE,CAAA,UAAA,CAAA;AAAA,QACL,OAAO,OAAA,EAAS;AAAA,OACjB;AAAA,IAKD,CAAA,MAAO;AACN,MAAA,IAAA,CAAK,KAAA,GAAQ,IAAI,YAAA,CAAa,IAAA,EAAM,EAAA,EAAI;AAAA,QACvC,GAAG,MAAM,OAAA,EAAS,YAAA;AAAA;AAAA;AAAA;AAAA,QAKlB,MACC,KAAA,EAAO,OAAA,EAAS,cAAc,IAAA,IAAQ,IAAA,CAAK,UAAU,cAAc,CAAA;AAAA;AAAA;AAAA;AAAA,QAKpE,WAAA,EACC,KAAA,EAAO,OAAA,EAAS,YAAA,EAAc,WAAA,IAC9B,4EAAA;AAAA;AAAA;AAAA;AAAA,QAKD,uBAAA,EAAyB,CAAC,YAAA,CAAa,MAAA,EAAQ,aAAa,MAAM,CAAA;AAAA;AAAA;AAAA;AAAA,QAKlE,kBAAA,EAAoB;AAAA,UACnB,OAAA,CAAQ,WAAA;AAAA,UACR,OAAA,CAAQ,WAAA;AAAA,UACR,OAAA,CAAQ;AAAA;AACT,OACqB,CAAA;AAAA,IACvB;AAMA,IAAA,IAAI,SAAA,CAAU,MAAM,gBAAA,EAAkB;AAAA,MACrC,KAAA,EACC,KAAA,CAAM,OAAA,EAAS,oBAAA,IACf,KAAA,CAAM,OAAA,EAAS,0BAAA,GACZ,IAAA,CAAK,aAAA,CAAc,eAAA,GACnB,IAAA,CAAK,KAAA,CAAM;AAAA,KACf,CAAA;AAAA,EACF;AACD","file":"lambda-layer.js","sourcesContent":["import { Construct } from 'constructs';\nimport { CfnOutput } from 'aws-cdk-lib';\nimport {\n\tArchitecture,\n\tCode,\n\tILayerVersion,\n\tLayerVersion,\n\tLayerVersionProps,\n\tRuntime,\n} from 'aws-cdk-lib/aws-lambda';\n\nimport { IBaseCdkConstructProps } from '../../types';\n\n/**\n * Props for BaseLambdaLayerConstruct\n *\n * Provides configuration for:\n * - Creating a new Lambda Layer\n * - Importing an existing layer by ARN or attributes\n */\ninterface ILambdaLayerConstructProps extends Omit<\n\tIBaseCdkConstructProps<{\n\t\t/**\n\t\t * Configuration for creating a new Lambda layer\n\t\t *\n\t\t * Note:\n\t\t * - `layerVersionName` is required\n\t\t * - `compatibleArchitectures` is managed internally\n\t\t */\n\t\treadonly layerOptions?: Partial<\n\t\t\tOmit<LayerVersionProps, 'layerVersionName' | 'compatibleArchitectures'>\n\t\t> &\n\t\t\tRequired<Pick<LayerVersionProps, 'layerVersionName'>>;\n\n\t\t/** Import an existing layer by ARN */\n\t\treadonly fromExistingLayerArn?: string;\n\n\t\t/** Import an existing layer using attributes */\n\t\treadonly fromExistingLayerAttribute?: {\n\t\t\treadonly layerVersionArn: string;\n\t\t\treadonly compatibleRuntimes?: Runtime[];\n\t\t};\n\t}>,\n\t'appName' | 'stage' | 'stackName'\n> {}\n\n/**\n * CDK construct for Lambda Layer\n *\n * Responsibilities:\n * - Creates a new Lambda layer or imports an existing one\n * - Applies default runtime and architecture compatibility\n * - Exposes the layer ARN as a CloudFormation output\n */\nexport class BaseLambdaLayerConstruct extends Construct {\n\t/** Newly created Lambda Layer (null if importing existing layer) */\n\treadonly layer: LayerVersion;\n\n\t/** Imported Lambda Layer reference (null if creating new layer) */\n\treadonly existingLayer: ILayerVersion;\n\n\t/**\n\t * @param scope Parent construct\n\t * @param id Unique construct identifier\n\t * @param props Configuration for layer creation or import\n\t */\n\tconstructor(\n\t\tscope: Construct,\n\t\tid: string,\n\t\tprops?: ILambdaLayerConstructProps,\n\t) {\n\t\tsuper(scope, id);\n\n\t\t/**\n\t\t * Import layer by ARN\n\t\t */\n\t\tif (props?.options?.fromExistingLayerArn) {\n\t\t\tthis.existingLayer = LayerVersion.fromLayerVersionArn(\n\t\t\t\tthis,\n\t\t\t\t`${id}-Arn`,\n\t\t\t\tprops?.options?.fromExistingLayerArn,\n\t\t\t);\n\n\t\t\t/**\n\t\t\t * Import layer using attributes\n\t\t\t */\n\t\t} else if (props?.options?.fromExistingLayerAttribute) {\n\t\t\tthis.existingLayer = LayerVersion.fromLayerVersionAttributes(\n\t\t\t\tthis,\n\t\t\t\t`${id}-Attribute`,\n\t\t\t\tprops?.options?.fromExistingLayerAttribute,\n\t\t\t);\n\n\t\t\t/**\n\t\t\t * Create new Lambda layer\n\t\t\t */\n\t\t} else {\n\t\t\tthis.layer = new LayerVersion(this, id, {\n\t\t\t\t...props.options?.layerOptions,\n\n\t\t\t\t/**\n\t\t\t\t * Default layer code asset\n\t\t\t\t */\n\t\t\t\tcode:\n\t\t\t\t\tprops?.options?.layerOptions?.code || Code.fromAsset('./dist-layer'),\n\n\t\t\t\t/**\n\t\t\t\t * Layer description\n\t\t\t\t */\n\t\t\t\tdescription:\n\t\t\t\t\tprops?.options?.layerOptions?.description ||\n\t\t\t\t\t'Lambda Layer written in NodeJS, NestJS, NodeJS-express, serverless-express',\n\n\t\t\t\t/**\n\t\t\t\t * Supported CPU architectures\n\t\t\t\t */\n\t\t\t\tcompatibleArchitectures: [Architecture.ARM_64, Architecture.X86_64],\n\n\t\t\t\t/**\n\t\t\t\t * Supported runtimes\n\t\t\t\t */\n\t\t\t\tcompatibleRuntimes: [\n\t\t\t\t\tRuntime.NODEJS_22_X,\n\t\t\t\t\tRuntime.NODEJS_24_X,\n\t\t\t\t\tRuntime.NODEJS_LATEST,\n\t\t\t\t],\n\t\t\t} as LayerVersionProps);\n\t\t}\n\n\t\t/**\n\t\t * CloudFormation output exposing the layer ARN\n\t\t * Resolves to either created or imported layer\n\t\t */\n\t\tnew CfnOutput(this, 'LambdaLayerArn', {\n\t\t\tvalue:\n\t\t\t\tprops.options?.fromExistingLayerArn ||\n\t\t\t\tprops.options?.fromExistingLayerAttribute\n\t\t\t\t\t? this.existingLayer.layerVersionArn\n\t\t\t\t\t: this.layer.layerVersionArn,\n\t\t});\n\t}\n}\n"]}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var constructs = require('constructs');
|
|
4
|
+
var awsCdkLib = require('aws-cdk-lib');
|
|
5
|
+
var awsLambda = require('aws-cdk-lib/aws-lambda');
|
|
6
|
+
var toolkit = require('@incloodsolutions/toolkit');
|
|
7
|
+
|
|
8
|
+
var __defProp = Object.defineProperty;
|
|
9
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
10
|
+
var BaseLambdaConstruct = class extends constructs.Construct {
|
|
11
|
+
static {
|
|
12
|
+
__name(this, "BaseLambdaConstruct");
|
|
13
|
+
}
|
|
14
|
+
/** The created Lambda function instance */
|
|
15
|
+
function;
|
|
16
|
+
/**
|
|
17
|
+
* @param scope Parent construct
|
|
18
|
+
* @param id Unique construct identifier
|
|
19
|
+
* @param props Configuration for Lambda function
|
|
20
|
+
*/
|
|
21
|
+
constructor(scope, id, props) {
|
|
22
|
+
super(scope, id);
|
|
23
|
+
const environment = {
|
|
24
|
+
...props.options?.lambdaOptions?.environment,
|
|
25
|
+
NODE_ENV: props.stage,
|
|
26
|
+
NODE_OPTIONS: "--enable-source-maps",
|
|
27
|
+
AWS_NODEJS_CONNECTION_REUSE_ENABLED: "1"
|
|
28
|
+
};
|
|
29
|
+
toolkit.detectDuplicateProperties({ data: environment });
|
|
30
|
+
this.function = new awsLambda.Function(this, id, {
|
|
31
|
+
...props?.options?.lambdaOptions,
|
|
32
|
+
/**
|
|
33
|
+
* Lambda function name
|
|
34
|
+
* Defaults to "<stackName>-handler" if not provided
|
|
35
|
+
*/
|
|
36
|
+
functionName: `${props?.options?.lambdaOptions?.functionName || props?.stackName}-handler`,
|
|
37
|
+
/**
|
|
38
|
+
* Function description
|
|
39
|
+
*/
|
|
40
|
+
description: props?.options?.lambdaOptions?.description || "A lambda function",
|
|
41
|
+
/**
|
|
42
|
+
* Entry handler for the Lambda function
|
|
43
|
+
*/
|
|
44
|
+
handler: props?.options?.lambdaOptions?.handler || "lambda.handler",
|
|
45
|
+
/**
|
|
46
|
+
* Runtime environment
|
|
47
|
+
*/
|
|
48
|
+
runtime: props?.options?.lambdaOptions?.runtime || awsLambda.Runtime.NODEJS_24_X,
|
|
49
|
+
/**
|
|
50
|
+
* Execution timeout
|
|
51
|
+
* - 30 seconds in production
|
|
52
|
+
* - 15 seconds otherwise
|
|
53
|
+
*/
|
|
54
|
+
timeout: props?.options?.lambdaOptions?.timeout || awsCdkLib.Duration.seconds(
|
|
55
|
+
props.stage === toolkit.AppEnvironmentEnum.PRODUCTION ? 30 : 15
|
|
56
|
+
),
|
|
57
|
+
/**
|
|
58
|
+
* Memory allocation (in MB)
|
|
59
|
+
*/
|
|
60
|
+
memorySize: props?.options?.lambdaOptions?.memorySize || 1024,
|
|
61
|
+
/**
|
|
62
|
+
* CPU architecture
|
|
63
|
+
*/
|
|
64
|
+
architecture: props?.options?.lambdaOptions?.architecture || awsLambda.Architecture.ARM_64,
|
|
65
|
+
/**
|
|
66
|
+
* Lambda deployment package source
|
|
67
|
+
*/
|
|
68
|
+
code: props?.options?.lambdaOptions?.code || awsLambda.Code.fromAsset("dist"),
|
|
69
|
+
/**
|
|
70
|
+
* Final merged environment variables
|
|
71
|
+
*/
|
|
72
|
+
environment
|
|
73
|
+
});
|
|
74
|
+
new awsCdkLib.CfnOutput(this, "LambdaFunctionArn", {
|
|
75
|
+
value: this.function.functionArn
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
exports.BaseLambdaConstruct = BaseLambdaConstruct;
|
|
81
|
+
//# sourceMappingURL=lambda.cjs.map
|
|
82
|
+
//# sourceMappingURL=lambda.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/aws/cdk/constructs/lambda-construct.ts"],"names":["Construct","detectDuplicateProperties","Function","Runtime","Duration","AppEnvironmentEnum","Architecture","Code","CfnOutput"],"mappings":";;;;;;;;;AAwCO,IAAM,mBAAA,GAAN,cAAkCA,oBAAA,CAAU;AAAA,EAxCnD;AAwCmD,IAAA,MAAA,CAAA,IAAA,EAAA,qBAAA,CAAA;AAAA;AAAA;AAAA,EAEzC,QAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOT,WAAA,CAAY,KAAA,EAAkB,EAAA,EAAY,KAAA,EAA8B;AACvE,IAAA,KAAA,CAAM,OAAO,EAAE,CAAA;AAUf,IAAA,MAAM,WAAA,GAAc;AAAA,MACnB,GAAG,KAAA,CAAM,OAAA,EAAS,aAAA,EAAe,WAAA;AAAA,MACjC,UAAU,KAAA,CAAM,KAAA;AAAA,MAChB,YAAA,EAAc,sBAAA;AAAA,MACd,mCAAA,EAAqC;AAAA,KACtC;AAKA,IAAAC,iCAAA,CAA0B,EAAE,IAAA,EAAM,WAAA,EAAa,CAAA;AAE/C,IAAA,IAAA,CAAK,QAAA,GAAW,IAAIC,kBAAA,CAAS,IAAA,EAAM,EAAA,EAAI;AAAA,MACtC,GAAG,OAAO,OAAA,EAAS,aAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAMnB,cAAc,CAAA,EAAG,KAAA,EAAO,SAAS,aAAA,EAAe,YAAA,IAAgB,OAAO,SAAS,CAAA,QAAA,CAAA;AAAA;AAAA;AAAA;AAAA,MAKhF,WAAA,EACC,KAAA,EAAO,OAAA,EAAS,aAAA,EAAe,WAAA,IAAe,mBAAA;AAAA;AAAA;AAAA;AAAA,MAK/C,OAAA,EAAS,KAAA,EAAO,OAAA,EAAS,aAAA,EAAe,OAAA,IAAW,gBAAA;AAAA;AAAA;AAAA;AAAA,MAKnD,OAAA,EAAS,KAAA,EAAO,OAAA,EAAS,aAAA,EAAe,WAAWC,iBAAA,CAAQ,WAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAO3D,OAAA,EACC,KAAA,EAAO,OAAA,EAAS,aAAA,EAAe,WAC/BC,kBAAA,CAAS,OAAA;AAAA,QACR,KAAA,CAAM,KAAA,KAAUC,0BAAA,CAAmB,UAAA,GAAa,EAAA,GAAK;AAAA,OACtD;AAAA;AAAA;AAAA;AAAA,MAKD,UAAA,EAAY,KAAA,EAAO,OAAA,EAAS,aAAA,EAAe,UAAA,IAAc,IAAA;AAAA;AAAA;AAAA;AAAA,MAKzD,YAAA,EACC,KAAA,EAAO,OAAA,EAAS,aAAA,EAAe,gBAAgBC,sBAAA,CAAa,MAAA;AAAA;AAAA;AAAA;AAAA,MAK7D,MAAM,KAAA,EAAO,OAAA,EAAS,eAAe,IAAA,IAAQC,cAAA,CAAK,UAAU,MAAM,CAAA;AAAA;AAAA;AAAA;AAAA,MAKlE;AAAA,KACA,CAAA;AAKD,IAAA,IAAIC,mBAAA,CAAU,MAAM,mBAAA,EAAqB;AAAA,MACxC,KAAA,EAAO,KAAK,QAAA,CAAS;AAAA,KACrB,CAAA;AAAA,EACF;AACD","file":"lambda.cjs","sourcesContent":["import { Construct } from 'constructs';\nimport { CfnOutput, Duration } from 'aws-cdk-lib';\nimport {\n\tArchitecture,\n\tCode,\n\tFunction,\n\tFunctionProps,\n\tRuntime,\n} from 'aws-cdk-lib/aws-lambda';\n\nimport {\n\tdetectDuplicateProperties,\n\tAppEnvironmentEnum,\n} from '@incloodsolutions/toolkit';\n\nimport { IBaseCdkConstructProps } from '../../types';\n\n/**\n * Props for BaseLambdaConstruct\n *\n * Provides configuration for creating a Lambda function\n * with optional overrides for runtime, memory, timeout, and environment.\n */\ninterface ILambdaConstructProps extends Omit<\n\tIBaseCdkConstructProps<{\n\t\t/** Partial Lambda configuration options */\n\t\treadonly lambdaOptions: Partial<FunctionProps>;\n\t}>,\n\t'appName'\n> {}\n\n/**\n * CDK construct for AWS Lambda function\n *\n * Responsibilities:\n * - Creates a Lambda function with sensible defaults\n * - Merges and validates environment variables\n * - Applies stage-based configuration (e.g. timeout)\n * - Exposes the function ARN as a CloudFormation output\n */\nexport class BaseLambdaConstruct extends Construct {\n\t/** The created Lambda function instance */\n\treadonly function: Function;\n\n\t/**\n\t * @param scope Parent construct\n\t * @param id Unique construct identifier\n\t * @param props Configuration for Lambda function\n\t */\n\tconstructor(scope: Construct, id: string, props: ILambdaConstructProps) {\n\t\tsuper(scope, id);\n\n\t\t/**\n\t\t * Environment variables for the Lambda function\n\t\t *\n\t\t * Includes:\n\t\t * - User-defined variables\n\t\t * - NODE_ENV derived from stage\n\t\t * - Node.js runtime optimisations\n\t\t */\n\t\tconst environment = {\n\t\t\t...props.options?.lambdaOptions?.environment,\n\t\t\tNODE_ENV: props.stage,\n\t\t\tNODE_OPTIONS: '--enable-source-maps',\n\t\t\tAWS_NODEJS_CONNECTION_REUSE_ENABLED: '1',\n\t\t};\n\n\t\t/**\n\t\t * Validate environment variables for duplicate keys\n\t\t */\n\t\tdetectDuplicateProperties({ data: environment });\n\n\t\tthis.function = new Function(this, id, {\n\t\t\t...props?.options?.lambdaOptions,\n\n\t\t\t/**\n\t\t\t * Lambda function name\n\t\t\t * Defaults to \"<stackName>-handler\" if not provided\n\t\t\t */\n\t\t\tfunctionName: `${props?.options?.lambdaOptions?.functionName || props?.stackName}-handler`,\n\n\t\t\t/**\n\t\t\t * Function description\n\t\t\t */\n\t\t\tdescription:\n\t\t\t\tprops?.options?.lambdaOptions?.description || 'A lambda function',\n\n\t\t\t/**\n\t\t\t * Entry handler for the Lambda function\n\t\t\t */\n\t\t\thandler: props?.options?.lambdaOptions?.handler || 'lambda.handler',\n\n\t\t\t/**\n\t\t\t * Runtime environment\n\t\t\t */\n\t\t\truntime: props?.options?.lambdaOptions?.runtime || Runtime.NODEJS_24_X,\n\n\t\t\t/**\n\t\t\t * Execution timeout\n\t\t\t * - 30 seconds in production\n\t\t\t * - 15 seconds otherwise\n\t\t\t */\n\t\t\ttimeout:\n\t\t\t\tprops?.options?.lambdaOptions?.timeout ||\n\t\t\t\tDuration.seconds(\n\t\t\t\t\tprops.stage === AppEnvironmentEnum.PRODUCTION ? 30 : 15,\n\t\t\t\t),\n\n\t\t\t/**\n\t\t\t * Memory allocation (in MB)\n\t\t\t */\n\t\t\tmemorySize: props?.options?.lambdaOptions?.memorySize || 1024,\n\n\t\t\t/**\n\t\t\t * CPU architecture\n\t\t\t */\n\t\t\tarchitecture:\n\t\t\t\tprops?.options?.lambdaOptions?.architecture || Architecture.ARM_64,\n\n\t\t\t/**\n\t\t\t * Lambda deployment package source\n\t\t\t */\n\t\t\tcode: props?.options?.lambdaOptions?.code || Code.fromAsset('dist'),\n\n\t\t\t/**\n\t\t\t * Final merged environment variables\n\t\t\t */\n\t\t\tenvironment,\n\t\t});\n\n\t\t/**\n\t\t * CloudFormation output exposing the Lambda function ARN\n\t\t */\n\t\tnew CfnOutput(this, 'LambdaFunctionArn', {\n\t\t\tvalue: this.function.functionArn,\n\t\t});\n\t}\n}\n"]}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Construct } from 'constructs';
|
|
2
|
+
import { Function, FunctionProps } from 'aws-cdk-lib/aws-lambda';
|
|
3
|
+
import { IBaseCdkConstructProps } from '../aws-types.cjs';
|
|
4
|
+
import '@incloodsolutions/toolkit';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Props for BaseLambdaConstruct
|
|
8
|
+
*
|
|
9
|
+
* Provides configuration for creating a Lambda function
|
|
10
|
+
* with optional overrides for runtime, memory, timeout, and environment.
|
|
11
|
+
*/
|
|
12
|
+
interface ILambdaConstructProps extends Omit<IBaseCdkConstructProps<{
|
|
13
|
+
/** Partial Lambda configuration options */
|
|
14
|
+
readonly lambdaOptions: Partial<FunctionProps>;
|
|
15
|
+
}>, 'appName'> {
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* CDK construct for AWS Lambda function
|
|
19
|
+
*
|
|
20
|
+
* Responsibilities:
|
|
21
|
+
* - Creates a Lambda function with sensible defaults
|
|
22
|
+
* - Merges and validates environment variables
|
|
23
|
+
* - Applies stage-based configuration (e.g. timeout)
|
|
24
|
+
* - Exposes the function ARN as a CloudFormation output
|
|
25
|
+
*/
|
|
26
|
+
declare class BaseLambdaConstruct extends Construct {
|
|
27
|
+
/** The created Lambda function instance */
|
|
28
|
+
readonly function: Function;
|
|
29
|
+
/**
|
|
30
|
+
* @param scope Parent construct
|
|
31
|
+
* @param id Unique construct identifier
|
|
32
|
+
* @param props Configuration for Lambda function
|
|
33
|
+
*/
|
|
34
|
+
constructor(scope: Construct, id: string, props: ILambdaConstructProps);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export { BaseLambdaConstruct };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Construct } from 'constructs';
|
|
2
|
+
import { Function, FunctionProps } from 'aws-cdk-lib/aws-lambda';
|
|
3
|
+
import { IBaseCdkConstructProps } from '../aws-types.js';
|
|
4
|
+
import '@incloodsolutions/toolkit';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Props for BaseLambdaConstruct
|
|
8
|
+
*
|
|
9
|
+
* Provides configuration for creating a Lambda function
|
|
10
|
+
* with optional overrides for runtime, memory, timeout, and environment.
|
|
11
|
+
*/
|
|
12
|
+
interface ILambdaConstructProps extends Omit<IBaseCdkConstructProps<{
|
|
13
|
+
/** Partial Lambda configuration options */
|
|
14
|
+
readonly lambdaOptions: Partial<FunctionProps>;
|
|
15
|
+
}>, 'appName'> {
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* CDK construct for AWS Lambda function
|
|
19
|
+
*
|
|
20
|
+
* Responsibilities:
|
|
21
|
+
* - Creates a Lambda function with sensible defaults
|
|
22
|
+
* - Merges and validates environment variables
|
|
23
|
+
* - Applies stage-based configuration (e.g. timeout)
|
|
24
|
+
* - Exposes the function ARN as a CloudFormation output
|
|
25
|
+
*/
|
|
26
|
+
declare class BaseLambdaConstruct extends Construct {
|
|
27
|
+
/** The created Lambda function instance */
|
|
28
|
+
readonly function: Function;
|
|
29
|
+
/**
|
|
30
|
+
* @param scope Parent construct
|
|
31
|
+
* @param id Unique construct identifier
|
|
32
|
+
* @param props Configuration for Lambda function
|
|
33
|
+
*/
|
|
34
|
+
constructor(scope: Construct, id: string, props: ILambdaConstructProps);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export { BaseLambdaConstruct };
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { Construct } from 'constructs';
|
|
2
|
+
import { Duration, CfnOutput } from 'aws-cdk-lib';
|
|
3
|
+
import { Function, Architecture, Runtime, Code } from 'aws-cdk-lib/aws-lambda';
|
|
4
|
+
import { detectDuplicateProperties, AppEnvironmentEnum } from '@incloodsolutions/toolkit';
|
|
5
|
+
|
|
6
|
+
var __defProp = Object.defineProperty;
|
|
7
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
|
+
var BaseLambdaConstruct = class extends Construct {
|
|
9
|
+
static {
|
|
10
|
+
__name(this, "BaseLambdaConstruct");
|
|
11
|
+
}
|
|
12
|
+
/** The created Lambda function instance */
|
|
13
|
+
function;
|
|
14
|
+
/**
|
|
15
|
+
* @param scope Parent construct
|
|
16
|
+
* @param id Unique construct identifier
|
|
17
|
+
* @param props Configuration for Lambda function
|
|
18
|
+
*/
|
|
19
|
+
constructor(scope, id, props) {
|
|
20
|
+
super(scope, id);
|
|
21
|
+
const environment = {
|
|
22
|
+
...props.options?.lambdaOptions?.environment,
|
|
23
|
+
NODE_ENV: props.stage,
|
|
24
|
+
NODE_OPTIONS: "--enable-source-maps",
|
|
25
|
+
AWS_NODEJS_CONNECTION_REUSE_ENABLED: "1"
|
|
26
|
+
};
|
|
27
|
+
detectDuplicateProperties({ data: environment });
|
|
28
|
+
this.function = new Function(this, id, {
|
|
29
|
+
...props?.options?.lambdaOptions,
|
|
30
|
+
/**
|
|
31
|
+
* Lambda function name
|
|
32
|
+
* Defaults to "<stackName>-handler" if not provided
|
|
33
|
+
*/
|
|
34
|
+
functionName: `${props?.options?.lambdaOptions?.functionName || props?.stackName}-handler`,
|
|
35
|
+
/**
|
|
36
|
+
* Function description
|
|
37
|
+
*/
|
|
38
|
+
description: props?.options?.lambdaOptions?.description || "A lambda function",
|
|
39
|
+
/**
|
|
40
|
+
* Entry handler for the Lambda function
|
|
41
|
+
*/
|
|
42
|
+
handler: props?.options?.lambdaOptions?.handler || "lambda.handler",
|
|
43
|
+
/**
|
|
44
|
+
* Runtime environment
|
|
45
|
+
*/
|
|
46
|
+
runtime: props?.options?.lambdaOptions?.runtime || Runtime.NODEJS_24_X,
|
|
47
|
+
/**
|
|
48
|
+
* Execution timeout
|
|
49
|
+
* - 30 seconds in production
|
|
50
|
+
* - 15 seconds otherwise
|
|
51
|
+
*/
|
|
52
|
+
timeout: props?.options?.lambdaOptions?.timeout || Duration.seconds(
|
|
53
|
+
props.stage === AppEnvironmentEnum.PRODUCTION ? 30 : 15
|
|
54
|
+
),
|
|
55
|
+
/**
|
|
56
|
+
* Memory allocation (in MB)
|
|
57
|
+
*/
|
|
58
|
+
memorySize: props?.options?.lambdaOptions?.memorySize || 1024,
|
|
59
|
+
/**
|
|
60
|
+
* CPU architecture
|
|
61
|
+
*/
|
|
62
|
+
architecture: props?.options?.lambdaOptions?.architecture || Architecture.ARM_64,
|
|
63
|
+
/**
|
|
64
|
+
* Lambda deployment package source
|
|
65
|
+
*/
|
|
66
|
+
code: props?.options?.lambdaOptions?.code || Code.fromAsset("dist"),
|
|
67
|
+
/**
|
|
68
|
+
* Final merged environment variables
|
|
69
|
+
*/
|
|
70
|
+
environment
|
|
71
|
+
});
|
|
72
|
+
new CfnOutput(this, "LambdaFunctionArn", {
|
|
73
|
+
value: this.function.functionArn
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
export { BaseLambdaConstruct };
|
|
79
|
+
//# sourceMappingURL=lambda.js.map
|
|
80
|
+
//# sourceMappingURL=lambda.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/aws/cdk/constructs/lambda-construct.ts"],"names":[],"mappings":";;;;;;;AAwCO,IAAM,mBAAA,GAAN,cAAkC,SAAA,CAAU;AAAA,EAxCnD;AAwCmD,IAAA,MAAA,CAAA,IAAA,EAAA,qBAAA,CAAA;AAAA;AAAA;AAAA,EAEzC,QAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOT,WAAA,CAAY,KAAA,EAAkB,EAAA,EAAY,KAAA,EAA8B;AACvE,IAAA,KAAA,CAAM,OAAO,EAAE,CAAA;AAUf,IAAA,MAAM,WAAA,GAAc;AAAA,MACnB,GAAG,KAAA,CAAM,OAAA,EAAS,aAAA,EAAe,WAAA;AAAA,MACjC,UAAU,KAAA,CAAM,KAAA;AAAA,MAChB,YAAA,EAAc,sBAAA;AAAA,MACd,mCAAA,EAAqC;AAAA,KACtC;AAKA,IAAA,yBAAA,CAA0B,EAAE,IAAA,EAAM,WAAA,EAAa,CAAA;AAE/C,IAAA,IAAA,CAAK,QAAA,GAAW,IAAI,QAAA,CAAS,IAAA,EAAM,EAAA,EAAI;AAAA,MACtC,GAAG,OAAO,OAAA,EAAS,aAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAMnB,cAAc,CAAA,EAAG,KAAA,EAAO,SAAS,aAAA,EAAe,YAAA,IAAgB,OAAO,SAAS,CAAA,QAAA,CAAA;AAAA;AAAA;AAAA;AAAA,MAKhF,WAAA,EACC,KAAA,EAAO,OAAA,EAAS,aAAA,EAAe,WAAA,IAAe,mBAAA;AAAA;AAAA;AAAA;AAAA,MAK/C,OAAA,EAAS,KAAA,EAAO,OAAA,EAAS,aAAA,EAAe,OAAA,IAAW,gBAAA;AAAA;AAAA;AAAA;AAAA,MAKnD,OAAA,EAAS,KAAA,EAAO,OAAA,EAAS,aAAA,EAAe,WAAW,OAAA,CAAQ,WAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAO3D,OAAA,EACC,KAAA,EAAO,OAAA,EAAS,aAAA,EAAe,WAC/B,QAAA,CAAS,OAAA;AAAA,QACR,KAAA,CAAM,KAAA,KAAU,kBAAA,CAAmB,UAAA,GAAa,EAAA,GAAK;AAAA,OACtD;AAAA;AAAA;AAAA;AAAA,MAKD,UAAA,EAAY,KAAA,EAAO,OAAA,EAAS,aAAA,EAAe,UAAA,IAAc,IAAA;AAAA;AAAA;AAAA;AAAA,MAKzD,YAAA,EACC,KAAA,EAAO,OAAA,EAAS,aAAA,EAAe,gBAAgB,YAAA,CAAa,MAAA;AAAA;AAAA;AAAA;AAAA,MAK7D,MAAM,KAAA,EAAO,OAAA,EAAS,eAAe,IAAA,IAAQ,IAAA,CAAK,UAAU,MAAM,CAAA;AAAA;AAAA;AAAA;AAAA,MAKlE;AAAA,KACA,CAAA;AAKD,IAAA,IAAI,SAAA,CAAU,MAAM,mBAAA,EAAqB;AAAA,MACxC,KAAA,EAAO,KAAK,QAAA,CAAS;AAAA,KACrB,CAAA;AAAA,EACF;AACD","file":"lambda.js","sourcesContent":["import { Construct } from 'constructs';\nimport { CfnOutput, Duration } from 'aws-cdk-lib';\nimport {\n\tArchitecture,\n\tCode,\n\tFunction,\n\tFunctionProps,\n\tRuntime,\n} from 'aws-cdk-lib/aws-lambda';\n\nimport {\n\tdetectDuplicateProperties,\n\tAppEnvironmentEnum,\n} from '@incloodsolutions/toolkit';\n\nimport { IBaseCdkConstructProps } from '../../types';\n\n/**\n * Props for BaseLambdaConstruct\n *\n * Provides configuration for creating a Lambda function\n * with optional overrides for runtime, memory, timeout, and environment.\n */\ninterface ILambdaConstructProps extends Omit<\n\tIBaseCdkConstructProps<{\n\t\t/** Partial Lambda configuration options */\n\t\treadonly lambdaOptions: Partial<FunctionProps>;\n\t}>,\n\t'appName'\n> {}\n\n/**\n * CDK construct for AWS Lambda function\n *\n * Responsibilities:\n * - Creates a Lambda function with sensible defaults\n * - Merges and validates environment variables\n * - Applies stage-based configuration (e.g. timeout)\n * - Exposes the function ARN as a CloudFormation output\n */\nexport class BaseLambdaConstruct extends Construct {\n\t/** The created Lambda function instance */\n\treadonly function: Function;\n\n\t/**\n\t * @param scope Parent construct\n\t * @param id Unique construct identifier\n\t * @param props Configuration for Lambda function\n\t */\n\tconstructor(scope: Construct, id: string, props: ILambdaConstructProps) {\n\t\tsuper(scope, id);\n\n\t\t/**\n\t\t * Environment variables for the Lambda function\n\t\t *\n\t\t * Includes:\n\t\t * - User-defined variables\n\t\t * - NODE_ENV derived from stage\n\t\t * - Node.js runtime optimisations\n\t\t */\n\t\tconst environment = {\n\t\t\t...props.options?.lambdaOptions?.environment,\n\t\t\tNODE_ENV: props.stage,\n\t\t\tNODE_OPTIONS: '--enable-source-maps',\n\t\t\tAWS_NODEJS_CONNECTION_REUSE_ENABLED: '1',\n\t\t};\n\n\t\t/**\n\t\t * Validate environment variables for duplicate keys\n\t\t */\n\t\tdetectDuplicateProperties({ data: environment });\n\n\t\tthis.function = new Function(this, id, {\n\t\t\t...props?.options?.lambdaOptions,\n\n\t\t\t/**\n\t\t\t * Lambda function name\n\t\t\t * Defaults to \"<stackName>-handler\" if not provided\n\t\t\t */\n\t\t\tfunctionName: `${props?.options?.lambdaOptions?.functionName || props?.stackName}-handler`,\n\n\t\t\t/**\n\t\t\t * Function description\n\t\t\t */\n\t\t\tdescription:\n\t\t\t\tprops?.options?.lambdaOptions?.description || 'A lambda function',\n\n\t\t\t/**\n\t\t\t * Entry handler for the Lambda function\n\t\t\t */\n\t\t\thandler: props?.options?.lambdaOptions?.handler || 'lambda.handler',\n\n\t\t\t/**\n\t\t\t * Runtime environment\n\t\t\t */\n\t\t\truntime: props?.options?.lambdaOptions?.runtime || Runtime.NODEJS_24_X,\n\n\t\t\t/**\n\t\t\t * Execution timeout\n\t\t\t * - 30 seconds in production\n\t\t\t * - 15 seconds otherwise\n\t\t\t */\n\t\t\ttimeout:\n\t\t\t\tprops?.options?.lambdaOptions?.timeout ||\n\t\t\t\tDuration.seconds(\n\t\t\t\t\tprops.stage === AppEnvironmentEnum.PRODUCTION ? 30 : 15,\n\t\t\t\t),\n\n\t\t\t/**\n\t\t\t * Memory allocation (in MB)\n\t\t\t */\n\t\t\tmemorySize: props?.options?.lambdaOptions?.memorySize || 1024,\n\n\t\t\t/**\n\t\t\t * CPU architecture\n\t\t\t */\n\t\t\tarchitecture:\n\t\t\t\tprops?.options?.lambdaOptions?.architecture || Architecture.ARM_64,\n\n\t\t\t/**\n\t\t\t * Lambda deployment package source\n\t\t\t */\n\t\t\tcode: props?.options?.lambdaOptions?.code || Code.fromAsset('dist'),\n\n\t\t\t/**\n\t\t\t * Final merged environment variables\n\t\t\t */\n\t\t\tenvironment,\n\t\t});\n\n\t\t/**\n\t\t * CloudFormation output exposing the Lambda function ARN\n\t\t */\n\t\tnew CfnOutput(this, 'LambdaFunctionArn', {\n\t\t\tvalue: this.function.functionArn,\n\t\t});\n\t}\n}\n"]}
|