@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,175 @@
|
|
|
1
|
+
import { Construct } from 'constructs';
|
|
2
|
+
import { S3BucketOrigin } from 'aws-cdk-lib/aws-cloudfront-origins';
|
|
3
|
+
import { BucketDeployment } from 'aws-cdk-lib/aws-s3-deployment';
|
|
4
|
+
import { CustomException } from '@incloodsolutions/toolkit';
|
|
5
|
+
import { RemovalPolicy, CfnOutput, Duration } from 'aws-cdk-lib';
|
|
6
|
+
import { Bucket } from 'aws-cdk-lib/aws-s3';
|
|
7
|
+
import { Distribution, ViewerProtocolPolicy } from 'aws-cdk-lib/aws-cloudfront';
|
|
8
|
+
|
|
9
|
+
var __defProp = Object.defineProperty;
|
|
10
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
11
|
+
var BaseS3Construct = class extends Construct {
|
|
12
|
+
static {
|
|
13
|
+
__name(this, "BaseS3Construct");
|
|
14
|
+
}
|
|
15
|
+
/** The created S3 bucket instance */
|
|
16
|
+
bucket;
|
|
17
|
+
/**
|
|
18
|
+
* @param scope Parent construct
|
|
19
|
+
* @param id Unique construct identifier
|
|
20
|
+
* @param props Configuration for S3 bucket
|
|
21
|
+
*/
|
|
22
|
+
constructor(scope, id, props) {
|
|
23
|
+
super(scope, id);
|
|
24
|
+
this.bucket = new Bucket(this, id, {
|
|
25
|
+
...props.options?.bucketOptions,
|
|
26
|
+
/**
|
|
27
|
+
* Removal policy applied to the bucket
|
|
28
|
+
* Defaults to DESTROY if not explicitly defined
|
|
29
|
+
*/
|
|
30
|
+
removalPolicy: props.options?.bucketOptions?.removalPolicy || RemovalPolicy.DESTROY
|
|
31
|
+
});
|
|
32
|
+
new CfnOutput(this, "S3BucketArn", {
|
|
33
|
+
value: this.bucket.bucketArn
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
var BaseCloudfrontConstruct = class extends Construct {
|
|
38
|
+
static {
|
|
39
|
+
__name(this, "BaseCloudfrontConstruct");
|
|
40
|
+
}
|
|
41
|
+
/** The created CloudFront distribution instance */
|
|
42
|
+
distribution;
|
|
43
|
+
/**
|
|
44
|
+
* @param scope Parent construct
|
|
45
|
+
* @param id Unique construct identifier
|
|
46
|
+
* @param props Configuration for CloudFront distribution
|
|
47
|
+
*/
|
|
48
|
+
constructor(scope, id, props) {
|
|
49
|
+
super(scope, id);
|
|
50
|
+
this.distribution = new Distribution(this, id, {
|
|
51
|
+
...props.options?.cloudfrontOptions,
|
|
52
|
+
/**
|
|
53
|
+
* Default behaviour configuration
|
|
54
|
+
* Enforces HTTPS if not explicitly defined
|
|
55
|
+
*/
|
|
56
|
+
defaultBehavior: {
|
|
57
|
+
...props.options?.cloudfrontOptions?.defaultBehavior,
|
|
58
|
+
viewerProtocolPolicy: props.options?.cloudfrontOptions?.defaultBehavior?.viewerProtocolPolicy || ViewerProtocolPolicy.REDIRECT_TO_HTTPS
|
|
59
|
+
},
|
|
60
|
+
/**
|
|
61
|
+
* Error response configuration
|
|
62
|
+
*
|
|
63
|
+
* Adds SPA-friendly fallbacks:
|
|
64
|
+
* - 400, 403, 404 responses are redirected to index.html
|
|
65
|
+
*/
|
|
66
|
+
errorResponses: [
|
|
67
|
+
...props.options?.cloudfrontOptions?.errorResponses || [],
|
|
68
|
+
/** Handle 400 errors */
|
|
69
|
+
{
|
|
70
|
+
httpStatus: 400,
|
|
71
|
+
responseHttpStatus: 200,
|
|
72
|
+
responsePagePath: "/index.html",
|
|
73
|
+
ttl: Duration.days(1)
|
|
74
|
+
},
|
|
75
|
+
/** Handle 403 errors */
|
|
76
|
+
{
|
|
77
|
+
httpStatus: 403,
|
|
78
|
+
responseHttpStatus: 200,
|
|
79
|
+
responsePagePath: "/index.html",
|
|
80
|
+
ttl: Duration.days(1)
|
|
81
|
+
},
|
|
82
|
+
/** Handle 404 errors */
|
|
83
|
+
{
|
|
84
|
+
httpStatus: 404,
|
|
85
|
+
responseHttpStatus: 200,
|
|
86
|
+
responsePagePath: "/index.html",
|
|
87
|
+
ttl: Duration.days(1)
|
|
88
|
+
}
|
|
89
|
+
]
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
// src/aws/cdk/constructs/s3-deployment-construct.ts
|
|
95
|
+
var BaseS3DeploymentConstruct = class extends Construct {
|
|
96
|
+
static {
|
|
97
|
+
__name(this, "BaseS3DeploymentConstruct");
|
|
98
|
+
}
|
|
99
|
+
/** The created or provided S3 bucket */
|
|
100
|
+
bucket;
|
|
101
|
+
/** The created CloudFront distribution */
|
|
102
|
+
distribution;
|
|
103
|
+
/** S3 bucket deployment instance */
|
|
104
|
+
bucketDeployment;
|
|
105
|
+
/**
|
|
106
|
+
* @param scope Parent construct
|
|
107
|
+
* @param id Unique construct identifier
|
|
108
|
+
* @param props Configuration for bucket, distribution, and deployment
|
|
109
|
+
*/
|
|
110
|
+
constructor(scope, id, props) {
|
|
111
|
+
super(scope, id);
|
|
112
|
+
if (!props.options?.cloudfrontOptions?.defaultBehavior?.origin && !props?.withS3Bucket && props.withCloudfront) {
|
|
113
|
+
throw new CustomException(
|
|
114
|
+
"Cloudfront distribution S3_Bucket origins must be defined!"
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
if (!props.options?.bucketDeploymentOptions?.destinationBucket && !props?.withS3Bucket) {
|
|
118
|
+
throw new CustomException(
|
|
119
|
+
"Deployment S3_Bucket destination must be defined!"
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
if (props?.withS3Bucket) {
|
|
123
|
+
this.bucket = new BaseS3Construct(this, "bucket", {
|
|
124
|
+
enableDebug: props.enableDebug,
|
|
125
|
+
options: { bucketOptions: props.options?.bucketOptions }
|
|
126
|
+
}).bucket;
|
|
127
|
+
}
|
|
128
|
+
if (props?.withCloudfront) {
|
|
129
|
+
const s3Origin = props.options?.cloudfrontOptions?.defaultBehavior?.origin || S3BucketOrigin.withOriginAccessControl(this.bucket);
|
|
130
|
+
this.distribution = new BaseCloudfrontConstruct(this, "distribution", {
|
|
131
|
+
enableDebug: props.enableDebug,
|
|
132
|
+
options: {
|
|
133
|
+
cloudfrontOptions: {
|
|
134
|
+
...props.options?.cloudfrontOptions,
|
|
135
|
+
/**
|
|
136
|
+
* Map additional behaviors and ensure origin is assigned
|
|
137
|
+
*/
|
|
138
|
+
additionalBehaviors: Object.entries(
|
|
139
|
+
props.options?.cloudfrontOptions?.additionalBehaviors || {}
|
|
140
|
+
).reduce(
|
|
141
|
+
(behavior, [pattern, behaviorOptions]) => {
|
|
142
|
+
behavior[pattern] = {
|
|
143
|
+
...behaviorOptions,
|
|
144
|
+
origin: behaviorOptions.origin || s3Origin
|
|
145
|
+
};
|
|
146
|
+
return behavior;
|
|
147
|
+
},
|
|
148
|
+
{}
|
|
149
|
+
),
|
|
150
|
+
/**
|
|
151
|
+
* Default behavior configuration
|
|
152
|
+
*/
|
|
153
|
+
defaultBehavior: {
|
|
154
|
+
...props.options?.cloudfrontOptions?.defaultBehavior,
|
|
155
|
+
origin: s3Origin
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}).distribution;
|
|
160
|
+
}
|
|
161
|
+
this.bucketDeployment = new BucketDeployment(this, "deployment", {
|
|
162
|
+
...props.options?.bucketDeploymentOptions,
|
|
163
|
+
/** Target distribution for cache invalidation */
|
|
164
|
+
distribution: props.options?.bucketDeploymentOptions?.distribution || this.distribution,
|
|
165
|
+
/** Paths to invalidate after deployment */
|
|
166
|
+
distributionPaths: props.options?.bucketDeploymentOptions?.distributionPaths || ["/*"],
|
|
167
|
+
/** Destination S3 bucket */
|
|
168
|
+
destinationBucket: props.options?.bucketDeploymentOptions?.destinationBucket || this.bucket
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
export { BaseS3DeploymentConstruct };
|
|
174
|
+
//# sourceMappingURL=s3-deployment.js.map
|
|
175
|
+
//# sourceMappingURL=s3-deployment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/aws/cdk/constructs/s3-construct.ts","../../src/aws/cdk/constructs/cloudfront-construct.ts","../../src/aws/cdk/constructs/s3-deployment-construct.ts"],"names":["Construct"],"mappings":"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","file":"s3-deployment.js","sourcesContent":["import { Construct } from 'constructs';\nimport { CfnOutput, RemovalPolicy } from 'aws-cdk-lib';\nimport { Bucket, BucketProps } from 'aws-cdk-lib/aws-s3';\n\nimport { IBaseCdkConstructProps } from '../../types';\n\n/**\n * Props for BaseS3Construct\n *\n * Provides configuration for creating an S3 bucket\n * with optional overrides for bucket properties.\n */\ninterface IS3DeploymentConstructProps extends Omit<\n\tIBaseCdkConstructProps<{\n\t\t/** Configuration options for the S3 bucket */\n\t\treadonly bucketOptions?: BucketProps;\n\t}>,\n\t'appName' | 'stackName'\n> {}\n\n/**\n * CDK construct for S3 bucket\n *\n * Responsibilities:\n * - Creates an S3 bucket with configurable options\n * - Applies a default removal policy if not provided\n * - Exposes the bucket ARN as a CloudFormation output\n */\nexport class BaseS3Construct extends Construct {\n\t/** The created S3 bucket instance */\n\treadonly bucket: Bucket;\n\n\t/**\n\t * @param scope Parent construct\n\t * @param id Unique construct identifier\n\t * @param props Configuration for S3 bucket\n\t */\n\tconstructor(\n\t\tscope: Construct,\n\t\tid: string,\n\t\tprops: IS3DeploymentConstructProps,\n\t) {\n\t\tsuper(scope, id);\n\n\t\tthis.bucket = new Bucket(this, id, {\n\t\t\t...props.options?.bucketOptions,\n\n\t\t\t/**\n\t\t\t * Removal policy applied to the bucket\n\t\t\t * Defaults to DESTROY if not explicitly defined\n\t\t\t */\n\t\t\tremovalPolicy:\n\t\t\t\tprops.options?.bucketOptions?.removalPolicy || RemovalPolicy.DESTROY,\n\t\t});\n\n\t\t/**\n\t\t * CloudFormation output exposing the S3 bucket ARN\n\t\t */\n\t\tnew CfnOutput(this, 'S3BucketArn', {\n\t\t\tvalue: this.bucket.bucketArn,\n\t\t});\n\t}\n}\n","import { Construct } from 'constructs';\nimport { Duration } from 'aws-cdk-lib';\nimport {\n\tDistribution,\n\tDistributionProps,\n\tViewerProtocolPolicy,\n} from 'aws-cdk-lib/aws-cloudfront';\n\nimport { IBaseCdkConstructProps } from '../../types';\n\n/**\n * Props for BaseCloudfrontConstruct\n *\n * Provides configuration for creating a CloudFront distribution\n * with optional overrides for default behaviour and error handling.\n */\ninterface ICloudfrontConstructProps extends Omit<\n\tIBaseCdkConstructProps<{\n\t\t/** Partial configuration for the CloudFront distribution */\n\t\treadonly cloudfrontOptions: Partial<DistributionProps>;\n\t}>,\n\t'appName' | 'stage' | 'stackName'\n> {}\n\n/**\n * CDK construct for CloudFront distribution\n *\n * Responsibilities:\n * - Creates a CloudFront distribution with configurable options\n * - Enforces HTTPS redirection by default\n * - Adds fallback error responses for SPA routing (400, 403, 404 → index.html)\n */\nexport class BaseCloudfrontConstruct extends Construct {\n\t/** The created CloudFront distribution instance */\n\treadonly distribution: Distribution;\n\n\t/**\n\t * @param scope Parent construct\n\t * @param id Unique construct identifier\n\t * @param props Configuration for CloudFront distribution\n\t */\n\tconstructor(scope: Construct, id: string, props: ICloudfrontConstructProps) {\n\t\tsuper(scope, id);\n\n\t\tthis.distribution = new Distribution(this, id, {\n\t\t\t...props.options?.cloudfrontOptions,\n\n\t\t\t/**\n\t\t\t * Default behaviour configuration\n\t\t\t * Enforces HTTPS if not explicitly defined\n\t\t\t */\n\t\t\tdefaultBehavior: {\n\t\t\t\t...props.options?.cloudfrontOptions?.defaultBehavior,\n\t\t\t\tviewerProtocolPolicy:\n\t\t\t\t\tprops.options?.cloudfrontOptions?.defaultBehavior\n\t\t\t\t\t\t?.viewerProtocolPolicy || ViewerProtocolPolicy.REDIRECT_TO_HTTPS,\n\t\t\t},\n\n\t\t\t/**\n\t\t\t * Error response configuration\n\t\t\t *\n\t\t\t * Adds SPA-friendly fallbacks:\n\t\t\t * - 400, 403, 404 responses are redirected to index.html\n\t\t\t */\n\t\t\terrorResponses: [\n\t\t\t\t...(props.options?.cloudfrontOptions?.errorResponses || []),\n\n\t\t\t\t/** Handle 400 errors */\n\t\t\t\t{\n\t\t\t\t\thttpStatus: 400,\n\t\t\t\t\tresponseHttpStatus: 200,\n\t\t\t\t\tresponsePagePath: '/index.html',\n\t\t\t\t\tttl: Duration.days(1),\n\t\t\t\t},\n\n\t\t\t\t/** Handle 403 errors */\n\t\t\t\t{\n\t\t\t\t\thttpStatus: 403,\n\t\t\t\t\tresponseHttpStatus: 200,\n\t\t\t\t\tresponsePagePath: '/index.html',\n\t\t\t\t\tttl: Duration.days(1),\n\t\t\t\t},\n\n\t\t\t\t/** Handle 404 errors */\n\t\t\t\t{\n\t\t\t\t\thttpStatus: 404,\n\t\t\t\t\tresponseHttpStatus: 200,\n\t\t\t\t\tresponsePagePath: '/index.html',\n\t\t\t\t\tttl: Duration.days(1),\n\t\t\t\t},\n\t\t\t],\n\t\t});\n\t}\n}\n","import { Construct } from 'constructs';\nimport { Bucket, BucketProps } from 'aws-cdk-lib/aws-s3';\nimport { S3BucketOrigin } from 'aws-cdk-lib/aws-cloudfront-origins';\nimport {\n\tBucketDeployment,\n\tBucketDeploymentProps,\n} from 'aws-cdk-lib/aws-s3-deployment';\nimport {\n\tBehaviorOptions,\n\tDistribution,\n\tDistributionProps,\n} from 'aws-cdk-lib/aws-cloudfront';\n\nimport { ObjectType, CustomException } from '@incloodsolutions/toolkit';\n\nimport { BaseS3Construct } from './s3-construct';\nimport { BaseCloudfrontConstruct } from './cloudfront-construct';\n\nimport { IBaseCdkConstructProps } from '../../types';\n\n/**\n * Props for BaseS3DeploymentConstruct\n *\n * Provides configuration for:\n * - Optional S3 bucket creation\n * - Optional CloudFront distribution\n * - S3 bucket deployment\n */\ninterface IS3DeploymentConstructProps extends Omit<\n\tIBaseCdkConstructProps<{\n\t\t/** Configuration options for S3 bucket */\n\t\treadonly bucketOptions?: BucketProps;\n\n\t\t/**\n\t\t * Configuration options for CloudFront distribution\n\t\t *\n\t\t * Note:\n\t\t * - `additionalBehaviors` supports dynamic route mappings\n\t\t * - Origins are automatically resolved if not provided\n\t\t */\n\t\treadonly cloudfrontOptions?: Partial<\n\t\t\tOmit<DistributionProps, 'additionalBehaviors'>\n\t\t> & {\n\t\t\treadonly additionalBehaviors?: ObjectType<\n\t\t\t\tPartial<BehaviorOptions>,\n\t\t\t\tstring\n\t\t\t>;\n\t\t};\n\n\t\t/**\n\t\t * Configuration for S3 bucket deployment\n\t\t *\n\t\t * Note:\n\t\t * - `sources` is required\n\t\t * - `destinationBucket` can be auto-resolved\n\t\t */\n\t\treadonly bucketDeploymentOptions: Omit<\n\t\t\tPartial<BucketDeploymentProps>,\n\t\t\t'sources'\n\t\t> &\n\t\t\tPick<BucketDeploymentProps, 'sources'>;\n\t}>,\n\t'appName' | 'stackName'\n> {\n\t/** Whether to create a new S3 bucket */\n\treadonly withS3Bucket?: boolean;\n\n\t/** Whether to create a CloudFront distribution */\n\treadonly withCloudfront?: boolean;\n}\n\n/**\n * CDK construct for S3 deployment with optional CloudFront integration\n *\n * Responsibilities:\n * - Optionally creates an S3 bucket\n * - Optionally creates a CloudFront distribution with S3 origin\n * - Deploys assets to S3 bucket\n * - Configures CloudFront invalidation paths\n *\n * Behaviour:\n * - Automatically links S3 bucket as CloudFront origin when enabled\n * - Resolves destination bucket and distribution if not explicitly provided\n * - Throws when required dependencies are missing\n */\nexport class BaseS3DeploymentConstruct extends Construct {\n\t/** The created or provided S3 bucket */\n\treadonly bucket: Bucket;\n\n\t/** The created CloudFront distribution */\n\treadonly distribution: Distribution;\n\n\t/** S3 bucket deployment instance */\n\treadonly bucketDeployment: BucketDeployment;\n\n\t/**\n\t * @param scope Parent construct\n\t * @param id Unique construct identifier\n\t * @param props Configuration for bucket, distribution, and deployment\n\t */\n\tconstructor(\n\t\tscope: Construct,\n\t\tid: string,\n\t\tprops: IS3DeploymentConstructProps,\n\t) {\n\t\tsuper(scope, id);\n\n\t\t/**\n\t\t * Validate CloudFront origin requirements\n\t\t */\n\t\tif (\n\t\t\t!props.options?.cloudfrontOptions?.defaultBehavior?.origin &&\n\t\t\t!props?.withS3Bucket &&\n\t\t\tprops.withCloudfront\n\t\t) {\n\t\t\tthrow new CustomException(\n\t\t\t\t'Cloudfront distribution S3_Bucket origins must be defined!',\n\t\t\t);\n\t\t}\n\n\t\t/**\n\t\t * Validate deployment destination requirements\n\t\t */\n\t\tif (\n\t\t\t!props.options?.bucketDeploymentOptions?.destinationBucket &&\n\t\t\t!props?.withS3Bucket\n\t\t) {\n\t\t\tthrow new CustomException(\n\t\t\t\t'Deployment S3_Bucket destination must be defined!',\n\t\t\t);\n\t\t}\n\n\t\t/**\n\t\t * Create S3 bucket if enabled\n\t\t */\n\t\tif (props?.withS3Bucket) {\n\t\t\tthis.bucket = new BaseS3Construct(this, 'bucket', {\n\t\t\t\tenableDebug: props.enableDebug,\n\t\t\t\toptions: { bucketOptions: props.options?.bucketOptions },\n\t\t\t}).bucket;\n\t\t}\n\n\t\t/**\n\t\t * Create CloudFront distribution if enabled\n\t\t */\n\t\tif (props?.withCloudfront) {\n\t\t\t/**\n\t\t\t * Resolve S3 origin for distribution\n\t\t\t */\n\t\t\tconst s3Origin =\n\t\t\t\tprops.options?.cloudfrontOptions?.defaultBehavior?.origin ||\n\t\t\t\tS3BucketOrigin.withOriginAccessControl(this.bucket);\n\n\t\t\tthis.distribution = new BaseCloudfrontConstruct(this, 'distribution', {\n\t\t\t\tenableDebug: props.enableDebug,\n\t\t\t\toptions: {\n\t\t\t\t\tcloudfrontOptions: {\n\t\t\t\t\t\t...props.options?.cloudfrontOptions,\n\n\t\t\t\t\t\t/**\n\t\t\t\t\t\t * Map additional behaviors and ensure origin is assigned\n\t\t\t\t\t\t */\n\t\t\t\t\t\tadditionalBehaviors: Object.entries(\n\t\t\t\t\t\t\tprops.options?.cloudfrontOptions?.additionalBehaviors || {},\n\t\t\t\t\t\t).reduce(\n\t\t\t\t\t\t\t(behavior, [pattern, behaviorOptions]) => {\n\t\t\t\t\t\t\t\tbehavior[pattern] = {\n\t\t\t\t\t\t\t\t\t...behaviorOptions,\n\t\t\t\t\t\t\t\t\torigin: behaviorOptions.origin || s3Origin,\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\treturn behavior;\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{} as typeof props.options.cloudfrontOptions.additionalBehaviors,\n\t\t\t\t\t\t) as ObjectType<BehaviorOptions>,\n\n\t\t\t\t\t\t/**\n\t\t\t\t\t\t * Default behavior configuration\n\t\t\t\t\t\t */\n\t\t\t\t\t\tdefaultBehavior: {\n\t\t\t\t\t\t\t...props.options?.cloudfrontOptions?.defaultBehavior,\n\t\t\t\t\t\t\torigin: s3Origin,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t}).distribution;\n\t\t}\n\n\t\t/**\n\t\t * Deploy assets to S3 bucket\n\t\t *\n\t\t * Automatically resolves:\n\t\t * - Destination bucket\n\t\t * - CloudFront distribution\n\t\t * - Invalidation paths\n\t\t */\n\t\tthis.bucketDeployment = new BucketDeployment(this, 'deployment', {\n\t\t\t...props.options?.bucketDeploymentOptions,\n\n\t\t\t/** Target distribution for cache invalidation */\n\t\t\tdistribution:\n\t\t\t\tprops.options?.bucketDeploymentOptions?.distribution ||\n\t\t\t\tthis.distribution,\n\n\t\t\t/** Paths to invalidate after deployment */\n\t\t\tdistributionPaths: props.options?.bucketDeploymentOptions\n\t\t\t\t?.distributionPaths || ['/*'],\n\n\t\t\t/** Destination S3 bucket */\n\t\t\tdestinationBucket:\n\t\t\t\tprops.options?.bucketDeploymentOptions?.destinationBucket ||\n\t\t\t\tthis.bucket,\n\t\t} as BucketDeploymentProps);\n\t}\n}\n"]}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var constructs = require('constructs');
|
|
4
|
+
var awsCdkLib = require('aws-cdk-lib');
|
|
5
|
+
var awsS3 = require('aws-cdk-lib/aws-s3');
|
|
6
|
+
|
|
7
|
+
var __defProp = Object.defineProperty;
|
|
8
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
9
|
+
var BaseS3Construct = class extends constructs.Construct {
|
|
10
|
+
static {
|
|
11
|
+
__name(this, "BaseS3Construct");
|
|
12
|
+
}
|
|
13
|
+
/** The created S3 bucket instance */
|
|
14
|
+
bucket;
|
|
15
|
+
/**
|
|
16
|
+
* @param scope Parent construct
|
|
17
|
+
* @param id Unique construct identifier
|
|
18
|
+
* @param props Configuration for S3 bucket
|
|
19
|
+
*/
|
|
20
|
+
constructor(scope, id, props) {
|
|
21
|
+
super(scope, id);
|
|
22
|
+
this.bucket = new awsS3.Bucket(this, id, {
|
|
23
|
+
...props.options?.bucketOptions,
|
|
24
|
+
/**
|
|
25
|
+
* Removal policy applied to the bucket
|
|
26
|
+
* Defaults to DESTROY if not explicitly defined
|
|
27
|
+
*/
|
|
28
|
+
removalPolicy: props.options?.bucketOptions?.removalPolicy || awsCdkLib.RemovalPolicy.DESTROY
|
|
29
|
+
});
|
|
30
|
+
new awsCdkLib.CfnOutput(this, "S3BucketArn", {
|
|
31
|
+
value: this.bucket.bucketArn
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
exports.BaseS3Construct = BaseS3Construct;
|
|
37
|
+
//# sourceMappingURL=s3.cjs.map
|
|
38
|
+
//# sourceMappingURL=s3.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/aws/cdk/constructs/s3-construct.ts"],"names":["Construct","Bucket","RemovalPolicy","CfnOutput"],"mappings":";;;;;;;;AA4BO,IAAM,eAAA,GAAN,cAA8BA,oBAAA,CAAU;AAAA,EA5B/C;AA4B+C,IAAA,MAAA,CAAA,IAAA,EAAA,iBAAA,CAAA;AAAA;AAAA;AAAA,EAErC,MAAA;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,MAAA,GAAS,IAAIC,YAAA,CAAO,IAAA,EAAM,EAAA,EAAI;AAAA,MAClC,GAAG,MAAM,OAAA,EAAS,aAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAMlB,aAAA,EACC,KAAA,CAAM,OAAA,EAAS,aAAA,EAAe,iBAAiBC,uBAAA,CAAc;AAAA,KAC9D,CAAA;AAKD,IAAA,IAAIC,mBAAA,CAAU,MAAM,aAAA,EAAe;AAAA,MAClC,KAAA,EAAO,KAAK,MAAA,CAAO;AAAA,KACnB,CAAA;AAAA,EACF;AACD","file":"s3.cjs","sourcesContent":["import { Construct } from 'constructs';\nimport { CfnOutput, RemovalPolicy } from 'aws-cdk-lib';\nimport { Bucket, BucketProps } from 'aws-cdk-lib/aws-s3';\n\nimport { IBaseCdkConstructProps } from '../../types';\n\n/**\n * Props for BaseS3Construct\n *\n * Provides configuration for creating an S3 bucket\n * with optional overrides for bucket properties.\n */\ninterface IS3DeploymentConstructProps extends Omit<\n\tIBaseCdkConstructProps<{\n\t\t/** Configuration options for the S3 bucket */\n\t\treadonly bucketOptions?: BucketProps;\n\t}>,\n\t'appName' | 'stackName'\n> {}\n\n/**\n * CDK construct for S3 bucket\n *\n * Responsibilities:\n * - Creates an S3 bucket with configurable options\n * - Applies a default removal policy if not provided\n * - Exposes the bucket ARN as a CloudFormation output\n */\nexport class BaseS3Construct extends Construct {\n\t/** The created S3 bucket instance */\n\treadonly bucket: Bucket;\n\n\t/**\n\t * @param scope Parent construct\n\t * @param id Unique construct identifier\n\t * @param props Configuration for S3 bucket\n\t */\n\tconstructor(\n\t\tscope: Construct,\n\t\tid: string,\n\t\tprops: IS3DeploymentConstructProps,\n\t) {\n\t\tsuper(scope, id);\n\n\t\tthis.bucket = new Bucket(this, id, {\n\t\t\t...props.options?.bucketOptions,\n\n\t\t\t/**\n\t\t\t * Removal policy applied to the bucket\n\t\t\t * Defaults to DESTROY if not explicitly defined\n\t\t\t */\n\t\t\tremovalPolicy:\n\t\t\t\tprops.options?.bucketOptions?.removalPolicy || RemovalPolicy.DESTROY,\n\t\t});\n\n\t\t/**\n\t\t * CloudFormation output exposing the S3 bucket ARN\n\t\t */\n\t\tnew CfnOutput(this, 'S3BucketArn', {\n\t\t\tvalue: this.bucket.bucketArn,\n\t\t});\n\t}\n}\n"]}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Construct } from 'constructs';
|
|
2
|
+
import { Bucket, BucketProps } from 'aws-cdk-lib/aws-s3';
|
|
3
|
+
import { IBaseCdkConstructProps } from '../aws-types.cjs';
|
|
4
|
+
import '@incloodsolutions/toolkit';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Props for BaseS3Construct
|
|
8
|
+
*
|
|
9
|
+
* Provides configuration for creating an S3 bucket
|
|
10
|
+
* with optional overrides for bucket properties.
|
|
11
|
+
*/
|
|
12
|
+
interface IS3DeploymentConstructProps extends Omit<IBaseCdkConstructProps<{
|
|
13
|
+
/** Configuration options for the S3 bucket */
|
|
14
|
+
readonly bucketOptions?: BucketProps;
|
|
15
|
+
}>, 'appName' | 'stackName'> {
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* CDK construct for S3 bucket
|
|
19
|
+
*
|
|
20
|
+
* Responsibilities:
|
|
21
|
+
* - Creates an S3 bucket with configurable options
|
|
22
|
+
* - Applies a default removal policy if not provided
|
|
23
|
+
* - Exposes the bucket ARN as a CloudFormation output
|
|
24
|
+
*/
|
|
25
|
+
declare class BaseS3Construct extends Construct {
|
|
26
|
+
/** The created S3 bucket instance */
|
|
27
|
+
readonly bucket: Bucket;
|
|
28
|
+
/**
|
|
29
|
+
* @param scope Parent construct
|
|
30
|
+
* @param id Unique construct identifier
|
|
31
|
+
* @param props Configuration for S3 bucket
|
|
32
|
+
*/
|
|
33
|
+
constructor(scope: Construct, id: string, props: IS3DeploymentConstructProps);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export { BaseS3Construct };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Construct } from 'constructs';
|
|
2
|
+
import { Bucket, BucketProps } from 'aws-cdk-lib/aws-s3';
|
|
3
|
+
import { IBaseCdkConstructProps } from '../aws-types.js';
|
|
4
|
+
import '@incloodsolutions/toolkit';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Props for BaseS3Construct
|
|
8
|
+
*
|
|
9
|
+
* Provides configuration for creating an S3 bucket
|
|
10
|
+
* with optional overrides for bucket properties.
|
|
11
|
+
*/
|
|
12
|
+
interface IS3DeploymentConstructProps extends Omit<IBaseCdkConstructProps<{
|
|
13
|
+
/** Configuration options for the S3 bucket */
|
|
14
|
+
readonly bucketOptions?: BucketProps;
|
|
15
|
+
}>, 'appName' | 'stackName'> {
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* CDK construct for S3 bucket
|
|
19
|
+
*
|
|
20
|
+
* Responsibilities:
|
|
21
|
+
* - Creates an S3 bucket with configurable options
|
|
22
|
+
* - Applies a default removal policy if not provided
|
|
23
|
+
* - Exposes the bucket ARN as a CloudFormation output
|
|
24
|
+
*/
|
|
25
|
+
declare class BaseS3Construct extends Construct {
|
|
26
|
+
/** The created S3 bucket instance */
|
|
27
|
+
readonly bucket: Bucket;
|
|
28
|
+
/**
|
|
29
|
+
* @param scope Parent construct
|
|
30
|
+
* @param id Unique construct identifier
|
|
31
|
+
* @param props Configuration for S3 bucket
|
|
32
|
+
*/
|
|
33
|
+
constructor(scope: Construct, id: string, props: IS3DeploymentConstructProps);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export { BaseS3Construct };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Construct } from 'constructs';
|
|
2
|
+
import { RemovalPolicy, CfnOutput } from 'aws-cdk-lib';
|
|
3
|
+
import { Bucket } from 'aws-cdk-lib/aws-s3';
|
|
4
|
+
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
+
var BaseS3Construct = class extends Construct {
|
|
8
|
+
static {
|
|
9
|
+
__name(this, "BaseS3Construct");
|
|
10
|
+
}
|
|
11
|
+
/** The created S3 bucket instance */
|
|
12
|
+
bucket;
|
|
13
|
+
/**
|
|
14
|
+
* @param scope Parent construct
|
|
15
|
+
* @param id Unique construct identifier
|
|
16
|
+
* @param props Configuration for S3 bucket
|
|
17
|
+
*/
|
|
18
|
+
constructor(scope, id, props) {
|
|
19
|
+
super(scope, id);
|
|
20
|
+
this.bucket = new Bucket(this, id, {
|
|
21
|
+
...props.options?.bucketOptions,
|
|
22
|
+
/**
|
|
23
|
+
* Removal policy applied to the bucket
|
|
24
|
+
* Defaults to DESTROY if not explicitly defined
|
|
25
|
+
*/
|
|
26
|
+
removalPolicy: props.options?.bucketOptions?.removalPolicy || RemovalPolicy.DESTROY
|
|
27
|
+
});
|
|
28
|
+
new CfnOutput(this, "S3BucketArn", {
|
|
29
|
+
value: this.bucket.bucketArn
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export { BaseS3Construct };
|
|
35
|
+
//# sourceMappingURL=s3.js.map
|
|
36
|
+
//# sourceMappingURL=s3.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/aws/cdk/constructs/s3-construct.ts"],"names":[],"mappings":";;;;;;AA4BO,IAAM,eAAA,GAAN,cAA8B,SAAA,CAAU;AAAA,EA5B/C;AA4B+C,IAAA,MAAA,CAAA,IAAA,EAAA,iBAAA,CAAA;AAAA;AAAA;AAAA,EAErC,MAAA;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,MAAA,GAAS,IAAI,MAAA,CAAO,IAAA,EAAM,EAAA,EAAI;AAAA,MAClC,GAAG,MAAM,OAAA,EAAS,aAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAMlB,aAAA,EACC,KAAA,CAAM,OAAA,EAAS,aAAA,EAAe,iBAAiB,aAAA,CAAc;AAAA,KAC9D,CAAA;AAKD,IAAA,IAAI,SAAA,CAAU,MAAM,aAAA,EAAe;AAAA,MAClC,KAAA,EAAO,KAAK,MAAA,CAAO;AAAA,KACnB,CAAA;AAAA,EACF;AACD","file":"s3.js","sourcesContent":["import { Construct } from 'constructs';\nimport { CfnOutput, RemovalPolicy } from 'aws-cdk-lib';\nimport { Bucket, BucketProps } from 'aws-cdk-lib/aws-s3';\n\nimport { IBaseCdkConstructProps } from '../../types';\n\n/**\n * Props for BaseS3Construct\n *\n * Provides configuration for creating an S3 bucket\n * with optional overrides for bucket properties.\n */\ninterface IS3DeploymentConstructProps extends Omit<\n\tIBaseCdkConstructProps<{\n\t\t/** Configuration options for the S3 bucket */\n\t\treadonly bucketOptions?: BucketProps;\n\t}>,\n\t'appName' | 'stackName'\n> {}\n\n/**\n * CDK construct for S3 bucket\n *\n * Responsibilities:\n * - Creates an S3 bucket with configurable options\n * - Applies a default removal policy if not provided\n * - Exposes the bucket ARN as a CloudFormation output\n */\nexport class BaseS3Construct extends Construct {\n\t/** The created S3 bucket instance */\n\treadonly bucket: Bucket;\n\n\t/**\n\t * @param scope Parent construct\n\t * @param id Unique construct identifier\n\t * @param props Configuration for S3 bucket\n\t */\n\tconstructor(\n\t\tscope: Construct,\n\t\tid: string,\n\t\tprops: IS3DeploymentConstructProps,\n\t) {\n\t\tsuper(scope, id);\n\n\t\tthis.bucket = new Bucket(this, id, {\n\t\t\t...props.options?.bucketOptions,\n\n\t\t\t/**\n\t\t\t * Removal policy applied to the bucket\n\t\t\t * Defaults to DESTROY if not explicitly defined\n\t\t\t */\n\t\t\tremovalPolicy:\n\t\t\t\tprops.options?.bucketOptions?.removalPolicy || RemovalPolicy.DESTROY,\n\t\t});\n\n\t\t/**\n\t\t * CloudFormation output exposing the S3 bucket ARN\n\t\t */\n\t\tnew CfnOutput(this, 'S3BucketArn', {\n\t\t\tvalue: this.bucket.bucketArn,\n\t\t});\n\t}\n}\n"]}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var constructs = require('constructs');
|
|
4
|
+
var awsCdkLib = require('aws-cdk-lib');
|
|
5
|
+
var awsSns = require('aws-cdk-lib/aws-sns');
|
|
6
|
+
var awsSnsSubscriptions = require('aws-cdk-lib/aws-sns-subscriptions');
|
|
7
|
+
|
|
8
|
+
var __defProp = Object.defineProperty;
|
|
9
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
10
|
+
var BaseSnsConstruct = class extends constructs.Construct {
|
|
11
|
+
static {
|
|
12
|
+
__name(this, "BaseSnsConstruct");
|
|
13
|
+
}
|
|
14
|
+
/** The created SNS topic instance */
|
|
15
|
+
topic;
|
|
16
|
+
/**
|
|
17
|
+
* @param scope Parent construct
|
|
18
|
+
* @param id Unique construct identifier
|
|
19
|
+
* @param props Configuration for topic and subscriptions
|
|
20
|
+
*/
|
|
21
|
+
constructor(scope, id, props) {
|
|
22
|
+
super(scope, id);
|
|
23
|
+
this.topic = new awsSns.Topic(this, id, props.options?.topicOptions);
|
|
24
|
+
if (props.options?.targetFunctions?.length) {
|
|
25
|
+
props.options.targetFunctions.forEach((targetFunction) => {
|
|
26
|
+
this.topic.addSubscription(
|
|
27
|
+
/**
|
|
28
|
+
* Lambda subscription target
|
|
29
|
+
*/
|
|
30
|
+
new awsSnsSubscriptions.LambdaSubscription(targetFunction)
|
|
31
|
+
);
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
this.topic.applyRemovalPolicy(awsCdkLib.RemovalPolicy.DESTROY);
|
|
35
|
+
new awsCdkLib.CfnOutput(this, "SnsTopicArn", {
|
|
36
|
+
value: this.topic.topicArn
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
exports.BaseSnsConstruct = BaseSnsConstruct;
|
|
42
|
+
//# sourceMappingURL=sns.cjs.map
|
|
43
|
+
//# sourceMappingURL=sns.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/aws/cdk/constructs/sns-construct.ts"],"names":["Construct","Topic","LambdaSubscription","RemovalPolicy","CfnOutput"],"mappings":";;;;;;;;;AAuCO,IAAM,gBAAA,GAAN,cAA+BA,oBAAA,CAAU;AAAA,EAvChD;AAuCgD,IAAA,MAAA,CAAA,IAAA,EAAA,kBAAA,CAAA;AAAA;AAAA;AAAA,EAEtC,KAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOT,WAAA,CAAY,KAAA,EAAkB,EAAA,EAAY,KAAA,EAA2B;AACpE,IAAA,KAAA,CAAM,OAAO,EAAE,CAAA;AAEf,IAAA,IAAA,CAAK,QAAQ,IAAIC,YAAA,CAAM,MAAM,EAAA,EAAI,KAAA,CAAM,SAAS,YAAY,CAAA;AAK5D,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,KAAA,CAAM,eAAA;AAAA;AAAA;AAAA;AAAA,UAIV,IAAIC,uCAAmB,cAAc;AAAA,SACtC;AAAA,MACD,CAAC,CAAA;AAAA,IACF;AAKA,IAAA,IAAA,CAAK,KAAA,CAAM,kBAAA,CAAmBC,uBAAA,CAAc,OAAO,CAAA;AAKnD,IAAA,IAAIC,mBAAA,CAAU,MAAM,aAAA,EAAe;AAAA,MAClC,KAAA,EAAO,KAAK,KAAA,CAAM;AAAA,KAClB,CAAA;AAAA,EACF;AACD","file":"sns.cjs","sourcesContent":["import { Construct } from 'constructs';\nimport { Function } from 'aws-cdk-lib/aws-lambda';\nimport { CfnOutput, RemovalPolicy } from 'aws-cdk-lib';\nimport { Topic, TopicProps } from 'aws-cdk-lib/aws-sns';\nimport { LambdaSubscription } from 'aws-cdk-lib/aws-sns-subscriptions';\n\nimport { IBaseCdkConstructProps } from '../../types';\n\n/**\n * Props for BaseSnsConstruct\n *\n * Provides configuration for:\n * - SNS topic creation\n * - Lambda subscriptions\n */\ninterface ISnsConstructProps extends Omit<\n\tIBaseCdkConstructProps<{\n\t\t/** SNS topic configuration options */\n\t\treadonly topicOptions: TopicProps;\n\n\t\t/**\n\t\t * Lambda functions to subscribe to the topic\n\t\t *\n\t\t * Each function will receive messages published to the topic\n\t\t */\n\t\treadonly targetFunctions: Function[];\n\t}>,\n\t'appName' | 'stage' | 'stackName'\n> {}\n\n/**\n * CDK construct for SNS topic with Lambda subscriptions\n *\n * Responsibilities:\n * - Creates an SNS topic with configurable options\n * - Subscribes one or more Lambda functions to the topic\n * - Applies a removal policy\n * - Exposes the topic ARN as a CloudFormation output\n */\nexport class BaseSnsConstruct extends Construct {\n\t/** The created SNS topic instance */\n\treadonly topic: Topic;\n\n\t/**\n\t * @param scope Parent construct\n\t * @param id Unique construct identifier\n\t * @param props Configuration for topic and subscriptions\n\t */\n\tconstructor(scope: Construct, id: string, props: ISnsConstructProps) {\n\t\tsuper(scope, id);\n\n\t\tthis.topic = new Topic(this, id, props.options?.topicOptions);\n\n\t\t/**\n\t\t * Attach Lambda subscriptions to the topic\n\t\t */\n\t\tif (props.options?.targetFunctions?.length) {\n\t\t\tprops.options.targetFunctions.forEach((targetFunction) => {\n\t\t\t\tthis.topic.addSubscription(\n\t\t\t\t\t/**\n\t\t\t\t\t * Lambda subscription target\n\t\t\t\t\t */\n\t\t\t\t\tnew LambdaSubscription(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.topic.applyRemovalPolicy(RemovalPolicy.DESTROY);\n\n\t\t/**\n\t\t * CloudFormation output exposing the topic ARN\n\t\t */\n\t\tnew CfnOutput(this, 'SnsTopicArn', {\n\t\t\tvalue: this.topic.topicArn,\n\t\t});\n\t}\n}\n"]}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Construct } from 'constructs';
|
|
2
|
+
import { Function } from 'aws-cdk-lib/aws-lambda';
|
|
3
|
+
import { Topic, TopicProps } from 'aws-cdk-lib/aws-sns';
|
|
4
|
+
import { IBaseCdkConstructProps } from '../aws-types.cjs';
|
|
5
|
+
import '@incloodsolutions/toolkit';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Props for BaseSnsConstruct
|
|
9
|
+
*
|
|
10
|
+
* Provides configuration for:
|
|
11
|
+
* - SNS topic creation
|
|
12
|
+
* - Lambda subscriptions
|
|
13
|
+
*/
|
|
14
|
+
interface ISnsConstructProps extends Omit<IBaseCdkConstructProps<{
|
|
15
|
+
/** SNS topic configuration options */
|
|
16
|
+
readonly topicOptions: TopicProps;
|
|
17
|
+
/**
|
|
18
|
+
* Lambda functions to subscribe to the topic
|
|
19
|
+
*
|
|
20
|
+
* Each function will receive messages published to the topic
|
|
21
|
+
*/
|
|
22
|
+
readonly targetFunctions: Function[];
|
|
23
|
+
}>, 'appName' | 'stage' | 'stackName'> {
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* CDK construct for SNS topic with Lambda subscriptions
|
|
27
|
+
*
|
|
28
|
+
* Responsibilities:
|
|
29
|
+
* - Creates an SNS topic with configurable options
|
|
30
|
+
* - Subscribes one or more Lambda functions to the topic
|
|
31
|
+
* - Applies a removal policy
|
|
32
|
+
* - Exposes the topic ARN as a CloudFormation output
|
|
33
|
+
*/
|
|
34
|
+
declare class BaseSnsConstruct extends Construct {
|
|
35
|
+
/** The created SNS topic instance */
|
|
36
|
+
readonly topic: Topic;
|
|
37
|
+
/**
|
|
38
|
+
* @param scope Parent construct
|
|
39
|
+
* @param id Unique construct identifier
|
|
40
|
+
* @param props Configuration for topic and subscriptions
|
|
41
|
+
*/
|
|
42
|
+
constructor(scope: Construct, id: string, props: ISnsConstructProps);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export { BaseSnsConstruct };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Construct } from 'constructs';
|
|
2
|
+
import { Function } from 'aws-cdk-lib/aws-lambda';
|
|
3
|
+
import { Topic, TopicProps } from 'aws-cdk-lib/aws-sns';
|
|
4
|
+
import { IBaseCdkConstructProps } from '../aws-types.js';
|
|
5
|
+
import '@incloodsolutions/toolkit';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Props for BaseSnsConstruct
|
|
9
|
+
*
|
|
10
|
+
* Provides configuration for:
|
|
11
|
+
* - SNS topic creation
|
|
12
|
+
* - Lambda subscriptions
|
|
13
|
+
*/
|
|
14
|
+
interface ISnsConstructProps extends Omit<IBaseCdkConstructProps<{
|
|
15
|
+
/** SNS topic configuration options */
|
|
16
|
+
readonly topicOptions: TopicProps;
|
|
17
|
+
/**
|
|
18
|
+
* Lambda functions to subscribe to the topic
|
|
19
|
+
*
|
|
20
|
+
* Each function will receive messages published to the topic
|
|
21
|
+
*/
|
|
22
|
+
readonly targetFunctions: Function[];
|
|
23
|
+
}>, 'appName' | 'stage' | 'stackName'> {
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* CDK construct for SNS topic with Lambda subscriptions
|
|
27
|
+
*
|
|
28
|
+
* Responsibilities:
|
|
29
|
+
* - Creates an SNS topic with configurable options
|
|
30
|
+
* - Subscribes one or more Lambda functions to the topic
|
|
31
|
+
* - Applies a removal policy
|
|
32
|
+
* - Exposes the topic ARN as a CloudFormation output
|
|
33
|
+
*/
|
|
34
|
+
declare class BaseSnsConstruct extends Construct {
|
|
35
|
+
/** The created SNS topic instance */
|
|
36
|
+
readonly topic: Topic;
|
|
37
|
+
/**
|
|
38
|
+
* @param scope Parent construct
|
|
39
|
+
* @param id Unique construct identifier
|
|
40
|
+
* @param props Configuration for topic and subscriptions
|
|
41
|
+
*/
|
|
42
|
+
constructor(scope: Construct, id: string, props: ISnsConstructProps);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export { BaseSnsConstruct };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Construct } from 'constructs';
|
|
2
|
+
import { RemovalPolicy, CfnOutput } from 'aws-cdk-lib';
|
|
3
|
+
import { Topic } from 'aws-cdk-lib/aws-sns';
|
|
4
|
+
import { LambdaSubscription } from 'aws-cdk-lib/aws-sns-subscriptions';
|
|
5
|
+
|
|
6
|
+
var __defProp = Object.defineProperty;
|
|
7
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
|
+
var BaseSnsConstruct = class extends Construct {
|
|
9
|
+
static {
|
|
10
|
+
__name(this, "BaseSnsConstruct");
|
|
11
|
+
}
|
|
12
|
+
/** The created SNS topic instance */
|
|
13
|
+
topic;
|
|
14
|
+
/**
|
|
15
|
+
* @param scope Parent construct
|
|
16
|
+
* @param id Unique construct identifier
|
|
17
|
+
* @param props Configuration for topic and subscriptions
|
|
18
|
+
*/
|
|
19
|
+
constructor(scope, id, props) {
|
|
20
|
+
super(scope, id);
|
|
21
|
+
this.topic = new Topic(this, id, props.options?.topicOptions);
|
|
22
|
+
if (props.options?.targetFunctions?.length) {
|
|
23
|
+
props.options.targetFunctions.forEach((targetFunction) => {
|
|
24
|
+
this.topic.addSubscription(
|
|
25
|
+
/**
|
|
26
|
+
* Lambda subscription target
|
|
27
|
+
*/
|
|
28
|
+
new LambdaSubscription(targetFunction)
|
|
29
|
+
);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
this.topic.applyRemovalPolicy(RemovalPolicy.DESTROY);
|
|
33
|
+
new CfnOutput(this, "SnsTopicArn", {
|
|
34
|
+
value: this.topic.topicArn
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export { BaseSnsConstruct };
|
|
40
|
+
//# sourceMappingURL=sns.js.map
|
|
41
|
+
//# sourceMappingURL=sns.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/aws/cdk/constructs/sns-construct.ts"],"names":[],"mappings":";;;;;;;AAuCO,IAAM,gBAAA,GAAN,cAA+B,SAAA,CAAU;AAAA,EAvChD;AAuCgD,IAAA,MAAA,CAAA,IAAA,EAAA,kBAAA,CAAA;AAAA;AAAA;AAAA,EAEtC,KAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOT,WAAA,CAAY,KAAA,EAAkB,EAAA,EAAY,KAAA,EAA2B;AACpE,IAAA,KAAA,CAAM,OAAO,EAAE,CAAA;AAEf,IAAA,IAAA,CAAK,QAAQ,IAAI,KAAA,CAAM,MAAM,EAAA,EAAI,KAAA,CAAM,SAAS,YAAY,CAAA;AAK5D,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,KAAA,CAAM,eAAA;AAAA;AAAA;AAAA;AAAA,UAIV,IAAI,mBAAmB,cAAc;AAAA,SACtC;AAAA,MACD,CAAC,CAAA;AAAA,IACF;AAKA,IAAA,IAAA,CAAK,KAAA,CAAM,kBAAA,CAAmB,aAAA,CAAc,OAAO,CAAA;AAKnD,IAAA,IAAI,SAAA,CAAU,MAAM,aAAA,EAAe;AAAA,MAClC,KAAA,EAAO,KAAK,KAAA,CAAM;AAAA,KAClB,CAAA;AAAA,EACF;AACD","file":"sns.js","sourcesContent":["import { Construct } from 'constructs';\nimport { Function } from 'aws-cdk-lib/aws-lambda';\nimport { CfnOutput, RemovalPolicy } from 'aws-cdk-lib';\nimport { Topic, TopicProps } from 'aws-cdk-lib/aws-sns';\nimport { LambdaSubscription } from 'aws-cdk-lib/aws-sns-subscriptions';\n\nimport { IBaseCdkConstructProps } from '../../types';\n\n/**\n * Props for BaseSnsConstruct\n *\n * Provides configuration for:\n * - SNS topic creation\n * - Lambda subscriptions\n */\ninterface ISnsConstructProps extends Omit<\n\tIBaseCdkConstructProps<{\n\t\t/** SNS topic configuration options */\n\t\treadonly topicOptions: TopicProps;\n\n\t\t/**\n\t\t * Lambda functions to subscribe to the topic\n\t\t *\n\t\t * Each function will receive messages published to the topic\n\t\t */\n\t\treadonly targetFunctions: Function[];\n\t}>,\n\t'appName' | 'stage' | 'stackName'\n> {}\n\n/**\n * CDK construct for SNS topic with Lambda subscriptions\n *\n * Responsibilities:\n * - Creates an SNS topic with configurable options\n * - Subscribes one or more Lambda functions to the topic\n * - Applies a removal policy\n * - Exposes the topic ARN as a CloudFormation output\n */\nexport class BaseSnsConstruct extends Construct {\n\t/** The created SNS topic instance */\n\treadonly topic: Topic;\n\n\t/**\n\t * @param scope Parent construct\n\t * @param id Unique construct identifier\n\t * @param props Configuration for topic and subscriptions\n\t */\n\tconstructor(scope: Construct, id: string, props: ISnsConstructProps) {\n\t\tsuper(scope, id);\n\n\t\tthis.topic = new Topic(this, id, props.options?.topicOptions);\n\n\t\t/**\n\t\t * Attach Lambda subscriptions to the topic\n\t\t */\n\t\tif (props.options?.targetFunctions?.length) {\n\t\t\tprops.options.targetFunctions.forEach((targetFunction) => {\n\t\t\t\tthis.topic.addSubscription(\n\t\t\t\t\t/**\n\t\t\t\t\t * Lambda subscription target\n\t\t\t\t\t */\n\t\t\t\t\tnew LambdaSubscription(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.topic.applyRemovalPolicy(RemovalPolicy.DESTROY);\n\n\t\t/**\n\t\t * CloudFormation output exposing the topic ARN\n\t\t */\n\t\tnew CfnOutput(this, 'SnsTopicArn', {\n\t\t\tvalue: this.topic.topicArn,\n\t\t});\n\t}\n}\n"]}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var constructs = require('constructs');
|
|
4
|
+
var awsCdkLib = require('aws-cdk-lib');
|
|
5
|
+
var awsSqs = require('aws-cdk-lib/aws-sqs');
|
|
6
|
+
var awsLambda = require('aws-cdk-lib/aws-lambda');
|
|
7
|
+
|
|
8
|
+
var __defProp = Object.defineProperty;
|
|
9
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
10
|
+
var BaseSqsConstruct = class extends constructs.Construct {
|
|
11
|
+
static {
|
|
12
|
+
__name(this, "BaseSqsConstruct");
|
|
13
|
+
}
|
|
14
|
+
/** The created SQS queue instance */
|
|
15
|
+
queue;
|
|
16
|
+
/**
|
|
17
|
+
* @param scope Parent construct
|
|
18
|
+
* @param id Unique construct identifier
|
|
19
|
+
* @param props Configuration for queue and Lambda consumers
|
|
20
|
+
*/
|
|
21
|
+
constructor(scope, id, props) {
|
|
22
|
+
super(scope, id);
|
|
23
|
+
this.queue = new awsSqs.Queue(this, id, {
|
|
24
|
+
...props?.options?.queueOptions,
|
|
25
|
+
/**
|
|
26
|
+
* Removal policy applied to the queue
|
|
27
|
+
* Defaults to DESTROY if not explicitly defined
|
|
28
|
+
*/
|
|
29
|
+
removalPolicy: props?.options?.queueOptions?.removalPolicy || awsCdkLib.RemovalPolicy.DESTROY
|
|
30
|
+
});
|
|
31
|
+
if (props?.targetFunctions?.length) {
|
|
32
|
+
props.targetFunctions.forEach((targetFunction, index) => {
|
|
33
|
+
new awsLambda.EventSourceMapping(this, `${id}-eventSourceMap${index + 1}`, {
|
|
34
|
+
...props?.options?.eventSourceMappingOptions,
|
|
35
|
+
/** Target Lambda function */
|
|
36
|
+
target: targetFunction,
|
|
37
|
+
/** Source SQS queue ARN */
|
|
38
|
+
eventSourceArn: this.queue.queueArn,
|
|
39
|
+
/**
|
|
40
|
+
* Retry attempts for failed batch processing
|
|
41
|
+
* Defaults to 3 if not explicitly defined
|
|
42
|
+
*/
|
|
43
|
+
retryAttempts: props?.options?.eventSourceMappingOptions?.retryAttempts || 3
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
new awsCdkLib.CfnOutput(this, "SqsQueueArn", {
|
|
48
|
+
value: this.queue.queueArn
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
exports.BaseSqsConstruct = BaseSqsConstruct;
|
|
54
|
+
//# sourceMappingURL=sqs.cjs.map
|
|
55
|
+
//# sourceMappingURL=sqs.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/aws/cdk/constructs/sqs-construct.ts"],"names":["Construct","Queue","RemovalPolicy","EventSourceMapping","CfnOutput"],"mappings":";;;;;;;;;AAqDO,IAAM,gBAAA,GAAN,cAA+BA,oBAAA,CAAU;AAAA,EArDhD;AAqDgD,IAAA,MAAA,CAAA,IAAA,EAAA,kBAAA,CAAA;AAAA;AAAA;AAAA,EAEtC,KAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOT,WAAA,CAAY,KAAA,EAAkB,EAAA,EAAY,KAAA,EAA2B;AACpE,IAAA,KAAA,CAAM,OAAO,EAAE,CAAA;AAEf,IAAA,IAAA,CAAK,KAAA,GAAQ,IAAIC,YAAA,CAAM,IAAA,EAAM,EAAA,EAAI;AAAA,MAChC,GAAG,OAAO,OAAA,EAAS,YAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAMnB,aAAA,EACC,KAAA,EAAO,OAAA,EAAS,YAAA,EAAc,iBAAiBC,uBAAA,CAAc;AAAA,KAC9D,CAAA;AAKD,IAAA,IAAI,KAAA,EAAO,iBAAiB,MAAA,EAAQ;AACnC,MAAA,KAAA,CAAM,eAAA,CAAgB,OAAA,CAAQ,CAAC,cAAA,EAAgB,KAAA,KAAU;AACxD,QAAA,IAAIC,6BAAmB,IAAA,EAAM,CAAA,EAAG,EAAE,CAAA,eAAA,EAAkB,KAAA,GAAQ,CAAC,CAAA,CAAA,EAAI;AAAA,UAChE,GAAG,OAAO,OAAA,EAAS,yBAAA;AAAA;AAAA,UAGnB,MAAA,EAAQ,cAAA;AAAA;AAAA,UAGR,cAAA,EAAgB,KAAK,KAAA,CAAM,QAAA;AAAA;AAAA;AAAA;AAAA;AAAA,UAM3B,aAAA,EACC,KAAA,EAAO,OAAA,EAAS,yBAAA,EAA2B,aAAA,IAAiB;AAAA,SAC7D,CAAA;AAAA,MACF,CAAC,CAAA;AAAA,IACF;AAKA,IAAA,IAAIC,mBAAA,CAAU,MAAM,aAAA,EAAe;AAAA,MAClC,KAAA,EAAO,KAAK,KAAA,CAAM;AAAA,KAClB,CAAA;AAAA,EACF;AACD","file":"sqs.cjs","sourcesContent":["import { Construct } from 'constructs';\nimport { CfnOutput, RemovalPolicy } from 'aws-cdk-lib';\nimport { Queue, QueueProps } from 'aws-cdk-lib/aws-sqs';\nimport {\n\tEventSourceMapping,\n\tEventSourceMappingProps,\n\tFunction,\n} from 'aws-cdk-lib/aws-lambda';\n\nimport { IBaseCdkConstructProps } from '../../types';\n\n/**\n * Props for BaseSqsConstruct\n *\n * Provides configuration for:\n * - SQS queue creation\n * - Lambda event source mappings\n */\ninterface ISqsConstructProps extends Omit<\n\tIBaseCdkConstructProps<{\n\t\t/** Configuration options for the SQS queue */\n\t\treadonly queueOptions?: QueueProps;\n\n\t\t/**\n\t\t * Configuration for Lambda event source mapping\n\t\t *\n\t\t * Note:\n\t\t * `eventSourceArn` and `target` are managed internally\n\t\t */\n\t\treadonly eventSourceMappingOptions?: Omit<\n\t\t\tEventSourceMappingProps,\n\t\t\t'eventSourceArn' | 'target'\n\t\t>;\n\t}>,\n\t'appName' | 'stage' | 'stackName'\n> {\n\t/**\n\t * Lambda functions to be triggered by SQS messages\n\t *\n\t * Each function will be connected via an event source mapping\n\t */\n\treadonly targetFunctions?: Function[];\n}\n\n/**\n * CDK construct for SQS queue with Lambda integration\n *\n * Responsibilities:\n * - Creates an SQS queue with configurable options\n * - Attaches one or more Lambda consumers via event source mappings\n * - Applies default retry behaviour\n * - Exposes the queue ARN as a CloudFormation output\n */\nexport class BaseSqsConstruct extends Construct {\n\t/** The created SQS queue instance */\n\treadonly queue: Queue;\n\n\t/**\n\t * @param scope Parent construct\n\t * @param id Unique construct identifier\n\t * @param props Configuration for queue and Lambda consumers\n\t */\n\tconstructor(scope: Construct, id: string, props: ISqsConstructProps) {\n\t\tsuper(scope, id);\n\n\t\tthis.queue = new Queue(this, id, {\n\t\t\t...props?.options?.queueOptions,\n\n\t\t\t/**\n\t\t\t * Removal policy applied to the queue\n\t\t\t * Defaults to DESTROY if not explicitly defined\n\t\t\t */\n\t\t\tremovalPolicy:\n\t\t\t\tprops?.options?.queueOptions?.removalPolicy || RemovalPolicy.DESTROY,\n\t\t});\n\n\t\t/**\n\t\t * Attach Lambda event source mappings for queue consumption\n\t\t */\n\t\tif (props?.targetFunctions?.length) {\n\t\t\tprops.targetFunctions.forEach((targetFunction, index) => {\n\t\t\t\tnew EventSourceMapping(this, `${id}-eventSourceMap${index + 1}`, {\n\t\t\t\t\t...props?.options?.eventSourceMappingOptions,\n\n\t\t\t\t\t/** Target Lambda function */\n\t\t\t\t\ttarget: targetFunction,\n\n\t\t\t\t\t/** Source SQS queue ARN */\n\t\t\t\t\teventSourceArn: this.queue.queueArn,\n\n\t\t\t\t\t/**\n\t\t\t\t\t * Retry attempts for failed batch processing\n\t\t\t\t\t * Defaults to 3 if not explicitly defined\n\t\t\t\t\t */\n\t\t\t\t\tretryAttempts:\n\t\t\t\t\t\tprops?.options?.eventSourceMappingOptions?.retryAttempts || 3,\n\t\t\t\t});\n\t\t\t});\n\t\t}\n\n\t\t/**\n\t\t * CloudFormation output exposing the SQS queue ARN\n\t\t */\n\t\tnew CfnOutput(this, 'SqsQueueArn', {\n\t\t\tvalue: this.queue.queueArn,\n\t\t});\n\t}\n}\n"]}
|