@incloodsolutions/devkit 0.0.2 → 0.0.3
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/aws/cdk/constructs/api-gateway-construct.cjs +95 -0
- package/dist/aws/cdk/constructs/api-gateway-construct.cjs.map +1 -0
- package/dist/aws/cdk/constructs/api-gateway-construct.d.cts +80 -0
- package/dist/aws/cdk/constructs/api-gateway-construct.d.ts +80 -0
- package/dist/aws/cdk/constructs/api-gateway-construct.js +93 -0
- package/dist/aws/cdk/constructs/api-gateway-construct.js.map +1 -0
- package/dist/aws/cdk/constructs/api-gateway-v2-construct.cjs +77 -0
- package/dist/aws/cdk/constructs/api-gateway-v2-construct.cjs.map +1 -0
- package/dist/aws/cdk/constructs/api-gateway-v2-construct.d.cts +55 -0
- package/dist/aws/cdk/constructs/api-gateway-v2-construct.d.ts +55 -0
- package/dist/aws/cdk/constructs/api-gateway-v2-construct.js +75 -0
- package/dist/aws/cdk/constructs/api-gateway-v2-construct.js.map +1 -0
- package/dist/aws/cdk/constructs/api-gateway-websocket-construct.cjs +65 -0
- package/dist/aws/cdk/constructs/api-gateway-websocket-construct.cjs.map +1 -0
- package/dist/aws/cdk/constructs/api-gateway-websocket-construct.d.cts +73 -0
- package/dist/aws/cdk/constructs/api-gateway-websocket-construct.d.ts +73 -0
- package/dist/aws/cdk/constructs/api-gateway-websocket-construct.js +63 -0
- package/dist/aws/cdk/constructs/api-gateway-websocket-construct.js.map +1 -0
- package/dist/aws/cdk/constructs/cloudfront-construct.cjs +68 -0
- package/dist/aws/cdk/constructs/cloudfront-construct.cjs.map +1 -0
- package/dist/aws/cdk/constructs/cloudfront-construct.d.cts +36 -0
- package/dist/aws/cdk/constructs/cloudfront-construct.d.ts +36 -0
- package/dist/aws/cdk/constructs/cloudfront-construct.js +66 -0
- package/dist/aws/cdk/constructs/cloudfront-construct.js.map +1 -0
- package/dist/aws/cdk/constructs/cloudwatch-construct.cjs +43 -0
- package/dist/aws/cdk/constructs/cloudwatch-construct.cjs.map +1 -0
- package/dist/aws/cdk/constructs/cloudwatch-construct.d.cts +36 -0
- package/dist/aws/cdk/constructs/cloudwatch-construct.d.ts +36 -0
- package/dist/aws/cdk/constructs/cloudwatch-construct.js +41 -0
- package/dist/aws/cdk/constructs/cloudwatch-construct.js.map +1 -0
- package/dist/aws/cdk/constructs/dynamo-db-construct.cjs +113 -0
- package/dist/aws/cdk/constructs/dynamo-db-construct.cjs.map +1 -0
- package/dist/aws/cdk/constructs/dynamo-db-construct.d.cts +53 -0
- package/dist/aws/cdk/constructs/dynamo-db-construct.d.ts +53 -0
- package/dist/aws/cdk/constructs/dynamo-db-construct.js +111 -0
- package/dist/aws/cdk/constructs/dynamo-db-construct.js.map +1 -0
- package/dist/aws/cdk/constructs/event-bridge-construct.cjs +47 -0
- package/dist/aws/cdk/constructs/event-bridge-construct.cjs.map +1 -0
- package/dist/aws/cdk/constructs/event-bridge-construct.d.cts +41 -0
- package/dist/aws/cdk/constructs/event-bridge-construct.d.ts +41 -0
- package/dist/aws/cdk/constructs/event-bridge-construct.js +45 -0
- package/dist/aws/cdk/constructs/event-bridge-construct.js.map +1 -0
- package/dist/aws/cdk/constructs/index.cjs +881 -0
- package/dist/aws/cdk/constructs/index.cjs.map +1 -0
- package/dist/aws/cdk/constructs/index.d.cts +34 -0
- package/dist/aws/cdk/constructs/index.d.ts +34 -0
- package/dist/aws/cdk/constructs/index.js +863 -0
- package/dist/aws/cdk/constructs/index.js.map +1 -0
- package/dist/aws/cdk/constructs/lambda-authorizer-construct.cjs +37 -0
- package/dist/aws/cdk/constructs/lambda-authorizer-construct.cjs.map +1 -0
- package/dist/aws/cdk/constructs/lambda-authorizer-construct.d.cts +44 -0
- package/dist/aws/cdk/constructs/lambda-authorizer-construct.d.ts +44 -0
- package/dist/aws/cdk/constructs/lambda-authorizer-construct.js +35 -0
- package/dist/aws/cdk/constructs/lambda-authorizer-construct.js.map +1 -0
- package/dist/aws/cdk/constructs/lambda-authorizer-v2-construct.cjs +47 -0
- package/dist/aws/cdk/constructs/lambda-authorizer-v2-construct.cjs.map +1 -0
- package/dist/aws/cdk/constructs/lambda-authorizer-v2-construct.d.cts +45 -0
- package/dist/aws/cdk/constructs/lambda-authorizer-v2-construct.d.ts +45 -0
- package/dist/aws/cdk/constructs/lambda-authorizer-v2-construct.js +45 -0
- package/dist/aws/cdk/constructs/lambda-authorizer-v2-construct.js.map +1 -0
- package/dist/aws/cdk/constructs/lambda-construct.cjs +82 -0
- package/dist/aws/cdk/constructs/lambda-construct.cjs.map +1 -0
- package/dist/aws/cdk/constructs/lambda-construct.d.cts +37 -0
- package/dist/aws/cdk/constructs/lambda-construct.d.ts +37 -0
- package/dist/aws/cdk/constructs/lambda-construct.js +80 -0
- package/dist/aws/cdk/constructs/lambda-construct.js.map +1 -0
- package/dist/aws/cdk/constructs/lambda-layer-construct.cjs +72 -0
- package/dist/aws/cdk/constructs/lambda-layer-construct.cjs.map +1 -0
- package/dist/aws/cdk/constructs/lambda-layer-construct.d.cts +52 -0
- package/dist/aws/cdk/constructs/lambda-layer-construct.d.ts +52 -0
- package/dist/aws/cdk/constructs/lambda-layer-construct.js +70 -0
- package/dist/aws/cdk/constructs/lambda-layer-construct.js.map +1 -0
- package/dist/aws/cdk/constructs/role-policy-construct.cjs +53 -0
- package/dist/aws/cdk/constructs/role-policy-construct.cjs.map +1 -0
- package/dist/aws/cdk/constructs/role-policy-construct.d.cts +44 -0
- package/dist/aws/cdk/constructs/role-policy-construct.d.ts +44 -0
- package/dist/aws/cdk/constructs/role-policy-construct.js +51 -0
- package/dist/aws/cdk/constructs/role-policy-construct.js.map +1 -0
- package/dist/aws/cdk/constructs/s3-construct.cjs +38 -0
- package/dist/aws/cdk/constructs/s3-construct.cjs.map +1 -0
- package/dist/aws/cdk/constructs/s3-construct.d.cts +36 -0
- package/dist/aws/cdk/constructs/s3-construct.d.ts +36 -0
- package/dist/aws/cdk/constructs/s3-construct.js +36 -0
- package/dist/aws/cdk/constructs/s3-construct.js.map +1 -0
- package/dist/aws/cdk/constructs/s3-deployment-construct.cjs +168 -0
- package/dist/aws/cdk/constructs/s3-deployment-construct.cjs.map +1 -0
- package/dist/aws/cdk/constructs/s3-deployment-construct.d.cts +72 -0
- package/dist/aws/cdk/constructs/s3-deployment-construct.d.ts +72 -0
- package/dist/aws/cdk/constructs/s3-deployment-construct.js +166 -0
- package/dist/aws/cdk/constructs/s3-deployment-construct.js.map +1 -0
- package/dist/aws/cdk/constructs/sns-construct.cjs +43 -0
- package/dist/aws/cdk/constructs/sns-construct.cjs.map +1 -0
- package/dist/aws/cdk/constructs/sns-construct.d.cts +45 -0
- package/dist/aws/cdk/constructs/sns-construct.d.ts +45 -0
- package/dist/aws/cdk/constructs/sns-construct.js +41 -0
- package/dist/aws/cdk/constructs/sns-construct.js.map +1 -0
- package/dist/aws/cdk/constructs/sqs-construct.cjs +55 -0
- package/dist/aws/cdk/constructs/sqs-construct.cjs.map +1 -0
- package/dist/aws/cdk/constructs/sqs-construct.d.cts +52 -0
- package/dist/aws/cdk/constructs/sqs-construct.d.ts +52 -0
- package/dist/aws/cdk/constructs/sqs-construct.js +53 -0
- package/dist/aws/cdk/constructs/sqs-construct.js.map +1 -0
- package/dist/aws/cdk/constructs/vpc-construct.cjs +33 -0
- package/dist/aws/cdk/constructs/vpc-construct.cjs.map +1 -0
- package/dist/aws/cdk/constructs/vpc-construct.d.cts +34 -0
- package/dist/aws/cdk/constructs/vpc-construct.d.ts +34 -0
- package/dist/aws/cdk/constructs/vpc-construct.js +31 -0
- package/dist/aws/cdk/constructs/vpc-construct.js.map +1 -0
- package/dist/aws/cdk/index.cjs +881 -0
- package/dist/aws/cdk/index.cjs.map +1 -0
- package/dist/aws/cdk/index.d.cts +34 -0
- package/dist/aws/cdk/index.d.ts +34 -0
- package/dist/aws/cdk/index.js +863 -0
- package/dist/aws/cdk/index.js.map +1 -0
- package/dist/aws/cli/index.cjs +4 -0
- package/dist/aws/cli/index.cjs.map +1 -0
- package/dist/aws/cli/index.d.cts +2 -0
- package/dist/aws/cli/index.d.ts +2 -0
- package/dist/aws/cli/index.js +3 -0
- package/dist/aws/cli/index.js.map +1 -0
- package/dist/aws/index.cjs +881 -0
- package/dist/aws/index.cjs.map +1 -0
- package/dist/aws/index.d.cts +34 -0
- package/dist/aws/index.d.ts +34 -0
- package/dist/aws/index.js +863 -0
- package/dist/aws/index.js.map +1 -0
- package/dist/aws/types/index.cjs +4 -0
- package/dist/aws/types/index.cjs.map +1 -0
- package/dist/aws/types/index.d.cts +18 -0
- package/dist/aws/types/index.d.ts +18 -0
- package/dist/aws/types/index.js +3 -0
- package/dist/aws/types/index.js.map +1 -0
- package/dist/index.d.cts +34 -755
- package/dist/index.d.ts +34 -755
- package/dist/lint/index.cjs +4 -0
- package/dist/lint/index.cjs.map +1 -0
- package/dist/lint/index.d.cts +2 -0
- package/dist/lint/index.d.ts +2 -0
- package/dist/lint/index.js +3 -0
- package/dist/lint/index.js.map +1 -0
- package/dist/prettier/index.cjs +4 -0
- package/dist/prettier/index.cjs.map +1 -0
- package/dist/prettier/index.d.cts +2 -0
- package/dist/prettier/index.d.ts +2 -0
- package/dist/prettier/index.js +3 -0
- package/dist/prettier/index.js.map +1 -0
- package/dist/utility/index.cjs +4 -0
- package/dist/utility/index.cjs.map +1 -0
- package/dist/utility/index.d.cts +2 -0
- package/dist/utility/index.d.ts +2 -0
- package/dist/utility/index.js +3 -0
- package/dist/utility/index.js.map +1 -0
- package/package.json +7 -2
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Construct } from 'constructs';
|
|
2
|
+
import { LogGroup, LogGroupProps } from 'aws-cdk-lib/aws-logs';
|
|
3
|
+
import { IBaseCdkConstructProps } from '../../types/index.js';
|
|
4
|
+
import '@incloodsolutions/toolkit';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Props for BaseCloudwatchLogGroupConstruct
|
|
8
|
+
*
|
|
9
|
+
* Provides configuration for creating a CloudWatch Log Group
|
|
10
|
+
* with optional overrides for retention and removal policy.
|
|
11
|
+
*/
|
|
12
|
+
interface ILogGroupConstructProps extends Omit<IBaseCdkConstructProps<{
|
|
13
|
+
/** Log Group configuration options */
|
|
14
|
+
readonly logGroupOptions: LogGroupProps;
|
|
15
|
+
}>, 'appName' | 'stage' | 'stackName'> {
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* CDK construct for CloudWatch Log Group
|
|
19
|
+
*
|
|
20
|
+
* Responsibilities:
|
|
21
|
+
* - Creates a log group with configurable options
|
|
22
|
+
* - Applies default removal policy and retention if not provided
|
|
23
|
+
* - Exposes the log group ARN as a CloudFormation output
|
|
24
|
+
*/
|
|
25
|
+
declare class BaseCloudwatchLogGroupConstruct extends Construct {
|
|
26
|
+
/** The created CloudWatch Log Group instance */
|
|
27
|
+
readonly logGroup: LogGroup;
|
|
28
|
+
/**
|
|
29
|
+
* @param scope Parent construct
|
|
30
|
+
* @param id Unique construct identifier
|
|
31
|
+
* @param props Configuration for the log group
|
|
32
|
+
*/
|
|
33
|
+
constructor(scope: Construct, id: string, props: ILogGroupConstructProps);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export { BaseCloudwatchLogGroupConstruct };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Construct } from 'constructs';
|
|
2
|
+
import { RemovalPolicy, CfnOutput } from 'aws-cdk-lib';
|
|
3
|
+
import { LogGroup, RetentionDays } from 'aws-cdk-lib/aws-logs';
|
|
4
|
+
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
+
var BaseCloudwatchLogGroupConstruct = class extends Construct {
|
|
8
|
+
static {
|
|
9
|
+
__name(this, "BaseCloudwatchLogGroupConstruct");
|
|
10
|
+
}
|
|
11
|
+
/** The created CloudWatch Log Group instance */
|
|
12
|
+
logGroup;
|
|
13
|
+
/**
|
|
14
|
+
* @param scope Parent construct
|
|
15
|
+
* @param id Unique construct identifier
|
|
16
|
+
* @param props Configuration for the log group
|
|
17
|
+
*/
|
|
18
|
+
constructor(scope, id, props) {
|
|
19
|
+
super(scope, id);
|
|
20
|
+
this.logGroup = new LogGroup(this, id, {
|
|
21
|
+
...props.options?.logGroupOptions,
|
|
22
|
+
/**
|
|
23
|
+
* Removal policy applied to the log group
|
|
24
|
+
* Defaults to DESTROY when not explicitly defined
|
|
25
|
+
*/
|
|
26
|
+
removalPolicy: props?.options?.logGroupOptions?.removalPolicy || RemovalPolicy.DESTROY,
|
|
27
|
+
/**
|
|
28
|
+
* Log retention period
|
|
29
|
+
* Defaults to INFINITE when not explicitly defined
|
|
30
|
+
*/
|
|
31
|
+
retention: props?.options?.logGroupOptions?.retention || RetentionDays.INFINITE
|
|
32
|
+
});
|
|
33
|
+
new CfnOutput(this, "CloudwatchArn", {
|
|
34
|
+
value: this.logGroup.logGroupArn
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export { BaseCloudwatchLogGroupConstruct };
|
|
40
|
+
//# sourceMappingURL=cloudwatch-construct.js.map
|
|
41
|
+
//# sourceMappingURL=cloudwatch-construct.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/aws/cdk/constructs/cloudwatch-construct.ts"],"names":[],"mappings":";;;;;;AAyBO,IAAM,+BAAA,GAAN,cAA8C,SAAA,CAAU;AAAA,EAzB/D;AAyB+D,IAAA,MAAA,CAAA,IAAA,EAAA,iCAAA,CAAA;AAAA;AAAA;AAAA,EAErD,QAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOT,WAAA,CAAY,KAAA,EAAkB,EAAA,EAAY,KAAA,EAAgC;AACzE,IAAA,KAAA,CAAM,OAAO,EAAE,CAAA;AAEf,IAAA,IAAA,CAAK,QAAA,GAAW,IAAI,QAAA,CAAS,IAAA,EAAM,EAAA,EAAI;AAAA,MACtC,GAAG,MAAM,OAAA,EAAS,eAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAMlB,aAAA,EACC,KAAA,EAAO,OAAA,EAAS,eAAA,EAAiB,iBAC9B,aAAA,CAAc,OAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAMlB,SAAA,EACC,KAAA,EAAO,OAAA,EAAS,eAAA,EAAiB,aAC9B,aAAA,CAAc;AAAA,KAClB,CAAA;AAKD,IAAA,IAAI,SAAA,CAAU,MAAM,eAAA,EAAiB;AAAA,MACpC,KAAA,EAAO,KAAK,QAAA,CAAS;AAAA,KACrB,CAAA;AAAA,EACF;AACD","file":"cloudwatch-construct.js","sourcesContent":["import { Construct } from 'constructs';\nimport { CfnOutput, RemovalPolicy } from 'aws-cdk-lib';\nimport { LogGroup, LogGroupProps, RetentionDays } from 'aws-cdk-lib/aws-logs';\n\nimport { IBaseCdkConstructProps } from '../../types';\n\n/**\n * Props for BaseCloudwatchLogGroupConstruct\n *\n * Provides configuration for creating a CloudWatch Log Group\n * with optional overrides for retention and removal policy.\n */\ninterface ILogGroupConstructProps extends Omit<IBaseCdkConstructProps<{\n\t/** Log Group configuration options */\n\treadonly logGroupOptions: LogGroupProps\n}>, 'appName' | 'stage' | 'stackName'> { }\n\n/**\n * CDK construct for CloudWatch Log Group\n *\n * Responsibilities:\n * - Creates a log group with configurable options\n * - Applies default removal policy and retention if not provided\n * - Exposes the log group ARN as a CloudFormation output\n */\nexport class BaseCloudwatchLogGroupConstruct extends Construct {\n\t/** The created CloudWatch Log Group instance */\n\treadonly logGroup: LogGroup;\n\n\t/**\n\t * @param scope Parent construct\n\t * @param id Unique construct identifier\n\t * @param props Configuration for the log group\n\t */\n\tconstructor(scope: Construct, id: string, props: ILogGroupConstructProps) {\n\t\tsuper(scope, id);\n\n\t\tthis.logGroup = new LogGroup(this, id, {\n\t\t\t...props.options?.logGroupOptions,\n\n\t\t\t/**\n\t\t\t * Removal policy applied to the log group\n\t\t\t * Defaults to DESTROY when not explicitly defined\n\t\t\t */\n\t\t\tremovalPolicy:\n\t\t\t\tprops?.options?.logGroupOptions?.removalPolicy\n\t\t\t\t|| RemovalPolicy.DESTROY,\n\n\t\t\t/**\n\t\t\t * Log retention period\n\t\t\t * Defaults to INFINITE when not explicitly defined\n\t\t\t */\n\t\t\tretention:\n\t\t\t\tprops?.options?.logGroupOptions?.retention\n\t\t\t\t|| RetentionDays.INFINITE,\n\t\t});\n\n\t\t/**\n\t\t * CloudFormation output exposing the Log Group ARN\n\t\t */\n\t\tnew CfnOutput(this, 'CloudwatchArn', {\n\t\t\tvalue: this.logGroup.logGroupArn\n\t\t});\n\t}\n}"]}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var constructs = require('constructs');
|
|
4
|
+
var awsCdkLib = require('aws-cdk-lib');
|
|
5
|
+
var awsDynamodb = require('aws-cdk-lib/aws-dynamodb');
|
|
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 BaseDynamoDBConstruct = class _BaseDynamoDBConstruct extends constructs.Construct {
|
|
11
|
+
static {
|
|
12
|
+
__name(this, "BaseDynamoDBConstruct");
|
|
13
|
+
}
|
|
14
|
+
/** Newly created DynamoDB table (null if importing existing table) */
|
|
15
|
+
table;
|
|
16
|
+
/** Imported DynamoDB table reference (null if creating new table) */
|
|
17
|
+
existingTable;
|
|
18
|
+
/** Enables debug logging */
|
|
19
|
+
enableDebug = false;
|
|
20
|
+
/**
|
|
21
|
+
* @param scope Parent construct
|
|
22
|
+
* @param id Unique construct identifier
|
|
23
|
+
* @param props Configuration for table creation or import
|
|
24
|
+
*/
|
|
25
|
+
constructor(scope, id, props) {
|
|
26
|
+
super(scope, id);
|
|
27
|
+
this.enableDebug = props?.enableDebug;
|
|
28
|
+
if (props.options?.fromExistingTableName) {
|
|
29
|
+
this.table = null;
|
|
30
|
+
this.existingTable = awsDynamodb.Table.fromTableName(
|
|
31
|
+
this,
|
|
32
|
+
`${id}-RefName`,
|
|
33
|
+
props.options.fromExistingTableName
|
|
34
|
+
);
|
|
35
|
+
if (this.enableDebug) {
|
|
36
|
+
toolkit.printLog(
|
|
37
|
+
_BaseDynamoDBConstruct.name,
|
|
38
|
+
`Created Dynamo-DB table from existing using name ${props.options?.fromExistingTableName}`
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
} else if (props.options?.fromExistingTableArn) {
|
|
42
|
+
this.table = null;
|
|
43
|
+
this.existingTable = awsDynamodb.Table.fromTableArn(
|
|
44
|
+
this,
|
|
45
|
+
`${id}-RefArn`,
|
|
46
|
+
props.options.fromExistingTableArn
|
|
47
|
+
);
|
|
48
|
+
if (this.enableDebug) {
|
|
49
|
+
toolkit.printLog(
|
|
50
|
+
_BaseDynamoDBConstruct.name,
|
|
51
|
+
`Created Dynamo-DB table from existing using ARN`
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
} else if (props.options?.fromExistingTableAttributes) {
|
|
55
|
+
this.table = null;
|
|
56
|
+
this.existingTable = awsDynamodb.Table.fromTableAttributes(
|
|
57
|
+
this,
|
|
58
|
+
`${id}-RefAttributes`,
|
|
59
|
+
props.options.fromExistingTableAttributes
|
|
60
|
+
);
|
|
61
|
+
if (this.enableDebug) {
|
|
62
|
+
toolkit.printLog(
|
|
63
|
+
_BaseDynamoDBConstruct.name,
|
|
64
|
+
`Created Dynamo-DB table from existing attributes`
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
} else {
|
|
68
|
+
this.existingTable = null;
|
|
69
|
+
this.table = new awsDynamodb.Table(this, id, {
|
|
70
|
+
...props.options?.tableOptions,
|
|
71
|
+
/**
|
|
72
|
+
* Billing mode defaults to PAY_PER_REQUEST if not provided
|
|
73
|
+
*/
|
|
74
|
+
billingMode: props.options?.tableOptions?.billingMode || awsDynamodb.BillingMode.PAY_PER_REQUEST,
|
|
75
|
+
/**
|
|
76
|
+
* Deletion protection:
|
|
77
|
+
* - Uses explicit value if provided
|
|
78
|
+
* - Defaults to true in production stage
|
|
79
|
+
*/
|
|
80
|
+
deletionProtection: props.options?.tableOptions?.deletionProtection === true || props.options?.tableOptions?.deletionProtection === false ? props.options.tableOptions.deletionProtection : props.stage === "production"
|
|
81
|
+
});
|
|
82
|
+
if (props.options?.globalSecondaryIndexes?.length) {
|
|
83
|
+
props.options.globalSecondaryIndexes.forEach((globalIndex) => {
|
|
84
|
+
this.table.addGlobalSecondaryIndex(globalIndex);
|
|
85
|
+
if (this.enableDebug) {
|
|
86
|
+
toolkit.printLog(
|
|
87
|
+
_BaseDynamoDBConstruct.name,
|
|
88
|
+
`Added GSI: ${globalIndex.indexName}`
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
if (props.options?.localSecondaryIndexes?.length) {
|
|
94
|
+
props.options.localSecondaryIndexes.forEach((localIndex) => {
|
|
95
|
+
this.table.addLocalSecondaryIndex(localIndex);
|
|
96
|
+
if (this.enableDebug) {
|
|
97
|
+
toolkit.printLog(
|
|
98
|
+
_BaseDynamoDBConstruct.name,
|
|
99
|
+
`Added LSI: ${localIndex.indexName}`
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
new awsCdkLib.CfnOutput(this, "DynamoDbArn", {
|
|
106
|
+
value: props.options?.fromExistingTableName || props.options?.fromExistingTableArn ? this.existingTable.tableArn : this.table.tableArn
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
exports.BaseDynamoDBConstruct = BaseDynamoDBConstruct;
|
|
112
|
+
//# sourceMappingURL=dynamo-db-construct.cjs.map
|
|
113
|
+
//# sourceMappingURL=dynamo-db-construct.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/aws/cdk/constructs/dynamo-db-construct.ts"],"names":["Construct","Table","printLog","BillingMode","CfnOutput"],"mappings":"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","file":"dynamo-db-construct.cjs","sourcesContent":["import { Construct } from 'constructs';\nimport { CfnOutput } from 'aws-cdk-lib';\nimport { BillingMode, GlobalSecondaryIndexProps, ITable, LocalSecondaryIndexProps, Table, TableAttributes, TableProps } from 'aws-cdk-lib/aws-dynamodb';\n\nimport { printLog } from '@incloodsolutions/toolkit';\n\nimport { IBaseCdkConstructProps, IBaseConstruct } from '../../types';\n\n/**\n * Props for BaseDynamoDBConstruct\n *\n * Provides configuration for:\n * - Creating a new DynamoDB table\n * - Importing an existing table (by name, ARN, or attributes)\n * - Defining Global Secondary Indexes (GSI) and Local Secondary Indexes (LSI)\n */\ninterface IDynamoDBConstructProps extends Omit<IBaseCdkConstructProps<{\n\t/** Configuration for creating a new table */\n\treadonly tableOptions?: TableProps;\n\n\t/** Import an existing table by ARN */\n\treadonly fromExistingTableArn?: string;\n\n\t/** Import an existing table by name */\n\treadonly fromExistingTableName?: string;\n\n\t/** Import an existing table using attributes */\n\treadonly fromExistingTableAttributes?: TableAttributes;\n\n\t/** Global Secondary Index definitions */\n\treadonly globalSecondaryIndexes?: GlobalSecondaryIndexProps[];\n\n\t/** Local Secondary Index definitions */\n\treadonly localSecondaryIndexes?: LocalSecondaryIndexProps[];\n}>, 'appName' | 'stackName'> { }\n\n/**\n * CDK construct for DynamoDB table management\n *\n * Responsibilities:\n * - Creates a new DynamoDB table or imports an existing one\n * - Applies default billing mode and deletion protection\n * - Attaches optional GSIs and LSIs\n * - Exposes table ARN as a CloudFormation output\n */\nexport class BaseDynamoDBConstruct extends Construct implements IBaseConstruct {\n\t/** Newly created DynamoDB table (null if importing existing table) */\n\treadonly table: Table;\n\n\t/** Imported DynamoDB table reference (null if creating new table) */\n\treadonly existingTable: ITable;\n\n\t/** Enables debug logging */\n\tenableDebug = false;\n\n\t/**\n\t * @param scope Parent construct\n\t * @param id Unique construct identifier\n\t * @param props Configuration for table creation or import\n\t */\n\tconstructor(scope: Construct, id: string, props: IDynamoDBConstructProps) {\n\t\tsuper(scope, id);\n\n\t\tthis.enableDebug = props?.enableDebug;\n\n\t\t/**\n\t\t * Import table by name\n\t\t */\n\t\tif (props.options?.fromExistingTableName) {\n\t\t\tthis.table = null;\n\n\t\t\tthis.existingTable = Table.fromTableName(\n\t\t\t\tthis,\n\t\t\t\t`${id}-RefName`,\n\t\t\t\tprops.options.fromExistingTableName\n\t\t\t);\n\n\t\t\tif (this.enableDebug) {\n\t\t\t\tprintLog(\n\t\t\t\t\tBaseDynamoDBConstruct.name,\n\t\t\t\t\t`Created Dynamo-DB table from existing using name ${props.options?.fromExistingTableName}`\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t/**\n\t\t\t * Import table by ARN\n\t\t\t */\n\t\t} else if (props.options?.fromExistingTableArn) {\n\t\t\tthis.table = null;\n\n\t\t\tthis.existingTable = Table.fromTableArn(\n\t\t\t\tthis,\n\t\t\t\t`${id}-RefArn`,\n\t\t\t\tprops.options.fromExistingTableArn\n\t\t\t);\n\n\t\t\tif (this.enableDebug) {\n\t\t\t\tprintLog(\n\t\t\t\t\tBaseDynamoDBConstruct.name,\n\t\t\t\t\t`Created Dynamo-DB table from existing using ARN`\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t/**\n\t\t\t * Import table using attributes\n\t\t\t */\n\t\t} else if (props.options?.fromExistingTableAttributes) {\n\t\t\tthis.table = null;\n\n\t\t\tthis.existingTable = Table.fromTableAttributes(\n\t\t\t\tthis,\n\t\t\t\t`${id}-RefAttributes`,\n\t\t\t\tprops.options.fromExistingTableAttributes\n\t\t\t);\n\n\t\t\tif (this.enableDebug) {\n\t\t\t\tprintLog(\n\t\t\t\t\tBaseDynamoDBConstruct.name,\n\t\t\t\t\t`Created Dynamo-DB table from existing attributes`\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t/**\n\t\t\t * Create new table\n\t\t\t */\n\t\t} else {\n\t\t\tthis.existingTable = null;\n\n\t\t\tthis.table = new Table(this, id, {\n\t\t\t\t...props.options?.tableOptions,\n\n\t\t\t\t/**\n\t\t\t\t * Billing mode defaults to PAY_PER_REQUEST if not provided\n\t\t\t\t */\n\t\t\t\tbillingMode:\n\t\t\t\t\tprops.options?.tableOptions?.billingMode\n\t\t\t\t\t|| BillingMode.PAY_PER_REQUEST,\n\n\t\t\t\t/**\n\t\t\t\t * Deletion protection:\n\t\t\t\t * - Uses explicit value if provided\n\t\t\t\t * - Defaults to true in production stage\n\t\t\t\t */\n\t\t\t\tdeletionProtection:\n\t\t\t\t\t(props.options?.tableOptions?.deletionProtection === true ||\n\t\t\t\t\t\tprops.options?.tableOptions?.deletionProtection === false)\n\t\t\t\t\t\t? props.options.tableOptions.deletionProtection\n\t\t\t\t\t\t: props.stage === 'production',\n\t\t\t});\n\n\t\t\t/**\n\t\t\t * Attach Global Secondary Indexes (GSI)\n\t\t\t */\n\t\t\tif (props.options?.globalSecondaryIndexes?.length) {\n\t\t\t\tprops.options.globalSecondaryIndexes.forEach(globalIndex => {\n\t\t\t\t\tthis.table.addGlobalSecondaryIndex(globalIndex);\n\n\t\t\t\t\tif (this.enableDebug) {\n\t\t\t\t\t\tprintLog(\n\t\t\t\t\t\t\tBaseDynamoDBConstruct.name,\n\t\t\t\t\t\t\t`Added GSI: ${globalIndex.indexName}`\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\n\t\t\t/**\n\t\t\t * Attach Local Secondary Indexes (LSI)\n\t\t\t */\n\t\t\tif (props.options?.localSecondaryIndexes?.length) {\n\t\t\t\tprops.options.localSecondaryIndexes.forEach(localIndex => {\n\t\t\t\t\tthis.table.addLocalSecondaryIndex(localIndex);\n\n\t\t\t\t\tif (this.enableDebug) {\n\t\t\t\t\t\tprintLog(\n\t\t\t\t\t\t\tBaseDynamoDBConstruct.name,\n\t\t\t\t\t\t\t`Added LSI: ${localIndex.indexName}`\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\t/**\n\t\t * CloudFormation output exposing the table ARN\n\t\t * Resolves to either created or imported table\n\t\t */\n\t\tnew CfnOutput(this, 'DynamoDbArn', {\n\t\t\tvalue:\n\t\t\t\t(props.options?.fromExistingTableName || props.options?.fromExistingTableArn)\n\t\t\t\t\t? this.existingTable.tableArn\n\t\t\t\t\t: this.table.tableArn\n\t\t});\n\t}\n}"]}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Construct } from 'constructs';
|
|
2
|
+
import { Table, ITable, TableProps, TableAttributes, GlobalSecondaryIndexProps, LocalSecondaryIndexProps } from 'aws-cdk-lib/aws-dynamodb';
|
|
3
|
+
import { IBaseConstruct, IBaseCdkConstructProps } from '../../types/index.cjs';
|
|
4
|
+
import '@incloodsolutions/toolkit';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Props for BaseDynamoDBConstruct
|
|
8
|
+
*
|
|
9
|
+
* Provides configuration for:
|
|
10
|
+
* - Creating a new DynamoDB table
|
|
11
|
+
* - Importing an existing table (by name, ARN, or attributes)
|
|
12
|
+
* - Defining Global Secondary Indexes (GSI) and Local Secondary Indexes (LSI)
|
|
13
|
+
*/
|
|
14
|
+
interface IDynamoDBConstructProps extends Omit<IBaseCdkConstructProps<{
|
|
15
|
+
/** Configuration for creating a new table */
|
|
16
|
+
readonly tableOptions?: TableProps;
|
|
17
|
+
/** Import an existing table by ARN */
|
|
18
|
+
readonly fromExistingTableArn?: string;
|
|
19
|
+
/** Import an existing table by name */
|
|
20
|
+
readonly fromExistingTableName?: string;
|
|
21
|
+
/** Import an existing table using attributes */
|
|
22
|
+
readonly fromExistingTableAttributes?: TableAttributes;
|
|
23
|
+
/** Global Secondary Index definitions */
|
|
24
|
+
readonly globalSecondaryIndexes?: GlobalSecondaryIndexProps[];
|
|
25
|
+
/** Local Secondary Index definitions */
|
|
26
|
+
readonly localSecondaryIndexes?: LocalSecondaryIndexProps[];
|
|
27
|
+
}>, 'appName' | 'stackName'> {
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* CDK construct for DynamoDB table management
|
|
31
|
+
*
|
|
32
|
+
* Responsibilities:
|
|
33
|
+
* - Creates a new DynamoDB table or imports an existing one
|
|
34
|
+
* - Applies default billing mode and deletion protection
|
|
35
|
+
* - Attaches optional GSIs and LSIs
|
|
36
|
+
* - Exposes table ARN as a CloudFormation output
|
|
37
|
+
*/
|
|
38
|
+
declare class BaseDynamoDBConstruct extends Construct implements IBaseConstruct {
|
|
39
|
+
/** Newly created DynamoDB table (null if importing existing table) */
|
|
40
|
+
readonly table: Table;
|
|
41
|
+
/** Imported DynamoDB table reference (null if creating new table) */
|
|
42
|
+
readonly existingTable: ITable;
|
|
43
|
+
/** Enables debug logging */
|
|
44
|
+
enableDebug: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* @param scope Parent construct
|
|
47
|
+
* @param id Unique construct identifier
|
|
48
|
+
* @param props Configuration for table creation or import
|
|
49
|
+
*/
|
|
50
|
+
constructor(scope: Construct, id: string, props: IDynamoDBConstructProps);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export { BaseDynamoDBConstruct };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Construct } from 'constructs';
|
|
2
|
+
import { Table, ITable, TableProps, TableAttributes, GlobalSecondaryIndexProps, LocalSecondaryIndexProps } from 'aws-cdk-lib/aws-dynamodb';
|
|
3
|
+
import { IBaseConstruct, IBaseCdkConstructProps } from '../../types/index.js';
|
|
4
|
+
import '@incloodsolutions/toolkit';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Props for BaseDynamoDBConstruct
|
|
8
|
+
*
|
|
9
|
+
* Provides configuration for:
|
|
10
|
+
* - Creating a new DynamoDB table
|
|
11
|
+
* - Importing an existing table (by name, ARN, or attributes)
|
|
12
|
+
* - Defining Global Secondary Indexes (GSI) and Local Secondary Indexes (LSI)
|
|
13
|
+
*/
|
|
14
|
+
interface IDynamoDBConstructProps extends Omit<IBaseCdkConstructProps<{
|
|
15
|
+
/** Configuration for creating a new table */
|
|
16
|
+
readonly tableOptions?: TableProps;
|
|
17
|
+
/** Import an existing table by ARN */
|
|
18
|
+
readonly fromExistingTableArn?: string;
|
|
19
|
+
/** Import an existing table by name */
|
|
20
|
+
readonly fromExistingTableName?: string;
|
|
21
|
+
/** Import an existing table using attributes */
|
|
22
|
+
readonly fromExistingTableAttributes?: TableAttributes;
|
|
23
|
+
/** Global Secondary Index definitions */
|
|
24
|
+
readonly globalSecondaryIndexes?: GlobalSecondaryIndexProps[];
|
|
25
|
+
/** Local Secondary Index definitions */
|
|
26
|
+
readonly localSecondaryIndexes?: LocalSecondaryIndexProps[];
|
|
27
|
+
}>, 'appName' | 'stackName'> {
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* CDK construct for DynamoDB table management
|
|
31
|
+
*
|
|
32
|
+
* Responsibilities:
|
|
33
|
+
* - Creates a new DynamoDB table or imports an existing one
|
|
34
|
+
* - Applies default billing mode and deletion protection
|
|
35
|
+
* - Attaches optional GSIs and LSIs
|
|
36
|
+
* - Exposes table ARN as a CloudFormation output
|
|
37
|
+
*/
|
|
38
|
+
declare class BaseDynamoDBConstruct extends Construct implements IBaseConstruct {
|
|
39
|
+
/** Newly created DynamoDB table (null if importing existing table) */
|
|
40
|
+
readonly table: Table;
|
|
41
|
+
/** Imported DynamoDB table reference (null if creating new table) */
|
|
42
|
+
readonly existingTable: ITable;
|
|
43
|
+
/** Enables debug logging */
|
|
44
|
+
enableDebug: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* @param scope Parent construct
|
|
47
|
+
* @param id Unique construct identifier
|
|
48
|
+
* @param props Configuration for table creation or import
|
|
49
|
+
*/
|
|
50
|
+
constructor(scope: Construct, id: string, props: IDynamoDBConstructProps);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export { BaseDynamoDBConstruct };
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { Construct } from 'constructs';
|
|
2
|
+
import { CfnOutput } from 'aws-cdk-lib';
|
|
3
|
+
import { Table, BillingMode } from 'aws-cdk-lib/aws-dynamodb';
|
|
4
|
+
import { printLog } from '@incloodsolutions/toolkit';
|
|
5
|
+
|
|
6
|
+
var __defProp = Object.defineProperty;
|
|
7
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
|
+
var BaseDynamoDBConstruct = class _BaseDynamoDBConstruct extends Construct {
|
|
9
|
+
static {
|
|
10
|
+
__name(this, "BaseDynamoDBConstruct");
|
|
11
|
+
}
|
|
12
|
+
/** Newly created DynamoDB table (null if importing existing table) */
|
|
13
|
+
table;
|
|
14
|
+
/** Imported DynamoDB table reference (null if creating new table) */
|
|
15
|
+
existingTable;
|
|
16
|
+
/** Enables debug logging */
|
|
17
|
+
enableDebug = false;
|
|
18
|
+
/**
|
|
19
|
+
* @param scope Parent construct
|
|
20
|
+
* @param id Unique construct identifier
|
|
21
|
+
* @param props Configuration for table creation or import
|
|
22
|
+
*/
|
|
23
|
+
constructor(scope, id, props) {
|
|
24
|
+
super(scope, id);
|
|
25
|
+
this.enableDebug = props?.enableDebug;
|
|
26
|
+
if (props.options?.fromExistingTableName) {
|
|
27
|
+
this.table = null;
|
|
28
|
+
this.existingTable = Table.fromTableName(
|
|
29
|
+
this,
|
|
30
|
+
`${id}-RefName`,
|
|
31
|
+
props.options.fromExistingTableName
|
|
32
|
+
);
|
|
33
|
+
if (this.enableDebug) {
|
|
34
|
+
printLog(
|
|
35
|
+
_BaseDynamoDBConstruct.name,
|
|
36
|
+
`Created Dynamo-DB table from existing using name ${props.options?.fromExistingTableName}`
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
} else if (props.options?.fromExistingTableArn) {
|
|
40
|
+
this.table = null;
|
|
41
|
+
this.existingTable = Table.fromTableArn(
|
|
42
|
+
this,
|
|
43
|
+
`${id}-RefArn`,
|
|
44
|
+
props.options.fromExistingTableArn
|
|
45
|
+
);
|
|
46
|
+
if (this.enableDebug) {
|
|
47
|
+
printLog(
|
|
48
|
+
_BaseDynamoDBConstruct.name,
|
|
49
|
+
`Created Dynamo-DB table from existing using ARN`
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
} else if (props.options?.fromExistingTableAttributes) {
|
|
53
|
+
this.table = null;
|
|
54
|
+
this.existingTable = Table.fromTableAttributes(
|
|
55
|
+
this,
|
|
56
|
+
`${id}-RefAttributes`,
|
|
57
|
+
props.options.fromExistingTableAttributes
|
|
58
|
+
);
|
|
59
|
+
if (this.enableDebug) {
|
|
60
|
+
printLog(
|
|
61
|
+
_BaseDynamoDBConstruct.name,
|
|
62
|
+
`Created Dynamo-DB table from existing attributes`
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
} else {
|
|
66
|
+
this.existingTable = null;
|
|
67
|
+
this.table = new Table(this, id, {
|
|
68
|
+
...props.options?.tableOptions,
|
|
69
|
+
/**
|
|
70
|
+
* Billing mode defaults to PAY_PER_REQUEST if not provided
|
|
71
|
+
*/
|
|
72
|
+
billingMode: props.options?.tableOptions?.billingMode || BillingMode.PAY_PER_REQUEST,
|
|
73
|
+
/**
|
|
74
|
+
* Deletion protection:
|
|
75
|
+
* - Uses explicit value if provided
|
|
76
|
+
* - Defaults to true in production stage
|
|
77
|
+
*/
|
|
78
|
+
deletionProtection: props.options?.tableOptions?.deletionProtection === true || props.options?.tableOptions?.deletionProtection === false ? props.options.tableOptions.deletionProtection : props.stage === "production"
|
|
79
|
+
});
|
|
80
|
+
if (props.options?.globalSecondaryIndexes?.length) {
|
|
81
|
+
props.options.globalSecondaryIndexes.forEach((globalIndex) => {
|
|
82
|
+
this.table.addGlobalSecondaryIndex(globalIndex);
|
|
83
|
+
if (this.enableDebug) {
|
|
84
|
+
printLog(
|
|
85
|
+
_BaseDynamoDBConstruct.name,
|
|
86
|
+
`Added GSI: ${globalIndex.indexName}`
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
if (props.options?.localSecondaryIndexes?.length) {
|
|
92
|
+
props.options.localSecondaryIndexes.forEach((localIndex) => {
|
|
93
|
+
this.table.addLocalSecondaryIndex(localIndex);
|
|
94
|
+
if (this.enableDebug) {
|
|
95
|
+
printLog(
|
|
96
|
+
_BaseDynamoDBConstruct.name,
|
|
97
|
+
`Added LSI: ${localIndex.indexName}`
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
new CfnOutput(this, "DynamoDbArn", {
|
|
104
|
+
value: props.options?.fromExistingTableName || props.options?.fromExistingTableArn ? this.existingTable.tableArn : this.table.tableArn
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
export { BaseDynamoDBConstruct };
|
|
110
|
+
//# sourceMappingURL=dynamo-db-construct.js.map
|
|
111
|
+
//# sourceMappingURL=dynamo-db-construct.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/aws/cdk/constructs/dynamo-db-construct.ts"],"names":[],"mappings":"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","file":"dynamo-db-construct.js","sourcesContent":["import { Construct } from 'constructs';\nimport { CfnOutput } from 'aws-cdk-lib';\nimport { BillingMode, GlobalSecondaryIndexProps, ITable, LocalSecondaryIndexProps, Table, TableAttributes, TableProps } from 'aws-cdk-lib/aws-dynamodb';\n\nimport { printLog } from '@incloodsolutions/toolkit';\n\nimport { IBaseCdkConstructProps, IBaseConstruct } from '../../types';\n\n/**\n * Props for BaseDynamoDBConstruct\n *\n * Provides configuration for:\n * - Creating a new DynamoDB table\n * - Importing an existing table (by name, ARN, or attributes)\n * - Defining Global Secondary Indexes (GSI) and Local Secondary Indexes (LSI)\n */\ninterface IDynamoDBConstructProps extends Omit<IBaseCdkConstructProps<{\n\t/** Configuration for creating a new table */\n\treadonly tableOptions?: TableProps;\n\n\t/** Import an existing table by ARN */\n\treadonly fromExistingTableArn?: string;\n\n\t/** Import an existing table by name */\n\treadonly fromExistingTableName?: string;\n\n\t/** Import an existing table using attributes */\n\treadonly fromExistingTableAttributes?: TableAttributes;\n\n\t/** Global Secondary Index definitions */\n\treadonly globalSecondaryIndexes?: GlobalSecondaryIndexProps[];\n\n\t/** Local Secondary Index definitions */\n\treadonly localSecondaryIndexes?: LocalSecondaryIndexProps[];\n}>, 'appName' | 'stackName'> { }\n\n/**\n * CDK construct for DynamoDB table management\n *\n * Responsibilities:\n * - Creates a new DynamoDB table or imports an existing one\n * - Applies default billing mode and deletion protection\n * - Attaches optional GSIs and LSIs\n * - Exposes table ARN as a CloudFormation output\n */\nexport class BaseDynamoDBConstruct extends Construct implements IBaseConstruct {\n\t/** Newly created DynamoDB table (null if importing existing table) */\n\treadonly table: Table;\n\n\t/** Imported DynamoDB table reference (null if creating new table) */\n\treadonly existingTable: ITable;\n\n\t/** Enables debug logging */\n\tenableDebug = false;\n\n\t/**\n\t * @param scope Parent construct\n\t * @param id Unique construct identifier\n\t * @param props Configuration for table creation or import\n\t */\n\tconstructor(scope: Construct, id: string, props: IDynamoDBConstructProps) {\n\t\tsuper(scope, id);\n\n\t\tthis.enableDebug = props?.enableDebug;\n\n\t\t/**\n\t\t * Import table by name\n\t\t */\n\t\tif (props.options?.fromExistingTableName) {\n\t\t\tthis.table = null;\n\n\t\t\tthis.existingTable = Table.fromTableName(\n\t\t\t\tthis,\n\t\t\t\t`${id}-RefName`,\n\t\t\t\tprops.options.fromExistingTableName\n\t\t\t);\n\n\t\t\tif (this.enableDebug) {\n\t\t\t\tprintLog(\n\t\t\t\t\tBaseDynamoDBConstruct.name,\n\t\t\t\t\t`Created Dynamo-DB table from existing using name ${props.options?.fromExistingTableName}`\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t/**\n\t\t\t * Import table by ARN\n\t\t\t */\n\t\t} else if (props.options?.fromExistingTableArn) {\n\t\t\tthis.table = null;\n\n\t\t\tthis.existingTable = Table.fromTableArn(\n\t\t\t\tthis,\n\t\t\t\t`${id}-RefArn`,\n\t\t\t\tprops.options.fromExistingTableArn\n\t\t\t);\n\n\t\t\tif (this.enableDebug) {\n\t\t\t\tprintLog(\n\t\t\t\t\tBaseDynamoDBConstruct.name,\n\t\t\t\t\t`Created Dynamo-DB table from existing using ARN`\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t/**\n\t\t\t * Import table using attributes\n\t\t\t */\n\t\t} else if (props.options?.fromExistingTableAttributes) {\n\t\t\tthis.table = null;\n\n\t\t\tthis.existingTable = Table.fromTableAttributes(\n\t\t\t\tthis,\n\t\t\t\t`${id}-RefAttributes`,\n\t\t\t\tprops.options.fromExistingTableAttributes\n\t\t\t);\n\n\t\t\tif (this.enableDebug) {\n\t\t\t\tprintLog(\n\t\t\t\t\tBaseDynamoDBConstruct.name,\n\t\t\t\t\t`Created Dynamo-DB table from existing attributes`\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t/**\n\t\t\t * Create new table\n\t\t\t */\n\t\t} else {\n\t\t\tthis.existingTable = null;\n\n\t\t\tthis.table = new Table(this, id, {\n\t\t\t\t...props.options?.tableOptions,\n\n\t\t\t\t/**\n\t\t\t\t * Billing mode defaults to PAY_PER_REQUEST if not provided\n\t\t\t\t */\n\t\t\t\tbillingMode:\n\t\t\t\t\tprops.options?.tableOptions?.billingMode\n\t\t\t\t\t|| BillingMode.PAY_PER_REQUEST,\n\n\t\t\t\t/**\n\t\t\t\t * Deletion protection:\n\t\t\t\t * - Uses explicit value if provided\n\t\t\t\t * - Defaults to true in production stage\n\t\t\t\t */\n\t\t\t\tdeletionProtection:\n\t\t\t\t\t(props.options?.tableOptions?.deletionProtection === true ||\n\t\t\t\t\t\tprops.options?.tableOptions?.deletionProtection === false)\n\t\t\t\t\t\t? props.options.tableOptions.deletionProtection\n\t\t\t\t\t\t: props.stage === 'production',\n\t\t\t});\n\n\t\t\t/**\n\t\t\t * Attach Global Secondary Indexes (GSI)\n\t\t\t */\n\t\t\tif (props.options?.globalSecondaryIndexes?.length) {\n\t\t\t\tprops.options.globalSecondaryIndexes.forEach(globalIndex => {\n\t\t\t\t\tthis.table.addGlobalSecondaryIndex(globalIndex);\n\n\t\t\t\t\tif (this.enableDebug) {\n\t\t\t\t\t\tprintLog(\n\t\t\t\t\t\t\tBaseDynamoDBConstruct.name,\n\t\t\t\t\t\t\t`Added GSI: ${globalIndex.indexName}`\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\n\t\t\t/**\n\t\t\t * Attach Local Secondary Indexes (LSI)\n\t\t\t */\n\t\t\tif (props.options?.localSecondaryIndexes?.length) {\n\t\t\t\tprops.options.localSecondaryIndexes.forEach(localIndex => {\n\t\t\t\t\tthis.table.addLocalSecondaryIndex(localIndex);\n\n\t\t\t\t\tif (this.enableDebug) {\n\t\t\t\t\t\tprintLog(\n\t\t\t\t\t\t\tBaseDynamoDBConstruct.name,\n\t\t\t\t\t\t\t`Added LSI: ${localIndex.indexName}`\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\t/**\n\t\t * CloudFormation output exposing the table ARN\n\t\t * Resolves to either created or imported table\n\t\t */\n\t\tnew CfnOutput(this, 'DynamoDbArn', {\n\t\t\tvalue:\n\t\t\t\t(props.options?.fromExistingTableName || props.options?.fromExistingTableArn)\n\t\t\t\t\t? this.existingTable.tableArn\n\t\t\t\t\t: this.table.tableArn\n\t\t});\n\t}\n}"]}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var constructs = require('constructs');
|
|
4
|
+
var awsCdkLib = require('aws-cdk-lib');
|
|
5
|
+
var awsEvents = require('aws-cdk-lib/aws-events');
|
|
6
|
+
var awsEventsTargets = require('aws-cdk-lib/aws-events-targets');
|
|
7
|
+
|
|
8
|
+
var __defProp = Object.defineProperty;
|
|
9
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
10
|
+
var BaseEventBridgeConstruct = class extends constructs.Construct {
|
|
11
|
+
static {
|
|
12
|
+
__name(this, "BaseEventBridgeConstruct");
|
|
13
|
+
}
|
|
14
|
+
/** The created EventBridge rule instance */
|
|
15
|
+
eventSchedule;
|
|
16
|
+
/**
|
|
17
|
+
* @param scope Parent construct
|
|
18
|
+
* @param id Unique construct identifier
|
|
19
|
+
* @param props Configuration for rule and target functions
|
|
20
|
+
*/
|
|
21
|
+
constructor(scope, id, props) {
|
|
22
|
+
super(scope, id);
|
|
23
|
+
this.eventSchedule = new awsEvents.Rule(this, id, {
|
|
24
|
+
...props.options?.eventBridgeOptions,
|
|
25
|
+
/** Default description if not explicitly provided */
|
|
26
|
+
description: props?.options?.eventBridgeOptions?.description || "An Event-bridge rule"
|
|
27
|
+
});
|
|
28
|
+
if (props.options?.targetFunctions?.length) {
|
|
29
|
+
props.options.targetFunctions.forEach((targetFunction) => {
|
|
30
|
+
this.eventSchedule.addTarget(
|
|
31
|
+
/**
|
|
32
|
+
* Lambda target integration
|
|
33
|
+
*/
|
|
34
|
+
new awsEventsTargets.LambdaFunction(targetFunction)
|
|
35
|
+
);
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
this.eventSchedule.applyRemovalPolicy(awsCdkLib.RemovalPolicy.DESTROY);
|
|
39
|
+
new awsCdkLib.CfnOutput(this, "EventBridgeArn", {
|
|
40
|
+
value: this.eventSchedule.ruleArn
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
exports.BaseEventBridgeConstruct = BaseEventBridgeConstruct;
|
|
46
|
+
//# sourceMappingURL=event-bridge-construct.cjs.map
|
|
47
|
+
//# sourceMappingURL=event-bridge-construct.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/aws/cdk/constructs/event-bridge-construct.ts"],"names":["Construct","Rule","LambdaFunction","RemovalPolicy","CfnOutput"],"mappings":";;;;;;;;;AAgCO,IAAM,wBAAA,GAAN,cAAuCA,oBAAA,CAAU;AAAA,EAhCxD;AAgCwD,IAAA,MAAA,CAAA,IAAA,EAAA,0BAAA,CAAA;AAAA;AAAA;AAAA,EAE9C,aAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOT,WAAA,CAAY,KAAA,EAAkB,EAAA,EAAY,KAAA,EAAmC;AAC5E,IAAA,KAAA,CAAM,OAAO,EAAE,CAAA;AAEf,IAAA,IAAA,CAAK,aAAA,GAAgB,IAAIC,cAAA,CAAK,IAAA,EAAM,EAAA,EAAI;AAAA,MACvC,GAAG,MAAM,OAAA,EAAS,kBAAA;AAAA;AAAA,MAGlB,WAAA,EACC,KAAA,EAAO,OAAA,EAAS,kBAAA,EAAoB,WAAA,IACjC;AAAA,KACJ,CAAA;AAKD,IAAA,IAAI,KAAA,CAAM,OAAA,EAAS,eAAA,EAAiB,MAAA,EAAQ;AAC3C,MAAA,KAAA,CAAM,OAAA,CAAQ,eAAA,CAAgB,OAAA,CAAQ,CAAC,cAAA,KAAmB;AACzD,QAAA,IAAA,CAAK,aAAA,CAAc,SAAA;AAAA;AAAA;AAAA;AAAA,UAIlB,IAAIC,gCAAe,cAAc;AAAA,SAClC;AAAA,MACD,CAAC,CAAA;AAAA,IACF;AAKA,IAAA,IAAA,CAAK,aAAA,CAAc,kBAAA,CAAmBC,uBAAA,CAAc,OAAO,CAAA;AAK3D,IAAA,IAAIC,mBAAA,CAAU,MAAM,gBAAA,EAAkB;AAAA,MACrC,KAAA,EAAO,KAAK,aAAA,CAAc;AAAA,KAC1B,CAAA;AAAA,EACF;AACD","file":"event-bridge-construct.cjs","sourcesContent":["import { Construct } from 'constructs';\nimport { Function } from 'aws-cdk-lib/aws-lambda';\nimport { CfnOutput, RemovalPolicy } from 'aws-cdk-lib';\nimport { Rule, RuleProps } from 'aws-cdk-lib/aws-events';\nimport { LambdaFunction } from 'aws-cdk-lib/aws-events-targets';\n\nimport { IBaseCdkConstructProps } from '../../types';\n\n/**\n * Props for BaseEventBridgeConstruct\n *\n * Provides configuration for:\n * - EventBridge rule creation\n * - Target Lambda functions\n */\ninterface IEventBridgeConstructProps extends Omit<IBaseCdkConstructProps<{\n\t/** Lambda functions to be triggered by the rule */\n\treadonly targetFunctions: Function[];\n\n\t/** EventBridge rule configuration */\n\treadonly eventBridgeOptions: RuleProps;\n}>, 'appName' | 'stage' | 'stackName'> { }\n\n/**\n * CDK construct for EventBridge rule\n *\n * Responsibilities:\n * - Creates an EventBridge rule with configurable options\n * - Attaches one or more Lambda targets\n * - Applies a removal policy\n * - Exposes the rule ARN as a CloudFormation output\n */\nexport class BaseEventBridgeConstruct extends Construct {\n\t/** The created EventBridge rule instance */\n\treadonly eventSchedule: Rule;\n\n\t/**\n\t * @param scope Parent construct\n\t * @param id Unique construct identifier\n\t * @param props Configuration for rule and target functions\n\t */\n\tconstructor(scope: Construct, id: string, props: IEventBridgeConstructProps) {\n\t\tsuper(scope, id);\n\n\t\tthis.eventSchedule = new Rule(this, id, {\n\t\t\t...props.options?.eventBridgeOptions,\n\n\t\t\t/** Default description if not explicitly provided */\n\t\t\tdescription:\n\t\t\t\tprops?.options?.eventBridgeOptions?.description\n\t\t\t\t|| 'An Event-bridge rule'\n\t\t});\n\n\t\t/**\n\t\t * Attach Lambda targets to the rule\n\t\t */\n\t\tif (props.options?.targetFunctions?.length) {\n\t\t\tprops.options.targetFunctions.forEach((targetFunction) => {\n\t\t\t\tthis.eventSchedule.addTarget(\n\t\t\t\t\t/**\n\t\t\t\t\t * Lambda target integration\n\t\t\t\t\t */\n\t\t\t\t\tnew LambdaFunction(targetFunction)\n\t\t\t\t);\n\t\t\t});\n\t\t}\n\n\t\t/**\n\t\t * Apply removal policy (useful for non-production environments)\n\t\t */\n\t\tthis.eventSchedule.applyRemovalPolicy(RemovalPolicy.DESTROY);\n\n\t\t/**\n\t\t * CloudFormation output exposing the rule ARN\n\t\t */\n\t\tnew CfnOutput(this, 'EventBridgeArn', {\n\t\t\tvalue: this.eventSchedule.ruleArn\n\t\t});\n\t}\n}"]}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Construct } from 'constructs';
|
|
2
|
+
import { Function } from 'aws-cdk-lib/aws-lambda';
|
|
3
|
+
import { Rule, RuleProps } from 'aws-cdk-lib/aws-events';
|
|
4
|
+
import { IBaseCdkConstructProps } from '../../types/index.cjs';
|
|
5
|
+
import '@incloodsolutions/toolkit';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Props for BaseEventBridgeConstruct
|
|
9
|
+
*
|
|
10
|
+
* Provides configuration for:
|
|
11
|
+
* - EventBridge rule creation
|
|
12
|
+
* - Target Lambda functions
|
|
13
|
+
*/
|
|
14
|
+
interface IEventBridgeConstructProps extends Omit<IBaseCdkConstructProps<{
|
|
15
|
+
/** Lambda functions to be triggered by the rule */
|
|
16
|
+
readonly targetFunctions: Function[];
|
|
17
|
+
/** EventBridge rule configuration */
|
|
18
|
+
readonly eventBridgeOptions: RuleProps;
|
|
19
|
+
}>, 'appName' | 'stage' | 'stackName'> {
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* CDK construct for EventBridge rule
|
|
23
|
+
*
|
|
24
|
+
* Responsibilities:
|
|
25
|
+
* - Creates an EventBridge rule with configurable options
|
|
26
|
+
* - Attaches one or more Lambda targets
|
|
27
|
+
* - Applies a removal policy
|
|
28
|
+
* - Exposes the rule ARN as a CloudFormation output
|
|
29
|
+
*/
|
|
30
|
+
declare class BaseEventBridgeConstruct extends Construct {
|
|
31
|
+
/** The created EventBridge rule instance */
|
|
32
|
+
readonly eventSchedule: Rule;
|
|
33
|
+
/**
|
|
34
|
+
* @param scope Parent construct
|
|
35
|
+
* @param id Unique construct identifier
|
|
36
|
+
* @param props Configuration for rule and target functions
|
|
37
|
+
*/
|
|
38
|
+
constructor(scope: Construct, id: string, props: IEventBridgeConstructProps);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export { BaseEventBridgeConstruct };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Construct } from 'constructs';
|
|
2
|
+
import { Function } from 'aws-cdk-lib/aws-lambda';
|
|
3
|
+
import { Rule, RuleProps } from 'aws-cdk-lib/aws-events';
|
|
4
|
+
import { IBaseCdkConstructProps } from '../../types/index.js';
|
|
5
|
+
import '@incloodsolutions/toolkit';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Props for BaseEventBridgeConstruct
|
|
9
|
+
*
|
|
10
|
+
* Provides configuration for:
|
|
11
|
+
* - EventBridge rule creation
|
|
12
|
+
* - Target Lambda functions
|
|
13
|
+
*/
|
|
14
|
+
interface IEventBridgeConstructProps extends Omit<IBaseCdkConstructProps<{
|
|
15
|
+
/** Lambda functions to be triggered by the rule */
|
|
16
|
+
readonly targetFunctions: Function[];
|
|
17
|
+
/** EventBridge rule configuration */
|
|
18
|
+
readonly eventBridgeOptions: RuleProps;
|
|
19
|
+
}>, 'appName' | 'stage' | 'stackName'> {
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* CDK construct for EventBridge rule
|
|
23
|
+
*
|
|
24
|
+
* Responsibilities:
|
|
25
|
+
* - Creates an EventBridge rule with configurable options
|
|
26
|
+
* - Attaches one or more Lambda targets
|
|
27
|
+
* - Applies a removal policy
|
|
28
|
+
* - Exposes the rule ARN as a CloudFormation output
|
|
29
|
+
*/
|
|
30
|
+
declare class BaseEventBridgeConstruct extends Construct {
|
|
31
|
+
/** The created EventBridge rule instance */
|
|
32
|
+
readonly eventSchedule: Rule;
|
|
33
|
+
/**
|
|
34
|
+
* @param scope Parent construct
|
|
35
|
+
* @param id Unique construct identifier
|
|
36
|
+
* @param props Configuration for rule and target functions
|
|
37
|
+
*/
|
|
38
|
+
constructor(scope: Construct, id: string, props: IEventBridgeConstructProps);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export { BaseEventBridgeConstruct };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Construct } from 'constructs';
|
|
2
|
+
import { RemovalPolicy, CfnOutput } from 'aws-cdk-lib';
|
|
3
|
+
import { Rule } from 'aws-cdk-lib/aws-events';
|
|
4
|
+
import { LambdaFunction } from 'aws-cdk-lib/aws-events-targets';
|
|
5
|
+
|
|
6
|
+
var __defProp = Object.defineProperty;
|
|
7
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
|
+
var BaseEventBridgeConstruct = class extends Construct {
|
|
9
|
+
static {
|
|
10
|
+
__name(this, "BaseEventBridgeConstruct");
|
|
11
|
+
}
|
|
12
|
+
/** The created EventBridge rule instance */
|
|
13
|
+
eventSchedule;
|
|
14
|
+
/**
|
|
15
|
+
* @param scope Parent construct
|
|
16
|
+
* @param id Unique construct identifier
|
|
17
|
+
* @param props Configuration for rule and target functions
|
|
18
|
+
*/
|
|
19
|
+
constructor(scope, id, props) {
|
|
20
|
+
super(scope, id);
|
|
21
|
+
this.eventSchedule = new Rule(this, id, {
|
|
22
|
+
...props.options?.eventBridgeOptions,
|
|
23
|
+
/** Default description if not explicitly provided */
|
|
24
|
+
description: props?.options?.eventBridgeOptions?.description || "An Event-bridge rule"
|
|
25
|
+
});
|
|
26
|
+
if (props.options?.targetFunctions?.length) {
|
|
27
|
+
props.options.targetFunctions.forEach((targetFunction) => {
|
|
28
|
+
this.eventSchedule.addTarget(
|
|
29
|
+
/**
|
|
30
|
+
* Lambda target integration
|
|
31
|
+
*/
|
|
32
|
+
new LambdaFunction(targetFunction)
|
|
33
|
+
);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
this.eventSchedule.applyRemovalPolicy(RemovalPolicy.DESTROY);
|
|
37
|
+
new CfnOutput(this, "EventBridgeArn", {
|
|
38
|
+
value: this.eventSchedule.ruleArn
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export { BaseEventBridgeConstruct };
|
|
44
|
+
//# sourceMappingURL=event-bridge-construct.js.map
|
|
45
|
+
//# sourceMappingURL=event-bridge-construct.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/aws/cdk/constructs/event-bridge-construct.ts"],"names":[],"mappings":";;;;;;;AAgCO,IAAM,wBAAA,GAAN,cAAuC,SAAA,CAAU;AAAA,EAhCxD;AAgCwD,IAAA,MAAA,CAAA,IAAA,EAAA,0BAAA,CAAA;AAAA;AAAA;AAAA,EAE9C,aAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOT,WAAA,CAAY,KAAA,EAAkB,EAAA,EAAY,KAAA,EAAmC;AAC5E,IAAA,KAAA,CAAM,OAAO,EAAE,CAAA;AAEf,IAAA,IAAA,CAAK,aAAA,GAAgB,IAAI,IAAA,CAAK,IAAA,EAAM,EAAA,EAAI;AAAA,MACvC,GAAG,MAAM,OAAA,EAAS,kBAAA;AAAA;AAAA,MAGlB,WAAA,EACC,KAAA,EAAO,OAAA,EAAS,kBAAA,EAAoB,WAAA,IACjC;AAAA,KACJ,CAAA;AAKD,IAAA,IAAI,KAAA,CAAM,OAAA,EAAS,eAAA,EAAiB,MAAA,EAAQ;AAC3C,MAAA,KAAA,CAAM,OAAA,CAAQ,eAAA,CAAgB,OAAA,CAAQ,CAAC,cAAA,KAAmB;AACzD,QAAA,IAAA,CAAK,aAAA,CAAc,SAAA;AAAA;AAAA;AAAA;AAAA,UAIlB,IAAI,eAAe,cAAc;AAAA,SAClC;AAAA,MACD,CAAC,CAAA;AAAA,IACF;AAKA,IAAA,IAAA,CAAK,aAAA,CAAc,kBAAA,CAAmB,aAAA,CAAc,OAAO,CAAA;AAK3D,IAAA,IAAI,SAAA,CAAU,MAAM,gBAAA,EAAkB;AAAA,MACrC,KAAA,EAAO,KAAK,aAAA,CAAc;AAAA,KAC1B,CAAA;AAAA,EACF;AACD","file":"event-bridge-construct.js","sourcesContent":["import { Construct } from 'constructs';\nimport { Function } from 'aws-cdk-lib/aws-lambda';\nimport { CfnOutput, RemovalPolicy } from 'aws-cdk-lib';\nimport { Rule, RuleProps } from 'aws-cdk-lib/aws-events';\nimport { LambdaFunction } from 'aws-cdk-lib/aws-events-targets';\n\nimport { IBaseCdkConstructProps } from '../../types';\n\n/**\n * Props for BaseEventBridgeConstruct\n *\n * Provides configuration for:\n * - EventBridge rule creation\n * - Target Lambda functions\n */\ninterface IEventBridgeConstructProps extends Omit<IBaseCdkConstructProps<{\n\t/** Lambda functions to be triggered by the rule */\n\treadonly targetFunctions: Function[];\n\n\t/** EventBridge rule configuration */\n\treadonly eventBridgeOptions: RuleProps;\n}>, 'appName' | 'stage' | 'stackName'> { }\n\n/**\n * CDK construct for EventBridge rule\n *\n * Responsibilities:\n * - Creates an EventBridge rule with configurable options\n * - Attaches one or more Lambda targets\n * - Applies a removal policy\n * - Exposes the rule ARN as a CloudFormation output\n */\nexport class BaseEventBridgeConstruct extends Construct {\n\t/** The created EventBridge rule instance */\n\treadonly eventSchedule: Rule;\n\n\t/**\n\t * @param scope Parent construct\n\t * @param id Unique construct identifier\n\t * @param props Configuration for rule and target functions\n\t */\n\tconstructor(scope: Construct, id: string, props: IEventBridgeConstructProps) {\n\t\tsuper(scope, id);\n\n\t\tthis.eventSchedule = new Rule(this, id, {\n\t\t\t...props.options?.eventBridgeOptions,\n\n\t\t\t/** Default description if not explicitly provided */\n\t\t\tdescription:\n\t\t\t\tprops?.options?.eventBridgeOptions?.description\n\t\t\t\t|| 'An Event-bridge rule'\n\t\t});\n\n\t\t/**\n\t\t * Attach Lambda targets to the rule\n\t\t */\n\t\tif (props.options?.targetFunctions?.length) {\n\t\t\tprops.options.targetFunctions.forEach((targetFunction) => {\n\t\t\t\tthis.eventSchedule.addTarget(\n\t\t\t\t\t/**\n\t\t\t\t\t * Lambda target integration\n\t\t\t\t\t */\n\t\t\t\t\tnew LambdaFunction(targetFunction)\n\t\t\t\t);\n\t\t\t});\n\t\t}\n\n\t\t/**\n\t\t * Apply removal policy (useful for non-production environments)\n\t\t */\n\t\tthis.eventSchedule.applyRemovalPolicy(RemovalPolicy.DESTROY);\n\n\t\t/**\n\t\t * CloudFormation output exposing the rule ARN\n\t\t */\n\t\tnew CfnOutput(this, 'EventBridgeArn', {\n\t\t\tvalue: this.eventSchedule.ruleArn\n\t\t});\n\t}\n}"]}
|