@incloodsolutions/devkit 0.0.4 → 0.0.5
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 +40 -10
- package/dist/aws-cdk/constructs/api-gateway-v2.cjs.map +1 -0
- package/dist/aws-cdk/{api-gateway-v2.d.cts → constructs/api-gateway-v2.d.cts} +2 -1
- package/dist/aws-cdk/{api-gateway-v2.d.ts → constructs/api-gateway-v2.d.ts} +2 -1
- package/dist/aws-cdk/constructs/api-gateway-v2.js.map +1 -0
- package/dist/aws-cdk/constructs/api-gateway-websocket.cjs.map +1 -0
- package/dist/aws-cdk/{api-gateway-websocket.d.cts → constructs/api-gateway-websocket.d.cts} +2 -1
- package/dist/aws-cdk/{api-gateway-websocket.d.ts → constructs/api-gateway-websocket.d.ts} +2 -1
- package/dist/aws-cdk/constructs/api-gateway-websocket.js.map +1 -0
- package/dist/aws-cdk/constructs/api-gateway.cjs.map +1 -0
- package/dist/aws-cdk/{api-gateway.d.cts → constructs/api-gateway.d.cts} +2 -1
- package/dist/aws-cdk/{api-gateway.d.ts → constructs/api-gateway.d.ts} +2 -1
- package/dist/aws-cdk/constructs/api-gateway.js.map +1 -0
- package/dist/aws-cdk/constructs/cloudfront.cjs.map +1 -0
- package/dist/aws-cdk/{cloudfront.d.cts → constructs/cloudfront.d.cts} +2 -1
- package/dist/aws-cdk/{cloudfront.d.ts → constructs/cloudfront.d.ts} +2 -1
- package/dist/aws-cdk/constructs/cloudfront.js.map +1 -0
- package/dist/aws-cdk/constructs/cloudwatch.cjs.map +1 -0
- package/dist/aws-cdk/{cloudwatch.d.cts → constructs/cloudwatch.d.cts} +2 -1
- package/dist/aws-cdk/{cloudwatch.d.ts → constructs/cloudwatch.d.ts} +2 -1
- package/dist/aws-cdk/constructs/cloudwatch.js.map +1 -0
- package/dist/aws-cdk/constructs/dynamo-db.cjs.map +1 -0
- package/dist/aws-cdk/{dynamo-db.d.cts → constructs/dynamo-db.d.cts} +2 -1
- package/dist/aws-cdk/{dynamo-db.d.ts → constructs/dynamo-db.d.ts} +2 -1
- package/dist/aws-cdk/constructs/dynamo-db.js.map +1 -0
- package/dist/aws-cdk/constructs/event-bridge.cjs.map +1 -0
- package/dist/aws-cdk/{event-bridge.d.cts → constructs/event-bridge.d.cts} +2 -1
- package/dist/aws-cdk/{event-bridge.d.ts → constructs/event-bridge.d.ts} +2 -1
- package/dist/aws-cdk/constructs/event-bridge.js.map +1 -0
- package/dist/aws-cdk/constructs/lambda-authorizer-v2.cjs.map +1 -0
- package/dist/aws-cdk/{lambda-authorizer-v2.d.cts → constructs/lambda-authorizer-v2.d.cts} +2 -1
- package/dist/aws-cdk/{lambda-authorizer-v2.d.ts → constructs/lambda-authorizer-v2.d.ts} +2 -1
- package/dist/aws-cdk/constructs/lambda-authorizer-v2.js.map +1 -0
- package/dist/aws-cdk/constructs/lambda-authorizer.cjs.map +1 -0
- package/dist/aws-cdk/{lambda-authorizer.d.cts → constructs/lambda-authorizer.d.cts} +2 -1
- package/dist/aws-cdk/{lambda-authorizer.d.ts → constructs/lambda-authorizer.d.ts} +2 -1
- package/dist/aws-cdk/constructs/lambda-authorizer.js.map +1 -0
- package/dist/aws-cdk/constructs/lambda-layer.cjs.map +1 -0
- package/dist/aws-cdk/{lambda-layer.d.cts → constructs/lambda-layer.d.cts} +2 -1
- package/dist/aws-cdk/{lambda-layer.d.ts → constructs/lambda-layer.d.ts} +2 -1
- package/dist/aws-cdk/constructs/lambda-layer.js.map +1 -0
- package/dist/aws-cdk/{lambda.cjs → constructs/lambda.cjs} +2 -2
- package/dist/aws-cdk/constructs/lambda.cjs.map +1 -0
- package/dist/aws-cdk/{lambda.d.cts → constructs/lambda.d.cts} +2 -1
- package/dist/aws-cdk/{lambda.d.ts → constructs/lambda.d.ts} +2 -1
- package/dist/aws-cdk/{lambda.js → constructs/lambda.js} +2 -2
- package/dist/aws-cdk/constructs/lambda.js.map +1 -0
- package/dist/aws-cdk/constructs/role-policy.cjs.map +1 -0
- package/dist/aws-cdk/{role-policy.d.cts → constructs/role-policy.d.cts} +2 -1
- package/dist/aws-cdk/{role-policy.d.ts → constructs/role-policy.d.ts} +2 -1
- package/dist/aws-cdk/constructs/role-policy.js.map +1 -0
- package/dist/aws-cdk/constructs/route53.cjs +79 -0
- package/dist/aws-cdk/constructs/route53.cjs.map +1 -0
- package/dist/aws-cdk/constructs/route53.d.cts +95 -0
- package/dist/aws-cdk/constructs/route53.d.ts +95 -0
- package/dist/aws-cdk/constructs/route53.js +77 -0
- package/dist/aws-cdk/constructs/route53.js.map +1 -0
- package/dist/aws-cdk/constructs/s3-deployment.cjs.map +1 -0
- package/dist/aws-cdk/{s3-deployment.d.cts → constructs/s3-deployment.d.cts} +2 -1
- package/dist/aws-cdk/{s3-deployment.d.ts → constructs/s3-deployment.d.ts} +2 -1
- package/dist/aws-cdk/constructs/s3-deployment.js.map +1 -0
- package/dist/aws-cdk/constructs/s3.cjs.map +1 -0
- package/dist/aws-cdk/{s3.d.cts → constructs/s3.d.cts} +2 -1
- package/dist/aws-cdk/{s3.d.ts → constructs/s3.d.ts} +2 -1
- package/dist/aws-cdk/constructs/s3.js.map +1 -0
- package/dist/aws-cdk/constructs/sns.cjs.map +1 -0
- package/dist/aws-cdk/{sns.d.cts → constructs/sns.d.cts} +2 -1
- package/dist/aws-cdk/{sns.d.ts → constructs/sns.d.ts} +2 -1
- package/dist/aws-cdk/constructs/sns.js.map +1 -0
- package/dist/aws-cdk/constructs/sqs.cjs.map +1 -0
- package/dist/aws-cdk/{sqs.d.cts → constructs/sqs.d.cts} +2 -1
- package/dist/aws-cdk/{sqs.d.ts → constructs/sqs.d.ts} +2 -1
- package/dist/aws-cdk/constructs/sqs.js.map +1 -0
- package/dist/aws-cdk/constructs/vpc.cjs.map +1 -0
- package/dist/aws-cdk/{vpc.d.cts → constructs/vpc.d.cts} +2 -1
- package/dist/aws-cdk/{vpc.d.ts → constructs/vpc.d.ts} +2 -1
- package/dist/aws-cdk/constructs/vpc.js.map +1 -0
- package/dist/aws-cdk/stacks/lambda-api.cjs +252 -0
- package/dist/aws-cdk/stacks/lambda-api.cjs.map +1 -0
- package/dist/aws-cdk/stacks/lambda-api.d.cts +16 -0
- package/dist/aws-cdk/stacks/lambda-api.d.ts +16 -0
- package/dist/aws-cdk/stacks/lambda-api.js +250 -0
- package/dist/aws-cdk/stacks/lambda-api.js.map +1 -0
- package/dist/aws-cdk/stacks/lambda-sns.cjs +211 -0
- package/dist/aws-cdk/stacks/lambda-sns.cjs.map +1 -0
- package/dist/aws-cdk/stacks/lambda-sns.d.cts +17 -0
- package/dist/aws-cdk/stacks/lambda-sns.d.ts +17 -0
- package/dist/aws-cdk/stacks/lambda-sns.js +209 -0
- package/dist/aws-cdk/stacks/lambda-sns.js.map +1 -0
- package/dist/aws-cdk/stacks/lambda-sqs.cjs +220 -0
- package/dist/aws-cdk/stacks/lambda-sqs.cjs.map +1 -0
- package/dist/aws-cdk/stacks/lambda-sqs.d.cts +18 -0
- package/dist/aws-cdk/stacks/lambda-sqs.d.ts +18 -0
- package/dist/aws-cdk/stacks/lambda-sqs.js +218 -0
- package/dist/aws-cdk/stacks/lambda-sqs.js.map +1 -0
- package/dist/aws-types.d.cts +14 -1
- package/dist/aws-types.d.ts +14 -1
- package/dist/aws.cjs +199 -2
- package/dist/aws.cjs.map +1 -1
- package/dist/aws.d.cts +25 -19
- package/dist/aws.d.ts +25 -19
- package/dist/aws.js +198 -5
- package/dist/aws.js.map +1 -1
- package/dist/index.cjs +199 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +24 -18
- package/dist/index.d.ts +24 -18
- package/dist/index.js +198 -5
- package/dist/index.js.map +1 -1
- package/package.json +130 -152
- package/dist/aws-cdk/api-gateway-v2.cjs.map +0 -1
- package/dist/aws-cdk/api-gateway-v2.js.map +0 -1
- package/dist/aws-cdk/api-gateway-websocket.cjs.map +0 -1
- package/dist/aws-cdk/api-gateway-websocket.js.map +0 -1
- package/dist/aws-cdk/api-gateway.cjs.map +0 -1
- package/dist/aws-cdk/api-gateway.js.map +0 -1
- package/dist/aws-cdk/cloudfront.cjs.map +0 -1
- package/dist/aws-cdk/cloudfront.js.map +0 -1
- package/dist/aws-cdk/cloudwatch.cjs.map +0 -1
- package/dist/aws-cdk/cloudwatch.js.map +0 -1
- package/dist/aws-cdk/dynamo-db.cjs.map +0 -1
- package/dist/aws-cdk/dynamo-db.js.map +0 -1
- package/dist/aws-cdk/event-bridge.cjs.map +0 -1
- package/dist/aws-cdk/event-bridge.js.map +0 -1
- package/dist/aws-cdk/lambda-authorizer-v2.cjs.map +0 -1
- package/dist/aws-cdk/lambda-authorizer-v2.js.map +0 -1
- package/dist/aws-cdk/lambda-authorizer.cjs.map +0 -1
- package/dist/aws-cdk/lambda-authorizer.js.map +0 -1
- package/dist/aws-cdk/lambda-layer.cjs.map +0 -1
- package/dist/aws-cdk/lambda-layer.js.map +0 -1
- package/dist/aws-cdk/lambda.cjs.map +0 -1
- package/dist/aws-cdk/lambda.js.map +0 -1
- package/dist/aws-cdk/role-policy.cjs.map +0 -1
- package/dist/aws-cdk/role-policy.js.map +0 -1
- package/dist/aws-cdk/s3-deployment.cjs.map +0 -1
- package/dist/aws-cdk/s3-deployment.js.map +0 -1
- package/dist/aws-cdk/s3.cjs.map +0 -1
- package/dist/aws-cdk/s3.js.map +0 -1
- package/dist/aws-cdk/sns.cjs.map +0 -1
- package/dist/aws-cdk/sns.js.map +0 -1
- package/dist/aws-cdk/sqs.cjs.map +0 -1
- package/dist/aws-cdk/sqs.js.map +0 -1
- package/dist/aws-cdk/vpc.cjs.map +0 -1
- package/dist/aws-cdk/vpc.js.map +0 -1
- package/dist/aws-cdk.cjs +0 -905
- package/dist/aws-cdk.cjs.map +0 -1
- package/dist/aws-cdk.d.cts +0 -34
- package/dist/aws-cdk.d.ts +0 -34
- package/dist/aws-cdk.js +0 -887
- package/dist/aws-cdk.js.map +0 -1
- /package/dist/aws-cdk/{api-gateway-v2.cjs → constructs/api-gateway-v2.cjs} +0 -0
- /package/dist/aws-cdk/{api-gateway-v2.js → constructs/api-gateway-v2.js} +0 -0
- /package/dist/aws-cdk/{api-gateway-websocket.cjs → constructs/api-gateway-websocket.cjs} +0 -0
- /package/dist/aws-cdk/{api-gateway-websocket.js → constructs/api-gateway-websocket.js} +0 -0
- /package/dist/aws-cdk/{api-gateway.cjs → constructs/api-gateway.cjs} +0 -0
- /package/dist/aws-cdk/{api-gateway.js → constructs/api-gateway.js} +0 -0
- /package/dist/aws-cdk/{cloudfront.cjs → constructs/cloudfront.cjs} +0 -0
- /package/dist/aws-cdk/{cloudfront.js → constructs/cloudfront.js} +0 -0
- /package/dist/aws-cdk/{cloudwatch.cjs → constructs/cloudwatch.cjs} +0 -0
- /package/dist/aws-cdk/{cloudwatch.js → constructs/cloudwatch.js} +0 -0
- /package/dist/aws-cdk/{dynamo-db.cjs → constructs/dynamo-db.cjs} +0 -0
- /package/dist/aws-cdk/{dynamo-db.js → constructs/dynamo-db.js} +0 -0
- /package/dist/aws-cdk/{event-bridge.cjs → constructs/event-bridge.cjs} +0 -0
- /package/dist/aws-cdk/{event-bridge.js → constructs/event-bridge.js} +0 -0
- /package/dist/aws-cdk/{lambda-authorizer-v2.cjs → constructs/lambda-authorizer-v2.cjs} +0 -0
- /package/dist/aws-cdk/{lambda-authorizer-v2.js → constructs/lambda-authorizer-v2.js} +0 -0
- /package/dist/aws-cdk/{lambda-authorizer.cjs → constructs/lambda-authorizer.cjs} +0 -0
- /package/dist/aws-cdk/{lambda-authorizer.js → constructs/lambda-authorizer.js} +0 -0
- /package/dist/aws-cdk/{lambda-layer.cjs → constructs/lambda-layer.cjs} +0 -0
- /package/dist/aws-cdk/{lambda-layer.js → constructs/lambda-layer.js} +0 -0
- /package/dist/aws-cdk/{role-policy.cjs → constructs/role-policy.cjs} +0 -0
- /package/dist/aws-cdk/{role-policy.js → constructs/role-policy.js} +0 -0
- /package/dist/aws-cdk/{s3-deployment.cjs → constructs/s3-deployment.cjs} +0 -0
- /package/dist/aws-cdk/{s3-deployment.js → constructs/s3-deployment.js} +0 -0
- /package/dist/aws-cdk/{s3.cjs → constructs/s3.cjs} +0 -0
- /package/dist/aws-cdk/{s3.js → constructs/s3.js} +0 -0
- /package/dist/aws-cdk/{sns.cjs → constructs/sns.cjs} +0 -0
- /package/dist/aws-cdk/{sns.js → constructs/sns.js} +0 -0
- /package/dist/aws-cdk/{sqs.cjs → constructs/sqs.cjs} +0 -0
- /package/dist/aws-cdk/{sqs.js → constructs/sqs.js} +0 -0
- /package/dist/aws-cdk/{vpc.cjs → constructs/vpc.cjs} +0 -0
- /package/dist/aws-cdk/{vpc.js → constructs/vpc.js} +0 -0
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Construct } from 'constructs';
|
|
2
2
|
import { LayerVersion, ILayerVersion, LayerVersionProps, Runtime } from 'aws-cdk-lib/aws-lambda';
|
|
3
|
-
import { IBaseCdkConstructProps } from '
|
|
3
|
+
import { IBaseCdkConstructProps } from '../../aws-types.cjs';
|
|
4
4
|
import '@incloodsolutions/toolkit';
|
|
5
|
+
import 'aws-cdk-lib';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* Props for BaseLambdaLayerConstruct
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Construct } from 'constructs';
|
|
2
2
|
import { LayerVersion, ILayerVersion, LayerVersionProps, Runtime } from 'aws-cdk-lib/aws-lambda';
|
|
3
|
-
import { IBaseCdkConstructProps } from '
|
|
3
|
+
import { IBaseCdkConstructProps } from '../../aws-types.js';
|
|
4
4
|
import '@incloodsolutions/toolkit';
|
|
5
|
+
import 'aws-cdk-lib';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* Props for BaseLambdaLayerConstruct
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/aws/cdk/constructs/lambda-layer-construct.ts"],"names":[],"mappings":";;;;;;AAsDO,IAAM,wBAAA,GAAN,cAAuC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AAA;AAAA,UACR,OAAA,CAAQ;AAAA;AACT,OACqB,CAAA;AAAA,IACvB;AAMA,IAAA,IAAI,SAAA,CAAU,MAAM,gBAAA,EAAkB;AAAA,MACrC,KAAA,EACC,KAAA,CAAM,OAAA,EAAS,oBAAA,IACf,KAAA,CAAM,OAAA,EAAS,0BAAA,GACZ,IAAA,CAAK,aAAA,CAAc,eAAA,GACnB,IAAA,CAAK,KAAA,CAAM;AAAA,KACf,CAAA;AAAA,EACF;AACD","file":"lambda-layer.js","sourcesContent":["import { Construct } from 'constructs';\nimport { CfnOutput } from 'aws-cdk-lib';\nimport {\n\tArchitecture,\n\tCode,\n\tILayerVersion,\n\tLayerVersion,\n\tLayerVersionProps,\n\tRuntime,\n} from 'aws-cdk-lib/aws-lambda';\n\nimport { IBaseCdkConstructProps } from '../../types';\n\n/**\n * Props for BaseLambdaLayerConstruct\n *\n * Provides configuration for:\n * - Creating a new Lambda Layer\n * - Importing an existing layer by ARN or attributes\n */\ninterface ILambdaLayerConstructProps extends Omit<\n\tIBaseCdkConstructProps<{\n\t\t/**\n\t\t * Configuration for creating a new Lambda layer\n\t\t *\n\t\t * Note:\n\t\t * - `layerVersionName` is required\n\t\t * - `compatibleArchitectures` is managed internally\n\t\t */\n\t\treadonly layerOptions?: Partial<\n\t\t\tOmit<LayerVersionProps, 'layerVersionName' | 'compatibleArchitectures'>\n\t\t> &\n\t\t\tRequired<Pick<LayerVersionProps, 'layerVersionName'>>;\n\n\t\t/** Import an existing layer by ARN */\n\t\treadonly fromExistingLayerArn?: string;\n\n\t\t/** Import an existing layer using attributes */\n\t\treadonly fromExistingLayerAttribute?: {\n\t\t\treadonly layerVersionArn: string;\n\t\t\treadonly compatibleRuntimes?: Runtime[];\n\t\t};\n\t}>,\n\t'appName' | 'stage' | 'stackName'\n> {}\n\n/**\n * CDK construct for Lambda Layer\n *\n * Responsibilities:\n * - Creates a new Lambda layer or imports an existing one\n * - Applies default runtime and architecture compatibility\n * - Exposes the layer ARN as a CloudFormation output\n */\nexport class BaseLambdaLayerConstruct extends Construct {\n\t/** Newly created Lambda Layer (null if importing existing layer) */\n\treadonly layer: LayerVersion;\n\n\t/** Imported Lambda Layer reference (null if creating new layer) */\n\treadonly existingLayer: ILayerVersion;\n\n\t/**\n\t * @param scope Parent construct\n\t * @param id Unique construct identifier\n\t * @param props Configuration for layer creation or import\n\t */\n\tconstructor(\n\t\tscope: Construct,\n\t\tid: string,\n\t\tprops?: ILambdaLayerConstructProps,\n\t) {\n\t\tsuper(scope, id);\n\n\t\t/**\n\t\t * Import layer by ARN\n\t\t */\n\t\tif (props?.options?.fromExistingLayerArn) {\n\t\t\tthis.existingLayer = LayerVersion.fromLayerVersionArn(\n\t\t\t\tthis,\n\t\t\t\t`${id}-Arn`,\n\t\t\t\tprops?.options?.fromExistingLayerArn,\n\t\t\t);\n\n\t\t\t/**\n\t\t\t * Import layer using attributes\n\t\t\t */\n\t\t} else if (props?.options?.fromExistingLayerAttribute) {\n\t\t\tthis.existingLayer = LayerVersion.fromLayerVersionAttributes(\n\t\t\t\tthis,\n\t\t\t\t`${id}-Attribute`,\n\t\t\t\tprops?.options?.fromExistingLayerAttribute,\n\t\t\t);\n\n\t\t\t/**\n\t\t\t * Create new Lambda layer\n\t\t\t */\n\t\t} else {\n\t\t\tthis.layer = new LayerVersion(this, id, {\n\t\t\t\t...props.options?.layerOptions,\n\n\t\t\t\t/**\n\t\t\t\t * Default layer code asset\n\t\t\t\t */\n\t\t\t\tcode:\n\t\t\t\t\tprops?.options?.layerOptions?.code || Code.fromAsset('./dist-layer'),\n\n\t\t\t\t/**\n\t\t\t\t * Layer description\n\t\t\t\t */\n\t\t\t\tdescription:\n\t\t\t\t\tprops?.options?.layerOptions?.description ||\n\t\t\t\t\t'Lambda Layer written in NodeJS, NestJS, NodeJS-express, serverless-express',\n\n\t\t\t\t/**\n\t\t\t\t * Supported CPU architectures\n\t\t\t\t */\n\t\t\t\tcompatibleArchitectures: [Architecture.ARM_64, Architecture.X86_64],\n\n\t\t\t\t/**\n\t\t\t\t * Supported runtimes\n\t\t\t\t */\n\t\t\t\tcompatibleRuntimes: [\n\t\t\t\t\tRuntime.NODEJS_22_X,\n\t\t\t\t\tRuntime.NODEJS_24_X,\n\t\t\t\t\tRuntime.NODEJS_LATEST,\n\t\t\t\t],\n\t\t\t} as LayerVersionProps);\n\t\t}\n\n\t\t/**\n\t\t * CloudFormation output exposing the layer ARN\n\t\t * Resolves to either created or imported layer\n\t\t */\n\t\tnew CfnOutput(this, 'LambdaLayerArn', {\n\t\t\tvalue:\n\t\t\t\tprops.options?.fromExistingLayerArn ||\n\t\t\t\tprops.options?.fromExistingLayerAttribute\n\t\t\t\t\t? this.existingLayer.layerVersionArn\n\t\t\t\t\t: this.layer.layerVersionArn,\n\t\t});\n\t}\n}\n"]}
|
|
@@ -31,9 +31,9 @@ var BaseLambdaConstruct = class extends constructs.Construct {
|
|
|
31
31
|
...props?.options?.lambdaOptions,
|
|
32
32
|
/**
|
|
33
33
|
* Lambda function name
|
|
34
|
-
* Defaults to "<stackName
|
|
34
|
+
* Defaults to "<stackName>" if not provided
|
|
35
35
|
*/
|
|
36
|
-
functionName: `${props?.options?.lambdaOptions?.functionName || props?.stackName}
|
|
36
|
+
functionName: `${props?.options?.lambdaOptions?.functionName || props?.stackName}`,
|
|
37
37
|
/**
|
|
38
38
|
* Function description
|
|
39
39
|
*/
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/aws/cdk/constructs/lambda-construct.ts"],"names":["Construct","detectDuplicateProperties","Function","Runtime","Duration","AppEnvironmentEnum","Architecture","Code","CfnOutput"],"mappings":";;;;;;;;;AAwCO,IAAM,mBAAA,GAAN,cAAkCA,oBAAA,CAAU;AAAA,EAxCnD;AAwCmD,IAAA,MAAA,CAAA,IAAA,EAAA,qBAAA,CAAA;AAAA;AAAA;AAAA,EAEzC,QAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOT,WAAA,CAAY,KAA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A,EAAO,OAAA,EAAS,aAAA,EAAe,gBAAgBC,sBAAA,CAAa,MAAA;AAAA;AAAA;AAAA;AAAA,MAK7D,MAAM,KAAA,EAAO,OAAA,EAAS,eAAe,IAAA,IAAQC,cAAA,CAAK,UAAU,MAAM,CAAA;AAAA;AAAA;AAAA;AAAA,MAKlE;AAAA,KACA,CAAA;AAKD,IAAA,IAAIC,mBAAA,CAAU,MAAM,mBAAA,EAAqB;AAAA,MACxC,KAAA,EAAO,KAAK,QAAA,CAAS;AAAA,KACrB,CAAA;AAAA,EACF;AACD","file":"lambda.cjs","sourcesContent":["import { Construct } from 'constructs';\nimport { CfnOutput, Duration } from 'aws-cdk-lib';\nimport {\n\tArchitecture,\n\tCode,\n\tFunction,\n\tFunctionProps,\n\tRuntime,\n} from 'aws-cdk-lib/aws-lambda';\n\nimport {\n\tdetectDuplicateProperties,\n\tAppEnvironmentEnum,\n} from '@incloodsolutions/toolkit';\n\nimport { IBaseCdkConstructProps } from '../../types';\n\n/**\n * Props for BaseLambdaConstruct\n *\n * Provides configuration for creating a Lambda function\n * with optional overrides for runtime, memory, timeout, and environment.\n */\ninterface ILambdaConstructProps extends Omit<\n\tIBaseCdkConstructProps<{\n\t\t/** Partial Lambda configuration options */\n\t\treadonly lambdaOptions: Partial<FunctionProps>;\n\t}>,\n\t'appName'\n> {}\n\n/**\n * CDK construct for AWS Lambda function\n *\n * Responsibilities:\n * - Creates a Lambda function with sensible defaults\n * - Merges and validates environment variables\n * - Applies stage-based configuration (e.g. timeout)\n * - Exposes the function ARN as a CloudFormation output\n */\nexport class BaseLambdaConstruct extends Construct {\n\t/** The created Lambda function instance */\n\treadonly function: Function;\n\n\t/**\n\t * @param scope Parent construct\n\t * @param id Unique construct identifier\n\t * @param props Configuration for Lambda function\n\t */\n\tconstructor(scope: Construct, id: string, props: ILambdaConstructProps) {\n\t\tsuper(scope, id);\n\n\t\t/**\n\t\t * Environment variables for the Lambda function\n\t\t *\n\t\t * Includes:\n\t\t * - User-defined variables\n\t\t * - NODE_ENV derived from stage\n\t\t * - Node.js runtime optimisations\n\t\t */\n\t\tconst environment = {\n\t\t\t...props.options?.lambdaOptions?.environment,\n\t\t\tNODE_ENV: props.stage,\n\t\t\tNODE_OPTIONS: '--enable-source-maps',\n\t\t\tAWS_NODEJS_CONNECTION_REUSE_ENABLED: '1',\n\t\t};\n\n\t\t/**\n\t\t * Validate environment variables for duplicate keys\n\t\t */\n\t\tdetectDuplicateProperties({ data: environment });\n\n\t\tthis.function = new Function(this, id, {\n\t\t\t...props?.options?.lambdaOptions,\n\n\t\t\t/**\n\t\t\t * Lambda function name\n\t\t\t * Defaults to \"<stackName>\" if not provided\n\t\t\t */\n\t\t\tfunctionName: `${props?.options?.lambdaOptions?.functionName || props?.stackName}`,\n\n\t\t\t/**\n\t\t\t * Function description\n\t\t\t */\n\t\t\tdescription:\n\t\t\t\tprops?.options?.lambdaOptions?.description || 'A lambda function',\n\n\t\t\t/**\n\t\t\t * Entry handler for the Lambda function\n\t\t\t */\n\t\t\thandler: props?.options?.lambdaOptions?.handler || 'lambda.handler',\n\n\t\t\t/**\n\t\t\t * Runtime environment\n\t\t\t */\n\t\t\truntime: props?.options?.lambdaOptions?.runtime || Runtime.NODEJS_24_X,\n\n\t\t\t/**\n\t\t\t * Execution timeout\n\t\t\t * - 30 seconds in production\n\t\t\t * - 15 seconds otherwise\n\t\t\t */\n\t\t\ttimeout:\n\t\t\t\tprops?.options?.lambdaOptions?.timeout ||\n\t\t\t\tDuration.seconds(\n\t\t\t\t\tprops.stage === AppEnvironmentEnum.PRODUCTION ? 30 : 15,\n\t\t\t\t),\n\n\t\t\t/**\n\t\t\t * Memory allocation (in MB)\n\t\t\t */\n\t\t\tmemorySize: props?.options?.lambdaOptions?.memorySize || 1024,\n\n\t\t\t/**\n\t\t\t * CPU architecture\n\t\t\t */\n\t\t\tarchitecture:\n\t\t\t\tprops?.options?.lambdaOptions?.architecture || Architecture.ARM_64,\n\n\t\t\t/**\n\t\t\t * Lambda deployment package source\n\t\t\t */\n\t\t\tcode: props?.options?.lambdaOptions?.code || Code.fromAsset('dist'),\n\n\t\t\t/**\n\t\t\t * Final merged environment variables\n\t\t\t */\n\t\t\tenvironment,\n\t\t});\n\n\t\t/**\n\t\t * CloudFormation output exposing the Lambda function ARN\n\t\t */\n\t\tnew CfnOutput(this, 'LambdaFunctionArn', {\n\t\t\tvalue: this.function.functionArn,\n\t\t});\n\t}\n}\n"]}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Construct } from 'constructs';
|
|
2
2
|
import { Function, FunctionProps } from 'aws-cdk-lib/aws-lambda';
|
|
3
|
-
import { IBaseCdkConstructProps } from '
|
|
3
|
+
import { IBaseCdkConstructProps } from '../../aws-types.cjs';
|
|
4
4
|
import '@incloodsolutions/toolkit';
|
|
5
|
+
import 'aws-cdk-lib';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* Props for BaseLambdaConstruct
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Construct } from 'constructs';
|
|
2
2
|
import { Function, FunctionProps } from 'aws-cdk-lib/aws-lambda';
|
|
3
|
-
import { IBaseCdkConstructProps } from '
|
|
3
|
+
import { IBaseCdkConstructProps } from '../../aws-types.js';
|
|
4
4
|
import '@incloodsolutions/toolkit';
|
|
5
|
+
import 'aws-cdk-lib';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* Props for BaseLambdaConstruct
|
|
@@ -29,9 +29,9 @@ var BaseLambdaConstruct = class extends Construct {
|
|
|
29
29
|
...props?.options?.lambdaOptions,
|
|
30
30
|
/**
|
|
31
31
|
* Lambda function name
|
|
32
|
-
* Defaults to "<stackName
|
|
32
|
+
* Defaults to "<stackName>" if not provided
|
|
33
33
|
*/
|
|
34
|
-
functionName: `${props?.options?.lambdaOptions?.functionName || props?.stackName}
|
|
34
|
+
functionName: `${props?.options?.lambdaOptions?.functionName || props?.stackName}`,
|
|
35
35
|
/**
|
|
36
36
|
* Function description
|
|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AO3D,OAAA,EACC,KAAA,EAAO,OAAA,EAAS,aAAA,EAAe,WAC/B,QAAA,CAAS,OAAA;AAAA,QACR,KAAA,CAAM,KAAA,KAAU,kBAAA,CAAmB,UAAA,GAAa,EAAA,GAAK;AAAA,OACtD;AAAA;AAAA;AAAA;AAAA,MAKD,UAAA,EAAY,KAAA,EAAO,OAAA,EAAS,aAAA,EAAe,UAAA,IAAc,IAAA;AAAA;AAAA;AAAA;AAAA,MAKzD,YAAA,EACC,KAAA,EAAO,OAAA,EAAS,aAAA,EAAe,gBAAgB,YAAA,CAAa,MAAA;AAAA;AAAA;AAAA;AAAA,MAK7D,MAAM,KAAA,EAAO,OAAA,EAAS,eAAe,IAAA,IAAQ,IAAA,CAAK,UAAU,MAAM,CAAA;AAAA;AAAA;AAAA;AAAA,MAKlE;AAAA,KACA,CAAA;AAKD,IAAA,IAAI,SAAA,CAAU,MAAM,mBAAA,EAAqB;AAAA,MACxC,KAAA,EAAO,KAAK,QAAA,CAAS;AAAA,KACrB,CAAA;AAAA,EACF;AACD","file":"lambda.js","sourcesContent":["import { Construct } from 'constructs';\nimport { CfnOutput, Duration } from 'aws-cdk-lib';\nimport {\n\tArchitecture,\n\tCode,\n\tFunction,\n\tFunctionProps,\n\tRuntime,\n} from 'aws-cdk-lib/aws-lambda';\n\nimport {\n\tdetectDuplicateProperties,\n\tAppEnvironmentEnum,\n} from '@incloodsolutions/toolkit';\n\nimport { IBaseCdkConstructProps } from '../../types';\n\n/**\n * Props for BaseLambdaConstruct\n *\n * Provides configuration for creating a Lambda function\n * with optional overrides for runtime, memory, timeout, and environment.\n */\ninterface ILambdaConstructProps extends Omit<\n\tIBaseCdkConstructProps<{\n\t\t/** Partial Lambda configuration options */\n\t\treadonly lambdaOptions: Partial<FunctionProps>;\n\t}>,\n\t'appName'\n> {}\n\n/**\n * CDK construct for AWS Lambda function\n *\n * Responsibilities:\n * - Creates a Lambda function with sensible defaults\n * - Merges and validates environment variables\n * - Applies stage-based configuration (e.g. timeout)\n * - Exposes the function ARN as a CloudFormation output\n */\nexport class BaseLambdaConstruct extends Construct {\n\t/** The created Lambda function instance */\n\treadonly function: Function;\n\n\t/**\n\t * @param scope Parent construct\n\t * @param id Unique construct identifier\n\t * @param props Configuration for Lambda function\n\t */\n\tconstructor(scope: Construct, id: string, props: ILambdaConstructProps) {\n\t\tsuper(scope, id);\n\n\t\t/**\n\t\t * Environment variables for the Lambda function\n\t\t *\n\t\t * Includes:\n\t\t * - User-defined variables\n\t\t * - NODE_ENV derived from stage\n\t\t * - Node.js runtime optimisations\n\t\t */\n\t\tconst environment = {\n\t\t\t...props.options?.lambdaOptions?.environment,\n\t\t\tNODE_ENV: props.stage,\n\t\t\tNODE_OPTIONS: '--enable-source-maps',\n\t\t\tAWS_NODEJS_CONNECTION_REUSE_ENABLED: '1',\n\t\t};\n\n\t\t/**\n\t\t * Validate environment variables for duplicate keys\n\t\t */\n\t\tdetectDuplicateProperties({ data: environment });\n\n\t\tthis.function = new Function(this, id, {\n\t\t\t...props?.options?.lambdaOptions,\n\n\t\t\t/**\n\t\t\t * Lambda function name\n\t\t\t * Defaults to \"<stackName>\" if not provided\n\t\t\t */\n\t\t\tfunctionName: `${props?.options?.lambdaOptions?.functionName || props?.stackName}`,\n\n\t\t\t/**\n\t\t\t * Function description\n\t\t\t */\n\t\t\tdescription:\n\t\t\t\tprops?.options?.lambdaOptions?.description || 'A lambda function',\n\n\t\t\t/**\n\t\t\t * Entry handler for the Lambda function\n\t\t\t */\n\t\t\thandler: props?.options?.lambdaOptions?.handler || 'lambda.handler',\n\n\t\t\t/**\n\t\t\t * Runtime environment\n\t\t\t */\n\t\t\truntime: props?.options?.lambdaOptions?.runtime || Runtime.NODEJS_24_X,\n\n\t\t\t/**\n\t\t\t * Execution timeout\n\t\t\t * - 30 seconds in production\n\t\t\t * - 15 seconds otherwise\n\t\t\t */\n\t\t\ttimeout:\n\t\t\t\tprops?.options?.lambdaOptions?.timeout ||\n\t\t\t\tDuration.seconds(\n\t\t\t\t\tprops.stage === AppEnvironmentEnum.PRODUCTION ? 30 : 15,\n\t\t\t\t),\n\n\t\t\t/**\n\t\t\t * Memory allocation (in MB)\n\t\t\t */\n\t\t\tmemorySize: props?.options?.lambdaOptions?.memorySize || 1024,\n\n\t\t\t/**\n\t\t\t * CPU architecture\n\t\t\t */\n\t\t\tarchitecture:\n\t\t\t\tprops?.options?.lambdaOptions?.architecture || Architecture.ARM_64,\n\n\t\t\t/**\n\t\t\t * Lambda deployment package source\n\t\t\t */\n\t\t\tcode: props?.options?.lambdaOptions?.code || Code.fromAsset('dist'),\n\n\t\t\t/**\n\t\t\t * Final merged environment variables\n\t\t\t */\n\t\t\tenvironment,\n\t\t});\n\n\t\t/**\n\t\t * CloudFormation output exposing the Lambda function ARN\n\t\t */\n\t\tnew CfnOutput(this, 'LambdaFunctionArn', {\n\t\t\tvalue: this.function.functionArn,\n\t\t});\n\t}\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/aws/cdk/constructs/role-policy-construct.ts"],"names":["Construct","Role","ManagedPolicy","PolicyStatement","RemovalPolicy","CfnOutput"],"mappings":";;;;;;;;AA2CO,IAAM,uBAAA,GAAN,cAAsCA,oBAAA,CAAU;AAAA,EA3CvD;AA2CuD,IAAA,MAAA,CAAA,IAAA,EAAA,yBAAA,CAAA;AAAA;AAAA;AAAA,EAE7C,IAAA;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,IAAA,GAAO,IAAIC,WAAA,CAAK,IAAA,EAAM,EAAA,EAAI;AAAA,MAC9B,GAAG,MAAM,OAAA,EAAS,WAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAMlB,eAAA,EAAiB,MAAM,OAAA,EAAS,WAAA,EAAa,kBAC1C,KAAA,CAAM,OAAA,CAAQ,YAAY,eAAA,GAC1B;AAAA,QACAC,oBAAA,CAAc,wBAAA;AAAA,UACb;AAAA;AACD;AACD,KACF,CAAA;AAKD,IAAA,IAAI,KAAA,EAAO,UAAU,MAAA,EAAQ;AAC5B,MAAA,KAAA,CAAM,QAAA,CAAS,OAAA,CAAQ,CAAC,MAAA,KAAW;AAClC,QAAA,IAAA,CAAK,IAAA,CAAK,WAAA;AAAA;AAAA;AAAA;AAAA,UAIT,IAAIC,uBAAgB,MAAM;AAAA,SAC3B;AAAA,MACD,CAAC,CAAA;AAAA,IACF;AAKA,IAAA,IAAA,CAAK,IAAA,CAAK,kBAAA,CAAmBC,uBAAA,CAAc,OAAO,CAAA;AAKlD,IAAA,IAAIC,mBAAA,CAAU,MAAM,eAAA,EAAiB;AAAA,MACpC,KAAA,EAAO,KAAK,IAAA,CAAK;AAAA,KACjB,CAAA;AAAA,EACF;AACD","file":"role-policy.cjs","sourcesContent":["import { Construct } from 'constructs';\nimport { CfnOutput, RemovalPolicy } from 'aws-cdk-lib';\nimport {\n\tManagedPolicy,\n\tPolicyStatement,\n\tPolicyStatementProps,\n\tRole,\n\tRoleProps,\n} from 'aws-cdk-lib/aws-iam';\n\nimport { IBaseCdkConstructProps } from '../../types';\n\n/**\n * Props for BaseRolePolicyConstruct\n *\n * Provides configuration for:\n * - IAM role creation\n * - Inline policy statements\n */\ninterface IDynamoDBConstructProps extends Omit<\n\tIBaseCdkConstructProps<{\n\t\t/** IAM Role configuration options */\n\t\treadonly roleOptions: RoleProps;\n\t}>,\n\t'appName' | 'stage' | 'stackName'\n> {\n\t/**\n\t * Additional inline policies to attach to the role\n\t *\n\t * Each entry is converted into a PolicyStatement\n\t */\n\treadonly policies?: PolicyStatementProps[];\n}\n\n/**\n * CDK construct for IAM Role with policies\n *\n * Responsibilities:\n * - Creates an IAM role with configurable options\n * - Applies a default AWS managed policy if none is provided\n * - Attaches optional inline policy statements\n * - Exposes the role ARN as a CloudFormation output\n */\nexport class BaseRolePolicyConstruct extends Construct {\n\t/** The created IAM Role instance */\n\treadonly role: Role;\n\n\t/**\n\t * @param scope Parent construct\n\t * @param id Unique construct identifier\n\t * @param props Configuration for role and policies\n\t */\n\tconstructor(scope: Construct, id: string, props: IDynamoDBConstructProps) {\n\t\tsuper(scope, id);\n\n\t\tthis.role = new Role(this, id, {\n\t\t\t...props.options?.roleOptions,\n\n\t\t\t/**\n\t\t\t * Managed policies attached to the role\n\t\t\t * Defaults to AWSLambdaBasicExecutionRole if not provided\n\t\t\t */\n\t\t\tmanagedPolicies: props.options?.roleOptions?.managedPolicies\n\t\t\t\t? props.options.roleOptions.managedPolicies\n\t\t\t\t: [\n\t\t\t\t\t\tManagedPolicy.fromAwsManagedPolicyName(\n\t\t\t\t\t\t\t'service-role/AWSLambdaBasicExecutionRole',\n\t\t\t\t\t\t),\n\t\t\t\t\t],\n\t\t});\n\n\t\t/**\n\t\t * Attach inline policy statements to the role\n\t\t */\n\t\tif (props?.policies?.length) {\n\t\t\tprops.policies.forEach((policy) => {\n\t\t\t\tthis.role.addToPolicy(\n\t\t\t\t\t/**\n\t\t\t\t\t * Inline policy statement\n\t\t\t\t\t */\n\t\t\t\t\tnew PolicyStatement(policy),\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.role.applyRemovalPolicy(RemovalPolicy.DESTROY);\n\n\t\t/**\n\t\t * CloudFormation output exposing the role ARN\n\t\t */\n\t\tnew CfnOutput(this, 'RolePolicyArn', {\n\t\t\tvalue: this.role.roleArn,\n\t\t});\n\t}\n}\n"]}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Construct } from 'constructs';
|
|
2
2
|
import { Role, RoleProps, PolicyStatementProps } from 'aws-cdk-lib/aws-iam';
|
|
3
|
-
import { IBaseCdkConstructProps } from '
|
|
3
|
+
import { IBaseCdkConstructProps } from '../../aws-types.cjs';
|
|
4
4
|
import '@incloodsolutions/toolkit';
|
|
5
|
+
import 'aws-cdk-lib';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* Props for BaseRolePolicyConstruct
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Construct } from 'constructs';
|
|
2
2
|
import { Role, RoleProps, PolicyStatementProps } from 'aws-cdk-lib/aws-iam';
|
|
3
|
-
import { IBaseCdkConstructProps } from '
|
|
3
|
+
import { IBaseCdkConstructProps } from '../../aws-types.js';
|
|
4
4
|
import '@incloodsolutions/toolkit';
|
|
5
|
+
import 'aws-cdk-lib';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* Props for BaseRolePolicyConstruct
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/aws/cdk/constructs/role-policy-construct.ts"],"names":[],"mappings":";;;;;;AA2CO,IAAM,uBAAA,GAAN,cAAsC,SAAA,CAAU;AAAA,EA3CvD;AA2CuD,IAAA,MAAA,CAAA,IAAA,EAAA,yBAAA,CAAA;AAAA;AAAA;AAAA,EAE7C,IAAA;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,IAAA,GAAO,IAAI,IAAA,CAAK,IAAA,EAAM,EAAA,EAAI;AAAA,MAC9B,GAAG,MAAM,OAAA,EAAS,WAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAMlB,eAAA,EAAiB,MAAM,OAAA,EAAS,WAAA,EAAa,kBAC1C,KAAA,CAAM,OAAA,CAAQ,YAAY,eAAA,GAC1B;AAAA,QACA,aAAA,CAAc,wBAAA;AAAA,UACb;AAAA;AACD;AACD,KACF,CAAA;AAKD,IAAA,IAAI,KAAA,EAAO,UAAU,MAAA,EAAQ;AAC5B,MAAA,KAAA,CAAM,QAAA,CAAS,OAAA,CAAQ,CAAC,MAAA,KAAW;AAClC,QAAA,IAAA,CAAK,IAAA,CAAK,WAAA;AAAA;AAAA;AAAA;AAAA,UAIT,IAAI,gBAAgB,MAAM;AAAA,SAC3B;AAAA,MACD,CAAC,CAAA;AAAA,IACF;AAKA,IAAA,IAAA,CAAK,IAAA,CAAK,kBAAA,CAAmB,aAAA,CAAc,OAAO,CAAA;AAKlD,IAAA,IAAI,SAAA,CAAU,MAAM,eAAA,EAAiB;AAAA,MACpC,KAAA,EAAO,KAAK,IAAA,CAAK;AAAA,KACjB,CAAA;AAAA,EACF;AACD","file":"role-policy.js","sourcesContent":["import { Construct } from 'constructs';\nimport { CfnOutput, RemovalPolicy } from 'aws-cdk-lib';\nimport {\n\tManagedPolicy,\n\tPolicyStatement,\n\tPolicyStatementProps,\n\tRole,\n\tRoleProps,\n} from 'aws-cdk-lib/aws-iam';\n\nimport { IBaseCdkConstructProps } from '../../types';\n\n/**\n * Props for BaseRolePolicyConstruct\n *\n * Provides configuration for:\n * - IAM role creation\n * - Inline policy statements\n */\ninterface IDynamoDBConstructProps extends Omit<\n\tIBaseCdkConstructProps<{\n\t\t/** IAM Role configuration options */\n\t\treadonly roleOptions: RoleProps;\n\t}>,\n\t'appName' | 'stage' | 'stackName'\n> {\n\t/**\n\t * Additional inline policies to attach to the role\n\t *\n\t * Each entry is converted into a PolicyStatement\n\t */\n\treadonly policies?: PolicyStatementProps[];\n}\n\n/**\n * CDK construct for IAM Role with policies\n *\n * Responsibilities:\n * - Creates an IAM role with configurable options\n * - Applies a default AWS managed policy if none is provided\n * - Attaches optional inline policy statements\n * - Exposes the role ARN as a CloudFormation output\n */\nexport class BaseRolePolicyConstruct extends Construct {\n\t/** The created IAM Role instance */\n\treadonly role: Role;\n\n\t/**\n\t * @param scope Parent construct\n\t * @param id Unique construct identifier\n\t * @param props Configuration for role and policies\n\t */\n\tconstructor(scope: Construct, id: string, props: IDynamoDBConstructProps) {\n\t\tsuper(scope, id);\n\n\t\tthis.role = new Role(this, id, {\n\t\t\t...props.options?.roleOptions,\n\n\t\t\t/**\n\t\t\t * Managed policies attached to the role\n\t\t\t * Defaults to AWSLambdaBasicExecutionRole if not provided\n\t\t\t */\n\t\t\tmanagedPolicies: props.options?.roleOptions?.managedPolicies\n\t\t\t\t? props.options.roleOptions.managedPolicies\n\t\t\t\t: [\n\t\t\t\t\t\tManagedPolicy.fromAwsManagedPolicyName(\n\t\t\t\t\t\t\t'service-role/AWSLambdaBasicExecutionRole',\n\t\t\t\t\t\t),\n\t\t\t\t\t],\n\t\t});\n\n\t\t/**\n\t\t * Attach inline policy statements to the role\n\t\t */\n\t\tif (props?.policies?.length) {\n\t\t\tprops.policies.forEach((policy) => {\n\t\t\t\tthis.role.addToPolicy(\n\t\t\t\t\t/**\n\t\t\t\t\t * Inline policy statement\n\t\t\t\t\t */\n\t\t\t\t\tnew PolicyStatement(policy),\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.role.applyRemovalPolicy(RemovalPolicy.DESTROY);\n\n\t\t/**\n\t\t * CloudFormation output exposing the role ARN\n\t\t */\n\t\tnew CfnOutput(this, 'RolePolicyArn', {\n\t\t\tvalue: this.role.roleArn,\n\t\t});\n\t}\n}\n"]}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var constructs = require('constructs');
|
|
4
|
+
var awsCdkLib = require('aws-cdk-lib');
|
|
5
|
+
var awsRoute53 = require('aws-cdk-lib/aws-route53');
|
|
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 BaseRoute53Construct = class extends constructs.Construct {
|
|
11
|
+
static {
|
|
12
|
+
__name(this, "BaseRoute53Construct");
|
|
13
|
+
}
|
|
14
|
+
/** The hosted zone this construct created, imported, or looked up */
|
|
15
|
+
hostedZone;
|
|
16
|
+
/**
|
|
17
|
+
* @param scope Parent construct
|
|
18
|
+
* @param id Unique construct identifier
|
|
19
|
+
* @param props Configuration for the hosted zone and its records
|
|
20
|
+
*/
|
|
21
|
+
constructor(scope, id, props) {
|
|
22
|
+
super(scope, id);
|
|
23
|
+
const options = props?.options ?? {};
|
|
24
|
+
if (options.hostedZoneOptions) {
|
|
25
|
+
this.hostedZone = new awsRoute53.HostedZone(
|
|
26
|
+
this,
|
|
27
|
+
`${id}-HostedZone`,
|
|
28
|
+
options.hostedZoneOptions
|
|
29
|
+
);
|
|
30
|
+
} else if (options.fromExistingHostedZoneAttributes) {
|
|
31
|
+
this.hostedZone = awsRoute53.HostedZone.fromHostedZoneAttributes(
|
|
32
|
+
this,
|
|
33
|
+
`${id}-HostedZone`,
|
|
34
|
+
options.fromExistingHostedZoneAttributes
|
|
35
|
+
);
|
|
36
|
+
} else if (options.fromLookupOptions) {
|
|
37
|
+
this.hostedZone = awsRoute53.HostedZone.fromLookup(
|
|
38
|
+
this,
|
|
39
|
+
`${id}-HostedZone`,
|
|
40
|
+
options.fromLookupOptions
|
|
41
|
+
);
|
|
42
|
+
} else {
|
|
43
|
+
throw new toolkit.CustomException(
|
|
44
|
+
"BaseRoute53Construct requires one of hostedZoneOptions, fromExistingHostedZoneAttributes, or fromLookupOptions"
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
options.aRecords?.forEach((record, index) => {
|
|
48
|
+
new awsRoute53.ARecord(this, `${id}-ARecord-${index}`, {
|
|
49
|
+
...record,
|
|
50
|
+
zone: this.hostedZone
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
options.aaaaRecords?.forEach((record, index) => {
|
|
54
|
+
new awsRoute53.AaaaRecord(this, `${id}-AaaaRecord-${index}`, {
|
|
55
|
+
...record,
|
|
56
|
+
zone: this.hostedZone
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
options.cnameRecords?.forEach((record, index) => {
|
|
60
|
+
new awsRoute53.CnameRecord(this, `${id}-CnameRecord-${index}`, {
|
|
61
|
+
...record,
|
|
62
|
+
zone: this.hostedZone
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
options.txtRecords?.forEach((record, index) => {
|
|
66
|
+
new awsRoute53.TxtRecord(this, `${id}-TxtRecord-${index}`, {
|
|
67
|
+
...record,
|
|
68
|
+
zone: this.hostedZone
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
new awsCdkLib.CfnOutput(this, "Route53HostedZoneId", {
|
|
72
|
+
value: this.hostedZone.hostedZoneId
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
exports.BaseRoute53Construct = BaseRoute53Construct;
|
|
78
|
+
//# sourceMappingURL=route53.cjs.map
|
|
79
|
+
//# sourceMappingURL=route53.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/aws/cdk/constructs/route53-construct.ts"],"names":["Construct","HostedZone","CustomException","ARecord","AaaaRecord","CnameRecord","TxtRecord","CfnOutput"],"mappings":";;;;;;;;;AA4GO,IAAM,oBAAA,GAAN,cAAmCA,oBAAA,CAAU;AAAA,EA5GpD;AA4GoD,IAAA,MAAA,CAAA,IAAA,EAAA,sBAAA,CAAA;AAAA;AAAA;AAAA,EAE1C,UAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOT,WAAA,CAAY,KAAA,EAAkB,EAAA,EAAY,KAAA,EAA+B;AACxE,IAAA,KAAA,CAAM,OAAO,EAAE,CAAA;AAEf,IAAA,MAAM,OAAA,GAAU,KAAA,EAAO,OAAA,IAAW,EAAC;AAEnC,IAAA,IAAI,QAAQ,iBAAA,EAAmB;AAC9B,MAAA,IAAA,CAAK,aAAa,IAAIC,qBAAA;AAAA,QACrB,IAAA;AAAA,QACA,GAAG,EAAE,CAAA,WAAA,CAAA;AAAA,QACL,OAAA,CAAQ;AAAA,OACT;AAAA,I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,QACH,MAAM,IAAA,CAAK;AAAA,OACX,CAAA;AAAA,IACF,CAAC,CAAA;AAED,IAAA,OAAA,CAAQ,UAAA,EAAY,OAAA,CAAQ,CAAC,MAAA,EAAQ,KAAA,KAAU;AAC9C,MAAA,IAAIC,qBAAU,IAAA,EAAM,CAAA,EAAG,EAAE,CAAA,WAAA,EAAc,KAAK,CAAA,CAAA,EAAI;AAAA,QAC/C,GAAG,MAAA;AAAA,QACH,MAAM,IAAA,CAAK;AAAA,OACX,CAAA;AAAA,IACF,CAAC,CAAA;AAKD,IAAA,IAAIC,mBAAA,CAAU,MAAM,qBAAA,EAAuB;AAAA,MAC1C,KAAA,EAAO,KAAK,UAAA,CAAW;AAAA,KACvB,CAAA;AAAA,EACF;AACD","file":"route53.cjs","sourcesContent":["import { Construct } from 'constructs';\nimport { CfnOutput } from 'aws-cdk-lib';\nimport {\n\tARecord,\n\tARecordProps,\n\tAaaaRecord,\n\tAaaaRecordProps,\n\tCnameRecord,\n\tCnameRecordProps,\n\tHostedZone,\n\tHostedZoneAttributes,\n\tHostedZoneProps,\n\tHostedZoneProviderProps,\n\tIHostedZone,\n\tTxtRecord,\n\tTxtRecordProps,\n} from 'aws-cdk-lib/aws-route53';\n\nimport { CustomException } from '@incloodsolutions/toolkit';\n\nimport { IBaseCdkConstructProps } from '../../types';\n\n/**\n * Props for BaseRoute53Construct\n *\n * Exactly one of `hostedZoneOptions`, `fromExistingHostedZoneAttributes`, or\n * `fromLookupOptions` must be provided to obtain the hosted zone — a hosted\n * zone is the container Route53 uses to hold every DNS record for one domain.\n * Records are then added to that zone via `aRecords` / `aaaaRecords` /\n * `cnameRecords` / `txtRecords`.\n */\ninterface IRoute53ConstructProps extends Omit<\n\tIBaseCdkConstructProps<{\n\t\t/**\n\t\t * Create a brand-new public hosted zone for `zoneName`. Use this when\n\t\t * Route53 has not yet been given authority over the domain — CDK also\n\t\t * prints the four NS records you must set as the domain's nameservers at\n\t\t * the registrar to actually delegate DNS to this zone.\n\t\t */\n\t\treadonly hostedZoneOptions?: HostedZoneProps;\n\n\t\t/**\n\t\t * Reference an existing hosted zone by its ID and zone name, without\n\t\t * creating a new one. Cheapest and most predictable option — no synth-time\n\t\t * AWS API call, no risk of creating a duplicate zone — but you must already\n\t\t * know the hosted zone ID (from the console, another stack's output, etc.).\n\t\t */\n\t\treadonly fromExistingHostedZoneAttributes?: HostedZoneAttributes;\n\n\t\t/**\n\t\t * Resolve an existing public hosted zone by domain name via an AWS API\n\t\t * call made while CDK synthesises the stack (not at deploy time). Convenient\n\t\t * when you only know the domain name, but requires AWS credentials at synth\n\t\t * and re-runs that lookup (and may cache stale results) on every synth.\n\t\t */\n\t\treadonly fromLookupOptions?: HostedZoneProviderProps;\n\n\t\t/**\n\t\t * `A` records — map this zone (or a subdomain) to one or more IPv4\n\t\t * addresses, or, via `target: RecordTarget.fromAlias(...)`, \"alias\" the\n\t\t * record directly to an AWS resource (CloudFront, API Gateway custom\n\t\t * domain, ALB, another Route53 record, …). Alias `A` records are free,\n\t\t * auto-update if the target's IP changes, and — unlike `CNAME` — are the\n\t\t * only way to point the zone apex (`example.com` itself, not a subdomain)\n\t\t * at an AWS resource. Use this for \"point my (sub)domain at this AWS\n\t\t * service\" or \"point it at a fixed IPv4 address\".\n\t\t */\n\t\treadonly aRecords?: Omit<ARecordProps, 'zone'>[];\n\n\t\t/**\n\t\t * `AAAA` records — the IPv6 counterpart to `A` records: map this zone or a\n\t\t * subdomain to IPv6 addresses, or alias to an AWS resource, the same way\n\t\t * `aRecords` does for IPv4. Add these alongside `aRecords` (not instead of)\n\t\t * when the target also needs to be reachable over IPv6.\n\t\t */\n\t\treadonly aaaaRecords?: Omit<AaaaRecordProps, 'zone'>[];\n\n\t\t/**\n\t\t * `CNAME` records — alias a subdomain to another DNS name (not an IP\n\t\t * address), e.g. `www.example.com` → `example.com`, or a subdomain to a\n\t\t * third-party service's domain (a SaaS custom-domain setup). DNS rules\n\t\t * forbid a `CNAME` at the zone apex and forbid mixing it with any other\n\t\t * record type on the same name — use an alias `A`/`AAAA` record instead\n\t\t * for the apex or for AWS-resource targets.\n\t\t */\n\t\treadonly cnameRecords?: Omit<CnameRecordProps, 'zone'>[];\n\n\t\t/**\n\t\t * `TXT` records — arbitrary text attached to a name, not used for routing\n\t\t * traffic at all. The standard way to prove domain ownership (ACM\n\t\t * certificate DNS validation, Google/Microsoft/other SaaS site\n\t\t * verification) and to publish email-authentication policy (SPF, DKIM,\n\t\t * DMARC). Each string in `values` becomes one quoted TXT value.\n\t\t */\n\t\treadonly txtRecords?: Omit<TxtRecordProps, 'zone'>[];\n\t}>,\n\t'appName' | 'stackName'\n> {}\n\n/**\n * CDK construct for Route53\n *\n * Responsibilities:\n * - Creates a new public hosted zone, imports one by attributes, or looks one\n * up by domain name (exactly one of the three is required)\n * - Optionally attaches `A`, `AAAA`, `CNAME`, and `TXT` records to that zone\n * - Exposes the hosted zone as `.hostedZone` and its ID as a CloudFormation output\n */\nexport class BaseRoute53Construct extends Construct {\n\t/** The hosted zone this construct created, imported, or looked up */\n\treadonly hostedZone: IHostedZone;\n\n\t/**\n\t * @param scope Parent construct\n\t * @param id Unique construct identifier\n\t * @param props Configuration for the hosted zone and its records\n\t */\n\tconstructor(scope: Construct, id: string, props: IRoute53ConstructProps) {\n\t\tsuper(scope, id);\n\n\t\tconst options = props?.options ?? {};\n\n\t\tif (options.hostedZoneOptions) {\n\t\t\tthis.hostedZone = new HostedZone(\n\t\t\t\tthis,\n\t\t\t\t`${id}-HostedZone`,\n\t\t\t\toptions.hostedZoneOptions,\n\t\t\t);\n\t\t} else if (options.fromExistingHostedZoneAttributes) {\n\t\t\tthis.hostedZone = HostedZone.fromHostedZoneAttributes(\n\t\t\t\tthis,\n\t\t\t\t`${id}-HostedZone`,\n\t\t\t\toptions.fromExistingHostedZoneAttributes,\n\t\t\t);\n\t\t} else if (options.fromLookupOptions) {\n\t\t\tthis.hostedZone = HostedZone.fromLookup(\n\t\t\t\tthis,\n\t\t\t\t`${id}-HostedZone`,\n\t\t\t\toptions.fromLookupOptions,\n\t\t\t);\n\t\t} else {\n\t\t\tthrow new CustomException(\n\t\t\t\t'BaseRoute53Construct requires one of hostedZoneOptions, fromExistingHostedZoneAttributes, or fromLookupOptions',\n\t\t\t);\n\t\t}\n\n\t\toptions.aRecords?.forEach((record, index) => {\n\t\t\tnew ARecord(this, `${id}-ARecord-${index}`, {\n\t\t\t\t...record,\n\t\t\t\tzone: this.hostedZone,\n\t\t\t});\n\t\t});\n\n\t\toptions.aaaaRecords?.forEach((record, index) => {\n\t\t\tnew AaaaRecord(this, `${id}-AaaaRecord-${index}`, {\n\t\t\t\t...record,\n\t\t\t\tzone: this.hostedZone,\n\t\t\t});\n\t\t});\n\n\t\toptions.cnameRecords?.forEach((record, index) => {\n\t\t\tnew CnameRecord(this, `${id}-CnameRecord-${index}`, {\n\t\t\t\t...record,\n\t\t\t\tzone: this.hostedZone,\n\t\t\t});\n\t\t});\n\n\t\toptions.txtRecords?.forEach((record, index) => {\n\t\t\tnew TxtRecord(this, `${id}-TxtRecord-${index}`, {\n\t\t\t\t...record,\n\t\t\t\tzone: this.hostedZone,\n\t\t\t});\n\t\t});\n\n\t\t/**\n\t\t * CloudFormation output exposing the Route53 hosted zone ID\n\t\t */\n\t\tnew CfnOutput(this, 'Route53HostedZoneId', {\n\t\t\tvalue: this.hostedZone.hostedZoneId,\n\t\t});\n\t}\n}\n"]}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { Construct } from 'constructs';
|
|
2
|
+
import { IHostedZone, HostedZoneProps, HostedZoneAttributes, HostedZoneProviderProps, ARecordProps, AaaaRecordProps, CnameRecordProps, TxtRecordProps } from 'aws-cdk-lib/aws-route53';
|
|
3
|
+
import { IBaseCdkConstructProps } from '../../aws-types.cjs';
|
|
4
|
+
import '@incloodsolutions/toolkit';
|
|
5
|
+
import 'aws-cdk-lib';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Props for BaseRoute53Construct
|
|
9
|
+
*
|
|
10
|
+
* Exactly one of `hostedZoneOptions`, `fromExistingHostedZoneAttributes`, or
|
|
11
|
+
* `fromLookupOptions` must be provided to obtain the hosted zone — a hosted
|
|
12
|
+
* zone is the container Route53 uses to hold every DNS record for one domain.
|
|
13
|
+
* Records are then added to that zone via `aRecords` / `aaaaRecords` /
|
|
14
|
+
* `cnameRecords` / `txtRecords`.
|
|
15
|
+
*/
|
|
16
|
+
interface IRoute53ConstructProps extends Omit<IBaseCdkConstructProps<{
|
|
17
|
+
/**
|
|
18
|
+
* Create a brand-new public hosted zone for `zoneName`. Use this when
|
|
19
|
+
* Route53 has not yet been given authority over the domain — CDK also
|
|
20
|
+
* prints the four NS records you must set as the domain's nameservers at
|
|
21
|
+
* the registrar to actually delegate DNS to this zone.
|
|
22
|
+
*/
|
|
23
|
+
readonly hostedZoneOptions?: HostedZoneProps;
|
|
24
|
+
/**
|
|
25
|
+
* Reference an existing hosted zone by its ID and zone name, without
|
|
26
|
+
* creating a new one. Cheapest and most predictable option — no synth-time
|
|
27
|
+
* AWS API call, no risk of creating a duplicate zone — but you must already
|
|
28
|
+
* know the hosted zone ID (from the console, another stack's output, etc.).
|
|
29
|
+
*/
|
|
30
|
+
readonly fromExistingHostedZoneAttributes?: HostedZoneAttributes;
|
|
31
|
+
/**
|
|
32
|
+
* Resolve an existing public hosted zone by domain name via an AWS API
|
|
33
|
+
* call made while CDK synthesises the stack (not at deploy time). Convenient
|
|
34
|
+
* when you only know the domain name, but requires AWS credentials at synth
|
|
35
|
+
* and re-runs that lookup (and may cache stale results) on every synth.
|
|
36
|
+
*/
|
|
37
|
+
readonly fromLookupOptions?: HostedZoneProviderProps;
|
|
38
|
+
/**
|
|
39
|
+
* `A` records — map this zone (or a subdomain) to one or more IPv4
|
|
40
|
+
* addresses, or, via `target: RecordTarget.fromAlias(...)`, "alias" the
|
|
41
|
+
* record directly to an AWS resource (CloudFront, API Gateway custom
|
|
42
|
+
* domain, ALB, another Route53 record, …). Alias `A` records are free,
|
|
43
|
+
* auto-update if the target's IP changes, and — unlike `CNAME` — are the
|
|
44
|
+
* only way to point the zone apex (`example.com` itself, not a subdomain)
|
|
45
|
+
* at an AWS resource. Use this for "point my (sub)domain at this AWS
|
|
46
|
+
* service" or "point it at a fixed IPv4 address".
|
|
47
|
+
*/
|
|
48
|
+
readonly aRecords?: Omit<ARecordProps, 'zone'>[];
|
|
49
|
+
/**
|
|
50
|
+
* `AAAA` records — the IPv6 counterpart to `A` records: map this zone or a
|
|
51
|
+
* subdomain to IPv6 addresses, or alias to an AWS resource, the same way
|
|
52
|
+
* `aRecords` does for IPv4. Add these alongside `aRecords` (not instead of)
|
|
53
|
+
* when the target also needs to be reachable over IPv6.
|
|
54
|
+
*/
|
|
55
|
+
readonly aaaaRecords?: Omit<AaaaRecordProps, 'zone'>[];
|
|
56
|
+
/**
|
|
57
|
+
* `CNAME` records — alias a subdomain to another DNS name (not an IP
|
|
58
|
+
* address), e.g. `www.example.com` → `example.com`, or a subdomain to a
|
|
59
|
+
* third-party service's domain (a SaaS custom-domain setup). DNS rules
|
|
60
|
+
* forbid a `CNAME` at the zone apex and forbid mixing it with any other
|
|
61
|
+
* record type on the same name — use an alias `A`/`AAAA` record instead
|
|
62
|
+
* for the apex or for AWS-resource targets.
|
|
63
|
+
*/
|
|
64
|
+
readonly cnameRecords?: Omit<CnameRecordProps, 'zone'>[];
|
|
65
|
+
/**
|
|
66
|
+
* `TXT` records — arbitrary text attached to a name, not used for routing
|
|
67
|
+
* traffic at all. The standard way to prove domain ownership (ACM
|
|
68
|
+
* certificate DNS validation, Google/Microsoft/other SaaS site
|
|
69
|
+
* verification) and to publish email-authentication policy (SPF, DKIM,
|
|
70
|
+
* DMARC). Each string in `values` becomes one quoted TXT value.
|
|
71
|
+
*/
|
|
72
|
+
readonly txtRecords?: Omit<TxtRecordProps, 'zone'>[];
|
|
73
|
+
}>, 'appName' | 'stackName'> {
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* CDK construct for Route53
|
|
77
|
+
*
|
|
78
|
+
* Responsibilities:
|
|
79
|
+
* - Creates a new public hosted zone, imports one by attributes, or looks one
|
|
80
|
+
* up by domain name (exactly one of the three is required)
|
|
81
|
+
* - Optionally attaches `A`, `AAAA`, `CNAME`, and `TXT` records to that zone
|
|
82
|
+
* - Exposes the hosted zone as `.hostedZone` and its ID as a CloudFormation output
|
|
83
|
+
*/
|
|
84
|
+
declare class BaseRoute53Construct extends Construct {
|
|
85
|
+
/** The hosted zone this construct created, imported, or looked up */
|
|
86
|
+
readonly hostedZone: IHostedZone;
|
|
87
|
+
/**
|
|
88
|
+
* @param scope Parent construct
|
|
89
|
+
* @param id Unique construct identifier
|
|
90
|
+
* @param props Configuration for the hosted zone and its records
|
|
91
|
+
*/
|
|
92
|
+
constructor(scope: Construct, id: string, props: IRoute53ConstructProps);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export { BaseRoute53Construct };
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { Construct } from 'constructs';
|
|
2
|
+
import { IHostedZone, HostedZoneProps, HostedZoneAttributes, HostedZoneProviderProps, ARecordProps, AaaaRecordProps, CnameRecordProps, TxtRecordProps } from 'aws-cdk-lib/aws-route53';
|
|
3
|
+
import { IBaseCdkConstructProps } from '../../aws-types.js';
|
|
4
|
+
import '@incloodsolutions/toolkit';
|
|
5
|
+
import 'aws-cdk-lib';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Props for BaseRoute53Construct
|
|
9
|
+
*
|
|
10
|
+
* Exactly one of `hostedZoneOptions`, `fromExistingHostedZoneAttributes`, or
|
|
11
|
+
* `fromLookupOptions` must be provided to obtain the hosted zone — a hosted
|
|
12
|
+
* zone is the container Route53 uses to hold every DNS record for one domain.
|
|
13
|
+
* Records are then added to that zone via `aRecords` / `aaaaRecords` /
|
|
14
|
+
* `cnameRecords` / `txtRecords`.
|
|
15
|
+
*/
|
|
16
|
+
interface IRoute53ConstructProps extends Omit<IBaseCdkConstructProps<{
|
|
17
|
+
/**
|
|
18
|
+
* Create a brand-new public hosted zone for `zoneName`. Use this when
|
|
19
|
+
* Route53 has not yet been given authority over the domain — CDK also
|
|
20
|
+
* prints the four NS records you must set as the domain's nameservers at
|
|
21
|
+
* the registrar to actually delegate DNS to this zone.
|
|
22
|
+
*/
|
|
23
|
+
readonly hostedZoneOptions?: HostedZoneProps;
|
|
24
|
+
/**
|
|
25
|
+
* Reference an existing hosted zone by its ID and zone name, without
|
|
26
|
+
* creating a new one. Cheapest and most predictable option — no synth-time
|
|
27
|
+
* AWS API call, no risk of creating a duplicate zone — but you must already
|
|
28
|
+
* know the hosted zone ID (from the console, another stack's output, etc.).
|
|
29
|
+
*/
|
|
30
|
+
readonly fromExistingHostedZoneAttributes?: HostedZoneAttributes;
|
|
31
|
+
/**
|
|
32
|
+
* Resolve an existing public hosted zone by domain name via an AWS API
|
|
33
|
+
* call made while CDK synthesises the stack (not at deploy time). Convenient
|
|
34
|
+
* when you only know the domain name, but requires AWS credentials at synth
|
|
35
|
+
* and re-runs that lookup (and may cache stale results) on every synth.
|
|
36
|
+
*/
|
|
37
|
+
readonly fromLookupOptions?: HostedZoneProviderProps;
|
|
38
|
+
/**
|
|
39
|
+
* `A` records — map this zone (or a subdomain) to one or more IPv4
|
|
40
|
+
* addresses, or, via `target: RecordTarget.fromAlias(...)`, "alias" the
|
|
41
|
+
* record directly to an AWS resource (CloudFront, API Gateway custom
|
|
42
|
+
* domain, ALB, another Route53 record, …). Alias `A` records are free,
|
|
43
|
+
* auto-update if the target's IP changes, and — unlike `CNAME` — are the
|
|
44
|
+
* only way to point the zone apex (`example.com` itself, not a subdomain)
|
|
45
|
+
* at an AWS resource. Use this for "point my (sub)domain at this AWS
|
|
46
|
+
* service" or "point it at a fixed IPv4 address".
|
|
47
|
+
*/
|
|
48
|
+
readonly aRecords?: Omit<ARecordProps, 'zone'>[];
|
|
49
|
+
/**
|
|
50
|
+
* `AAAA` records — the IPv6 counterpart to `A` records: map this zone or a
|
|
51
|
+
* subdomain to IPv6 addresses, or alias to an AWS resource, the same way
|
|
52
|
+
* `aRecords` does for IPv4. Add these alongside `aRecords` (not instead of)
|
|
53
|
+
* when the target also needs to be reachable over IPv6.
|
|
54
|
+
*/
|
|
55
|
+
readonly aaaaRecords?: Omit<AaaaRecordProps, 'zone'>[];
|
|
56
|
+
/**
|
|
57
|
+
* `CNAME` records — alias a subdomain to another DNS name (not an IP
|
|
58
|
+
* address), e.g. `www.example.com` → `example.com`, or a subdomain to a
|
|
59
|
+
* third-party service's domain (a SaaS custom-domain setup). DNS rules
|
|
60
|
+
* forbid a `CNAME` at the zone apex and forbid mixing it with any other
|
|
61
|
+
* record type on the same name — use an alias `A`/`AAAA` record instead
|
|
62
|
+
* for the apex or for AWS-resource targets.
|
|
63
|
+
*/
|
|
64
|
+
readonly cnameRecords?: Omit<CnameRecordProps, 'zone'>[];
|
|
65
|
+
/**
|
|
66
|
+
* `TXT` records — arbitrary text attached to a name, not used for routing
|
|
67
|
+
* traffic at all. The standard way to prove domain ownership (ACM
|
|
68
|
+
* certificate DNS validation, Google/Microsoft/other SaaS site
|
|
69
|
+
* verification) and to publish email-authentication policy (SPF, DKIM,
|
|
70
|
+
* DMARC). Each string in `values` becomes one quoted TXT value.
|
|
71
|
+
*/
|
|
72
|
+
readonly txtRecords?: Omit<TxtRecordProps, 'zone'>[];
|
|
73
|
+
}>, 'appName' | 'stackName'> {
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* CDK construct for Route53
|
|
77
|
+
*
|
|
78
|
+
* Responsibilities:
|
|
79
|
+
* - Creates a new public hosted zone, imports one by attributes, or looks one
|
|
80
|
+
* up by domain name (exactly one of the three is required)
|
|
81
|
+
* - Optionally attaches `A`, `AAAA`, `CNAME`, and `TXT` records to that zone
|
|
82
|
+
* - Exposes the hosted zone as `.hostedZone` and its ID as a CloudFormation output
|
|
83
|
+
*/
|
|
84
|
+
declare class BaseRoute53Construct extends Construct {
|
|
85
|
+
/** The hosted zone this construct created, imported, or looked up */
|
|
86
|
+
readonly hostedZone: IHostedZone;
|
|
87
|
+
/**
|
|
88
|
+
* @param scope Parent construct
|
|
89
|
+
* @param id Unique construct identifier
|
|
90
|
+
* @param props Configuration for the hosted zone and its records
|
|
91
|
+
*/
|
|
92
|
+
constructor(scope: Construct, id: string, props: IRoute53ConstructProps);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export { BaseRoute53Construct };
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { Construct } from 'constructs';
|
|
2
|
+
import { CfnOutput } from 'aws-cdk-lib';
|
|
3
|
+
import { HostedZone, ARecord, AaaaRecord, CnameRecord, TxtRecord } from 'aws-cdk-lib/aws-route53';
|
|
4
|
+
import { CustomException } from '@incloodsolutions/toolkit';
|
|
5
|
+
|
|
6
|
+
var __defProp = Object.defineProperty;
|
|
7
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
|
+
var BaseRoute53Construct = class extends Construct {
|
|
9
|
+
static {
|
|
10
|
+
__name(this, "BaseRoute53Construct");
|
|
11
|
+
}
|
|
12
|
+
/** The hosted zone this construct created, imported, or looked up */
|
|
13
|
+
hostedZone;
|
|
14
|
+
/**
|
|
15
|
+
* @param scope Parent construct
|
|
16
|
+
* @param id Unique construct identifier
|
|
17
|
+
* @param props Configuration for the hosted zone and its records
|
|
18
|
+
*/
|
|
19
|
+
constructor(scope, id, props) {
|
|
20
|
+
super(scope, id);
|
|
21
|
+
const options = props?.options ?? {};
|
|
22
|
+
if (options.hostedZoneOptions) {
|
|
23
|
+
this.hostedZone = new HostedZone(
|
|
24
|
+
this,
|
|
25
|
+
`${id}-HostedZone`,
|
|
26
|
+
options.hostedZoneOptions
|
|
27
|
+
);
|
|
28
|
+
} else if (options.fromExistingHostedZoneAttributes) {
|
|
29
|
+
this.hostedZone = HostedZone.fromHostedZoneAttributes(
|
|
30
|
+
this,
|
|
31
|
+
`${id}-HostedZone`,
|
|
32
|
+
options.fromExistingHostedZoneAttributes
|
|
33
|
+
);
|
|
34
|
+
} else if (options.fromLookupOptions) {
|
|
35
|
+
this.hostedZone = HostedZone.fromLookup(
|
|
36
|
+
this,
|
|
37
|
+
`${id}-HostedZone`,
|
|
38
|
+
options.fromLookupOptions
|
|
39
|
+
);
|
|
40
|
+
} else {
|
|
41
|
+
throw new CustomException(
|
|
42
|
+
"BaseRoute53Construct requires one of hostedZoneOptions, fromExistingHostedZoneAttributes, or fromLookupOptions"
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
options.aRecords?.forEach((record, index) => {
|
|
46
|
+
new ARecord(this, `${id}-ARecord-${index}`, {
|
|
47
|
+
...record,
|
|
48
|
+
zone: this.hostedZone
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
options.aaaaRecords?.forEach((record, index) => {
|
|
52
|
+
new AaaaRecord(this, `${id}-AaaaRecord-${index}`, {
|
|
53
|
+
...record,
|
|
54
|
+
zone: this.hostedZone
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
options.cnameRecords?.forEach((record, index) => {
|
|
58
|
+
new CnameRecord(this, `${id}-CnameRecord-${index}`, {
|
|
59
|
+
...record,
|
|
60
|
+
zone: this.hostedZone
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
options.txtRecords?.forEach((record, index) => {
|
|
64
|
+
new TxtRecord(this, `${id}-TxtRecord-${index}`, {
|
|
65
|
+
...record,
|
|
66
|
+
zone: this.hostedZone
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
new CfnOutput(this, "Route53HostedZoneId", {
|
|
70
|
+
value: this.hostedZone.hostedZoneId
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
export { BaseRoute53Construct };
|
|
76
|
+
//# sourceMappingURL=route53.js.map
|
|
77
|
+
//# sourceMappingURL=route53.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/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G,MAAA;AAAA,QACH,MAAM,IAAA,CAAK;AAAA,OACX,CAAA;AAAA,IACF,CAAC,CAAA;AAED,IAAA,OAAA,CAAQ,WAAA,EAAa,OAAA,CAAQ,CAAC,MAAA,EAAQ,KAAA,KAAU;AAC/C,MAAA,IAAI,WAAW,IAAA,EAAM,CAAA,EAAG,EAAE,CAAA,YAAA,EAAe,KAAK,CAAA,CAAA,EAAI;AAAA,QACjD,GAAG,MAAA;AAAA,QACH,MAAM,IAAA,CAAK;AAAA,OACX,CAAA;AAAA,IACF,CAAC,CAAA;AAED,IAAA,OAAA,CAAQ,YAAA,EAAc,OAAA,CAAQ,CAAC,MAAA,EAAQ,KAAA,KAAU;AAChD,MAAA,IAAI,YAAY,IAAA,EAAM,CAAA,EAAG,EAAE,CAAA,aAAA,EAAgB,KAAK,CAAA,CAAA,EAAI;AAAA,QACnD,GAAG,MAAA;AAAA,QACH,MAAM,IAAA,CAAK;AAAA,OACX,CAAA;AAAA,IACF,CAAC,CAAA;AAED,IAAA,OAAA,CAAQ,UAAA,EAAY,OAAA,CAAQ,CAAC,MAAA,EAAQ,KAAA,KAAU;AAC9C,MAAA,IAAI,UAAU,IAAA,EAAM,CAAA,EAAG,EAAE,CAAA,WAAA,EAAc,KAAK,CAAA,CAAA,EAAI;AAAA,QAC/C,GAAG,MAAA;AAAA,QACH,MAAM,IAAA,CAAK;AAAA,OACX,CAAA;AAAA,IACF,CAAC,CAAA;AAKD,IAAA,IAAI,SAAA,CAAU,MAAM,qBAAA,EAAuB;AAAA,MAC1C,KAAA,EAAO,KAAK,UAAA,CAAW;AAAA,KACvB,CAAA;AAAA,EACF;AACD","file":"route53.js","sourcesContent":["import { Construct } from 'constructs';\nimport { CfnOutput } from 'aws-cdk-lib';\nimport {\n\tARecord,\n\tARecordProps,\n\tAaaaRecord,\n\tAaaaRecordProps,\n\tCnameRecord,\n\tCnameRecordProps,\n\tHostedZone,\n\tHostedZoneAttributes,\n\tHostedZoneProps,\n\tHostedZoneProviderProps,\n\tIHostedZone,\n\tTxtRecord,\n\tTxtRecordProps,\n} from 'aws-cdk-lib/aws-route53';\n\nimport { CustomException } from '@incloodsolutions/toolkit';\n\nimport { IBaseCdkConstructProps } from '../../types';\n\n/**\n * Props for BaseRoute53Construct\n *\n * Exactly one of `hostedZoneOptions`, `fromExistingHostedZoneAttributes`, or\n * `fromLookupOptions` must be provided to obtain the hosted zone — a hosted\n * zone is the container Route53 uses to hold every DNS record for one domain.\n * Records are then added to that zone via `aRecords` / `aaaaRecords` /\n * `cnameRecords` / `txtRecords`.\n */\ninterface IRoute53ConstructProps extends Omit<\n\tIBaseCdkConstructProps<{\n\t\t/**\n\t\t * Create a brand-new public hosted zone for `zoneName`. Use this when\n\t\t * Route53 has not yet been given authority over the domain — CDK also\n\t\t * prints the four NS records you must set as the domain's nameservers at\n\t\t * the registrar to actually delegate DNS to this zone.\n\t\t */\n\t\treadonly hostedZoneOptions?: HostedZoneProps;\n\n\t\t/**\n\t\t * Reference an existing hosted zone by its ID and zone name, without\n\t\t * creating a new one. Cheapest and most predictable option — no synth-time\n\t\t * AWS API call, no risk of creating a duplicate zone — but you must already\n\t\t * know the hosted zone ID (from the console, another stack's output, etc.).\n\t\t */\n\t\treadonly fromExistingHostedZoneAttributes?: HostedZoneAttributes;\n\n\t\t/**\n\t\t * Resolve an existing public hosted zone by domain name via an AWS API\n\t\t * call made while CDK synthesises the stack (not at deploy time). Convenient\n\t\t * when you only know the domain name, but requires AWS credentials at synth\n\t\t * and re-runs that lookup (and may cache stale results) on every synth.\n\t\t */\n\t\treadonly fromLookupOptions?: HostedZoneProviderProps;\n\n\t\t/**\n\t\t * `A` records — map this zone (or a subdomain) to one or more IPv4\n\t\t * addresses, or, via `target: RecordTarget.fromAlias(...)`, \"alias\" the\n\t\t * record directly to an AWS resource (CloudFront, API Gateway custom\n\t\t * domain, ALB, another Route53 record, …). Alias `A` records are free,\n\t\t * auto-update if the target's IP changes, and — unlike `CNAME` — are the\n\t\t * only way to point the zone apex (`example.com` itself, not a subdomain)\n\t\t * at an AWS resource. Use this for \"point my (sub)domain at this AWS\n\t\t * service\" or \"point it at a fixed IPv4 address\".\n\t\t */\n\t\treadonly aRecords?: Omit<ARecordProps, 'zone'>[];\n\n\t\t/**\n\t\t * `AAAA` records — the IPv6 counterpart to `A` records: map this zone or a\n\t\t * subdomain to IPv6 addresses, or alias to an AWS resource, the same way\n\t\t * `aRecords` does for IPv4. Add these alongside `aRecords` (not instead of)\n\t\t * when the target also needs to be reachable over IPv6.\n\t\t */\n\t\treadonly aaaaRecords?: Omit<AaaaRecordProps, 'zone'>[];\n\n\t\t/**\n\t\t * `CNAME` records — alias a subdomain to another DNS name (not an IP\n\t\t * address), e.g. `www.example.com` → `example.com`, or a subdomain to a\n\t\t * third-party service's domain (a SaaS custom-domain setup). DNS rules\n\t\t * forbid a `CNAME` at the zone apex and forbid mixing it with any other\n\t\t * record type on the same name — use an alias `A`/`AAAA` record instead\n\t\t * for the apex or for AWS-resource targets.\n\t\t */\n\t\treadonly cnameRecords?: Omit<CnameRecordProps, 'zone'>[];\n\n\t\t/**\n\t\t * `TXT` records — arbitrary text attached to a name, not used for routing\n\t\t * traffic at all. The standard way to prove domain ownership (ACM\n\t\t * certificate DNS validation, Google/Microsoft/other SaaS site\n\t\t * verification) and to publish email-authentication policy (SPF, DKIM,\n\t\t * DMARC). Each string in `values` becomes one quoted TXT value.\n\t\t */\n\t\treadonly txtRecords?: Omit<TxtRecordProps, 'zone'>[];\n\t}>,\n\t'appName' | 'stackName'\n> {}\n\n/**\n * CDK construct for Route53\n *\n * Responsibilities:\n * - Creates a new public hosted zone, imports one by attributes, or looks one\n * up by domain name (exactly one of the three is required)\n * - Optionally attaches `A`, `AAAA`, `CNAME`, and `TXT` records to that zone\n * - Exposes the hosted zone as `.hostedZone` and its ID as a CloudFormation output\n */\nexport class BaseRoute53Construct extends Construct {\n\t/** The hosted zone this construct created, imported, or looked up */\n\treadonly hostedZone: IHostedZone;\n\n\t/**\n\t * @param scope Parent construct\n\t * @param id Unique construct identifier\n\t * @param props Configuration for the hosted zone and its records\n\t */\n\tconstructor(scope: Construct, id: string, props: IRoute53ConstructProps) {\n\t\tsuper(scope, id);\n\n\t\tconst options = props?.options ?? {};\n\n\t\tif (options.hostedZoneOptions) {\n\t\t\tthis.hostedZone = new HostedZone(\n\t\t\t\tthis,\n\t\t\t\t`${id}-HostedZone`,\n\t\t\t\toptions.hostedZoneOptions,\n\t\t\t);\n\t\t} else if (options.fromExistingHostedZoneAttributes) {\n\t\t\tthis.hostedZone = HostedZone.fromHostedZoneAttributes(\n\t\t\t\tthis,\n\t\t\t\t`${id}-HostedZone`,\n\t\t\t\toptions.fromExistingHostedZoneAttributes,\n\t\t\t);\n\t\t} else if (options.fromLookupOptions) {\n\t\t\tthis.hostedZone = HostedZone.fromLookup(\n\t\t\t\tthis,\n\t\t\t\t`${id}-HostedZone`,\n\t\t\t\toptions.fromLookupOptions,\n\t\t\t);\n\t\t} else {\n\t\t\tthrow new CustomException(\n\t\t\t\t'BaseRoute53Construct requires one of hostedZoneOptions, fromExistingHostedZoneAttributes, or fromLookupOptions',\n\t\t\t);\n\t\t}\n\n\t\toptions.aRecords?.forEach((record, index) => {\n\t\t\tnew ARecord(this, `${id}-ARecord-${index}`, {\n\t\t\t\t...record,\n\t\t\t\tzone: this.hostedZone,\n\t\t\t});\n\t\t});\n\n\t\toptions.aaaaRecords?.forEach((record, index) => {\n\t\t\tnew AaaaRecord(this, `${id}-AaaaRecord-${index}`, {\n\t\t\t\t...record,\n\t\t\t\tzone: this.hostedZone,\n\t\t\t});\n\t\t});\n\n\t\toptions.cnameRecords?.forEach((record, index) => {\n\t\t\tnew CnameRecord(this, `${id}-CnameRecord-${index}`, {\n\t\t\t\t...record,\n\t\t\t\tzone: this.hostedZone,\n\t\t\t});\n\t\t});\n\n\t\toptions.txtRecords?.forEach((record, index) => {\n\t\t\tnew TxtRecord(this, `${id}-TxtRecord-${index}`, {\n\t\t\t\t...record,\n\t\t\t\tzone: this.hostedZone,\n\t\t\t});\n\t\t});\n\n\t\t/**\n\t\t * CloudFormation output exposing the Route53 hosted zone ID\n\t\t */\n\t\tnew CfnOutput(this, 'Route53HostedZoneId', {\n\t\t\tvalue: this.hostedZone.hostedZoneId,\n\t\t});\n\t}\n}\n"]}
|
|
@@ -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","Bucket","RemovalPolicy","CfnOutput","Distribution","ViewerProtocolPolicy","Duration","CustomException","S3BucketOrigin","BucketDeployment"],"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,CAAA;AC9BO,IAAM,uBAAA,GAAN,cAAsCH,oBAAAA,CAAU;AAAA,EAhCvD;AAgCuD,IAAA,MAAA,CAAA,IAAA,EAAA,yBAAA,CAAA;AAAA;AAAA;AAAA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,iBAAA,EAAmB;AAAA,YAClB,GAAG,MAAM,OAAA,EAAS,iBAAA;AAAA;AAAA;AAAA;AAAA,YAKlB,qBAAqB,MAAA,CAAO,OAAA;AAAA,cAC3B,KAAA,CAAM,OAAA,EAAS,iBAAA,EAAmB,mBAAA,IAAuB;AAAC,aAC3D,CAAE,MAAA;AAAA,cACD,CAAC,QAAA,EAAU,CAAC,OAAA,EAAS,eAAe,CAAA,KAAM;AACzC,gBAAA,QAAA,CAAS,OAAO,CAAA,GAAI;AAAA,kBACnB,GAAG,eAAA;AAAA,kBACH,MAAA,EAAQ,gBAAgB,MAAA,IAAU;AAAA,iBACnC;AACA,gBAAA,OAAO,QAAA;AAAA,cACR,CAAA;AAAA,cACA;AAAC,aACF;AAAA;AAAA;AAAA;AAAA,YAKA,eAAA,EAAiB;AAAA,cAChB,GAAG,KAAA,CAAM,OAAA,EAAS,iBAAA,EAAmB,eAAA;AAAA,cACrC,MAAA,EAAQ;AAAA;AACT;AACD;AACD,OACA,CAAA,CAAE,YAAA;AAAA,IACJ;AAUA,IAAA,IAAA,CAAK,gBAAA,GAAmB,IAAIC,gCAAA,CAAiB,IAAA,EAAM,YAAA,EAAc;AAAA,MAChE,GAAG,MAAM,OAAA,EAAS,uBAAA;AAAA;AAAA,MAGlB,YAAA,EACC,KAAA,CAAM,OAAA,EAAS,uBAAA,EAAyB,gBACxC,IAAA,CAAK,YAAA;AAAA;AAAA,MAGN,mBAAmB,KAAA,CAAM,OAAA,EAAS,uBAAA,EAC/B,iBAAA,IAAqB,CAAC,IAAI,CAAA;AAAA;AAAA,MAG7B,iBAAA,EACC,KAAA,CAAM,OAAA,EAAS,uBAAA,EAAyB,qBACxC,IAAA,CAAK;AAAA,KACmB,CAAA;AAAA,EAC3B;AACD","file":"s3-deployment.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","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"]}
|
|
@@ -3,7 +3,8 @@ import { Bucket, BucketProps } from 'aws-cdk-lib/aws-s3';
|
|
|
3
3
|
import { BucketDeployment, BucketDeploymentProps } from 'aws-cdk-lib/aws-s3-deployment';
|
|
4
4
|
import { Distribution, DistributionProps, BehaviorOptions } from 'aws-cdk-lib/aws-cloudfront';
|
|
5
5
|
import { ObjectType } from '@incloodsolutions/toolkit';
|
|
6
|
-
import { IBaseCdkConstructProps } from '
|
|
6
|
+
import { IBaseCdkConstructProps } from '../../aws-types.cjs';
|
|
7
|
+
import 'aws-cdk-lib';
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Props for BaseS3DeploymentConstruct
|
|
@@ -3,7 +3,8 @@ import { Bucket, BucketProps } from 'aws-cdk-lib/aws-s3';
|
|
|
3
3
|
import { BucketDeployment, BucketDeploymentProps } from 'aws-cdk-lib/aws-s3-deployment';
|
|
4
4
|
import { Distribution, DistributionProps, BehaviorOptions } from 'aws-cdk-lib/aws-cloudfront';
|
|
5
5
|
import { ObjectType } from '@incloodsolutions/toolkit';
|
|
6
|
-
import { IBaseCdkConstructProps } from '
|
|
6
|
+
import { IBaseCdkConstructProps } from '../../aws-types.js';
|
|
7
|
+
import 'aws-cdk-lib';
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Props for BaseS3DeploymentConstruct
|