cdk-factory 0.13.1__py3-none-any.whl → 0.13.4__py3-none-any.whl

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.

Potentially problematic release.


This version of cdk-factory might be problematic. Click here for more details.

@@ -118,11 +118,17 @@ class CloudFrontDistributionConstruct(Construct):
118
118
  origin_access_identity=self.oai,
119
119
  )
120
120
 
121
+ # Get comment from config, or use default
122
+ comment = "CloudFront Distribution generated via the CDK Factory"
123
+ if self.stack_config and isinstance(self.stack_config, StackConfig):
124
+ cloudfront_config = self.stack_config.dictionary.get("cloudfront", {})
125
+ comment = cloudfront_config.get("comment", comment)
126
+
121
127
  distribution = cloudfront.Distribution(
122
128
  self,
123
129
  "cloudfront-dist",
124
130
  domain_names=self.aliases,
125
- comment="CloudFront Distribution generated via the CDK Factory",
131
+ comment=comment,
126
132
  certificate=self.certificate,
127
133
  default_behavior=cloudfront.BehaviorOptions(
128
134
  origin=origin,
@@ -228,6 +234,15 @@ class CloudFrontDistributionConstruct(Construct):
228
234
  """
229
235
  Get the Lambda@Edge associations for the distribution from config.
230
236
 
237
+ Supports two configuration methods:
238
+ 1. Convenience flag: "enable_ip_gating": true
239
+ - Automatically adds Lambda@Edge IP gating function
240
+ - Uses auto-derived SSM parameter path: /{env}/{workload}/lambda-edge/version-arn
241
+
242
+ 2. Manual configuration: "lambda_edge_associations": [...]
243
+ - Full control over Lambda@Edge associations
244
+ - Can specify custom ARNs, event types, etc.
245
+
231
246
  Returns:
232
247
  List[cloudfront.EdgeLambda] or None: list of Lambda@Edge associations
233
248
  """
@@ -235,7 +250,33 @@ class CloudFrontDistributionConstruct(Construct):
235
250
 
236
251
  if self.stack_config and isinstance(self.stack_config, StackConfig):
237
252
  cloudfront_config = self.stack_config.dictionary.get("cloudfront", {})
238
- lambda_edge_associations = cloudfront_config.get("lambda_edge_associations", [])
253
+
254
+ # Check for convenience IP gating flag
255
+ enable_ip_gating = cloudfront_config.get("enable_ip_gating", False)
256
+ if enable_ip_gating:
257
+ logger.info("IP gating enabled via convenience flag - adding Lambda@Edge association")
258
+
259
+ # Extract environment and workload name from config
260
+ # These come from the workload/deployment configuration
261
+ workload_dict = self.stack_config.workload
262
+ environment = workload_dict.get("deployment", {}).get("environment", "dev")
263
+ workload_name = workload_dict.get("name", "workload")
264
+
265
+ # Auto-derive SSM parameter path or use override
266
+ default_ssm_path = f"/{environment}/{workload_name}/lambda-edge/version-arn"
267
+ ip_gate_ssm_path = cloudfront_config.get("ip_gate_function_ssm_path", default_ssm_path)
268
+
269
+ logger.info(f"Using IP gate Lambda ARN from SSM: {ip_gate_ssm_path}")
270
+
271
+ # Add the IP gating Lambda@Edge association
272
+ lambda_edge_associations = [{
273
+ "event_type": "origin-request",
274
+ "lambda_arn": f"{{{{ssm:{ip_gate_ssm_path}}}}}",
275
+ "include_body": False
276
+ }]
277
+ else:
278
+ # Use manual configuration
279
+ lambda_edge_associations = cloudfront_config.get("lambda_edge_associations", [])
239
280
 
240
281
  for association in lambda_edge_associations:
241
282
  event_type_str = association.get("event_type", "origin-request")
@@ -11,6 +11,7 @@ from pathlib import Path
11
11
  import json
12
12
  import tempfile
13
13
  import shutil
14
+ import importlib.resources
14
15
 
15
16
  import aws_cdk as cdk
16
17
  from aws_cdk import aws_lambda as _lambda
@@ -86,7 +87,10 @@ class LambdaEdgeStack(IStack, EnhancedSsmParameterMixin):
86
87
  deployment
87
88
  )
88
89
 
89
- function_name = deployment.build_resource_name(self.edge_config.name)
90
+ # Use the Lambda function name from config (supports template variables)
91
+ # e.g., "{{WORKLOAD_NAME}}-{{ENVIRONMENT}}-ip-gate" becomes "tech-talk-dev-ip-gate"
92
+ function_name = self.edge_config.name
93
+ logger.info(f"Lambda function name: '{function_name}'")
90
94
 
91
95
  # Create Lambda function
92
96
  self._create_lambda_function(function_name)
@@ -128,11 +132,38 @@ class LambdaEdgeStack(IStack, EnhancedSsmParameterMixin):
128
132
  def _create_lambda_function(self, function_name: str) -> None:
129
133
  """Create the Lambda function"""
130
134
 
131
- # Resolve code path (relative to runtime directory or absolute)
132
- code_path = Path(self.edge_config.code_path)
133
- if not code_path.is_absolute():
134
- # Assume relative to the project root
135
- code_path = Path.cwd() / code_path
135
+ # Resolve code path - support package references (e.g., "cdk_factory:lambdas/edge/ip_gate")
136
+ code_path_str = self.edge_config.code_path
137
+
138
+ if ':' in code_path_str:
139
+ # Package reference format: "package_name:path/within/package"
140
+ package_name, package_path = code_path_str.split(':', 1)
141
+ logger.info(f"Resolving package reference: {package_name}:{package_path}")
142
+
143
+ try:
144
+ # Get the package's installed location
145
+ if hasattr(importlib.resources, 'files'):
146
+ # Python 3.9+
147
+ package_root = importlib.resources.files(package_name)
148
+ code_path = Path(str(package_root / package_path))
149
+ else:
150
+ # Fallback for older Python
151
+ import pkg_resources
152
+ package_root = pkg_resources.resource_filename(package_name, '')
153
+ code_path = Path(package_root) / package_path
154
+
155
+ logger.info(f"Resolved package path to: {code_path}")
156
+ except Exception as e:
157
+ raise FileNotFoundError(
158
+ f"Could not resolve package reference '{code_path_str}': {e}\n"
159
+ f"Make sure package '{package_name}' is installed."
160
+ )
161
+ else:
162
+ # Regular file path
163
+ code_path = Path(code_path_str)
164
+ if not code_path.is_absolute():
165
+ # Assume relative to the project root
166
+ code_path = Path.cwd() / code_path
136
167
 
137
168
  if not code_path.exists():
138
169
  raise FileNotFoundError(
@@ -153,9 +184,10 @@ class LambdaEdgeStack(IStack, EnhancedSsmParameterMixin):
153
184
 
154
185
  # Create runtime configuration file for Lambda@Edge
155
186
  # Since Lambda@Edge doesn't support environment variables, we bundle a config file
187
+ # Use the full function_name (e.g., "tech-talk-dev-ip-gate") not just the base name
156
188
  runtime_config = {
157
189
  'environment': self.deployment.environment,
158
- 'function_name': self.edge_config.name,
190
+ 'function_name': function_name,
159
191
  'region': self.deployment.region
160
192
  }
161
193
 
cdk_factory/version.py CHANGED
@@ -1 +1 @@
1
- __version__ = "0.13.1"
1
+ __version__ = "0.13.4"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cdk_factory
3
- Version: 0.13.1
3
+ Version: 0.13.4
4
4
  Summary: CDK Factory. A QuickStarter and best practices setup for CDK projects
5
5
  Author-email: Eric Wilson <eric.wilson@geekcafe.com>
6
6
  License: MIT License
@@ -2,7 +2,7 @@ cdk_factory/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
2
  cdk_factory/app.py,sha256=RnX0-pwdTAPAdKJK_j13Zl8anf9zYKBwboR0KA8K8xM,10346
3
3
  cdk_factory/cdk.json,sha256=SKZKhJ2PBpFH78j-F8S3VDYW-lf76--Q2I3ON-ZIQfw,3106
4
4
  cdk_factory/cli.py,sha256=FGbCTS5dYCNsfp-etshzvFlGDCjC28r6rtzYbe7KoHI,6407
5
- cdk_factory/version.py,sha256=Zg3oo58_HXe_ieb_PwWnYkKGH2zTvu6G2jly-7GnPGo,23
5
+ cdk_factory/version.py,sha256=6QrvAtwvKbCiayGvUAi82njNCcPWhkMC4sBk4mXPkIc,23
6
6
  cdk_factory/builds/README.md,sha256=9BBWd7bXpyKdMU_g2UljhQwrC9i5O_Tvkb6oPvndoZk,90
7
7
  cdk_factory/commands/command_loader.py,sha256=QbLquuP_AdxtlxlDy-2IWCQ6D-7qa58aphnDPtp_uTs,3744
8
8
  cdk_factory/configurations/base_config.py,sha256=JKjhNsy0RCUZy1s8n5D_aXXI-upR9izaLtCTfKYiV9k,9624
@@ -50,7 +50,7 @@ cdk_factory/configurations/resources/security_group.py,sha256=8kQtaaRVEn2aDm8XoC
50
50
  cdk_factory/configurations/resources/security_group_full_stack.py,sha256=x5MIMCa_olO7prFBKx9zVOfvsVdKo-2mWyhrCy27dFw,2031
51
51
  cdk_factory/configurations/resources/sqs.py,sha256=fAh2dqttJ6PX46enFRULuiLEu3TEj0Vb2xntAOgUpYE,4346
52
52
  cdk_factory/configurations/resources/vpc.py,sha256=sNn6w76bHFwmt6N76gZZhqpsuNB9860C1SZu6tebaXY,3835
53
- cdk_factory/constructs/cloudfront/cloudfront_distribution_construct.py,sha256=ZTlRUFhfrkIv95buChJiNh-nd_hmGjUxT5LaPScStgY,17902
53
+ cdk_factory/constructs/cloudfront/cloudfront_distribution_construct.py,sha256=MS3xrjm1I4gnUZorh2Orc6oi_fZE_ZPU29czDDhiD_A,20072
54
54
  cdk_factory/constructs/ecr/ecr_construct.py,sha256=JLz3gWrsjlM0XghvbgxuoGlF-VIo_7IYxtgX7mTkidE,10660
55
55
  cdk_factory/constructs/lambdas/lambda_function_construct.py,sha256=SQ5SEXn4kezVAzXuv_A_JB3o_svyBXOMi-htvfB9HQs,4516
56
56
  cdk_factory/constructs/lambdas/lambda_function_docker_construct.py,sha256=aSyn3eh1YnuIahZ7CbZ5WswwPL8u70ZibMoS24QQifc,9907
@@ -95,7 +95,7 @@ cdk_factory/stack_library/ecr/ecr_stack.py,sha256=1xA68sxFVyqreYjXrP_7U9I8RF9RtF
95
95
  cdk_factory/stack_library/ecs/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
96
96
  cdk_factory/stack_library/ecs/ecs_service_stack.py,sha256=zuGdZEP5KmeVDTJb-H47LYhvs-85-Fi4Xb78nsA-lF4,24685
97
97
  cdk_factory/stack_library/lambda_edge/__init__.py,sha256=ByBJ_CWdc4UtTmFBZH-6pzBMNkjkdtE65AmnB0Fs6lM,156
98
- cdk_factory/stack_library/lambda_edge/lambda_edge_stack.py,sha256=5MXYXFLVpLX2DNDU9doRfUciyS8h1KM6YdpiiEAkMqY,14141
98
+ cdk_factory/stack_library/lambda_edge/lambda_edge_stack.py,sha256=kTPjvS-IqBbYyqLG-YUtfiVrkX4HFUTzXamzdflDtCE,15780
99
99
  cdk_factory/stack_library/load_balancer/__init__.py,sha256=wZpKw2OecLJGdF5mPayCYAEhu2H3c2gJFFIxwXftGDU,52
100
100
  cdk_factory/stack_library/load_balancer/load_balancer_stack.py,sha256=t5JUe5lMUbQCRFZR08k8nO-g-53yWY8gKB9v8ZnedBs,24391
101
101
  cdk_factory/stack_library/monitoring/__init__.py,sha256=k1G_KDx47Aw0UugaL99PN_TKlyLK4nkJVApCaAK7GJg,153
@@ -129,8 +129,8 @@ cdk_factory/utilities/lambda_function_utilities.py,sha256=S1GvBsY_q2cyUiaud3HORJ
129
129
  cdk_factory/utilities/os_execute.py,sha256=5Op0LY_8Y-pUm04y1k8MTpNrmQvcLmQHPQITEP7EuSU,1019
130
130
  cdk_factory/utils/api_gateway_utilities.py,sha256=If7Xu5s_UxmuV-kL3JkXxPLBdSVUKoLtohm0IUFoiV8,4378
131
131
  cdk_factory/workload/workload_factory.py,sha256=mM8GU_5mKq_0OyK060T3JrUSUiGAcKf0eqNlT9mfaws,6028
132
- cdk_factory-0.13.1.dist-info/METADATA,sha256=GC7Guc1LQ_wDzflKXg8VUxUj7ra97GYDF66Ugz3p0eE,2451
133
- cdk_factory-0.13.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
134
- cdk_factory-0.13.1.dist-info/entry_points.txt,sha256=S1DPe0ORcdiwEALMN_WIo3UQrW_g4YdQCLEsc_b0Swg,53
135
- cdk_factory-0.13.1.dist-info/licenses/LICENSE,sha256=NOtdOeLwg2il_XBJdXUPFPX8JlV4dqTdDGAd2-khxT8,1066
136
- cdk_factory-0.13.1.dist-info/RECORD,,
132
+ cdk_factory-0.13.4.dist-info/METADATA,sha256=sGZgb7401ZPUYcigvG6cwLfwArL98CJnL4U5O3mgeL8,2451
133
+ cdk_factory-0.13.4.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
134
+ cdk_factory-0.13.4.dist-info/entry_points.txt,sha256=S1DPe0ORcdiwEALMN_WIo3UQrW_g4YdQCLEsc_b0Swg,53
135
+ cdk_factory-0.13.4.dist-info/licenses/LICENSE,sha256=NOtdOeLwg2il_XBJdXUPFPX8JlV4dqTdDGAd2-khxT8,1066
136
+ cdk_factory-0.13.4.dist-info/RECORD,,