cdk-factory 0.9.11__py3-none-any.whl → 0.10.0__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.

Files changed (24) hide show
  1. cdk_factory/app.py +39 -8
  2. cdk_factory/configurations/resources/auto_scaling.py +27 -0
  3. cdk_factory/configurations/resources/cloudfront.py +101 -11
  4. cdk_factory/configurations/resources/ecs_service.py +12 -0
  5. cdk_factory/configurations/resources/lambda_edge.py +92 -0
  6. cdk_factory/configurations/resources/monitoring.py +74 -0
  7. cdk_factory/constructs/cloudfront/cloudfront_distribution_construct.py +51 -1
  8. cdk_factory/lambdas/edge/ip_gate/handler.py +104 -0
  9. cdk_factory/pipeline/pipeline_factory.py +1 -0
  10. cdk_factory/stack_library/auto_scaling/auto_scaling_stack.py +99 -0
  11. cdk_factory/stack_library/cloudfront/__init__.py +6 -0
  12. cdk_factory/stack_library/cloudfront/cloudfront_stack.py +627 -0
  13. cdk_factory/stack_library/ecs/ecs_service_stack.py +90 -0
  14. cdk_factory/stack_library/lambda_edge/__init__.py +6 -0
  15. cdk_factory/stack_library/lambda_edge/lambda_edge_stack.py +217 -0
  16. cdk_factory/stack_library/monitoring/__init__.py +6 -0
  17. cdk_factory/stack_library/monitoring/monitoring_stack.py +492 -0
  18. cdk_factory/version.py +1 -1
  19. cdk_factory/workload/workload_factory.py +2 -0
  20. {cdk_factory-0.9.11.dist-info → cdk_factory-0.10.0.dist-info}/METADATA +1 -1
  21. {cdk_factory-0.9.11.dist-info → cdk_factory-0.10.0.dist-info}/RECORD +24 -15
  22. {cdk_factory-0.9.11.dist-info → cdk_factory-0.10.0.dist-info}/WHEEL +0 -0
  23. {cdk_factory-0.9.11.dist-info → cdk_factory-0.10.0.dist-info}/entry_points.txt +0 -0
  24. {cdk_factory-0.9.11.dist-info → cdk_factory-0.10.0.dist-info}/licenses/LICENSE +0 -0
@@ -193,6 +193,41 @@ class AutoScalingStack(IStack, EnhancedSsmParameterMixin):
193
193
  iam.ManagedPolicy.from_aws_managed_policy_name(policy_name)
194
194
  )
195
195
 
196
+ # Add inline policies (for custom permissions like S3 bucket access)
197
+ for policy_config in self.asg_config.iam_inline_policies:
198
+ policy_name = policy_config.get("name", "CustomPolicy")
199
+ statements = policy_config.get("statements", [])
200
+
201
+ if not statements:
202
+ logger.warning(f"No statements found for inline policy {policy_name}, skipping")
203
+ continue
204
+
205
+ # Build policy statements
206
+ policy_statements = []
207
+ for stmt in statements:
208
+ effect = iam.Effect.ALLOW if stmt.get("effect", "Allow") == "Allow" else iam.Effect.DENY
209
+ actions = stmt.get("actions", [])
210
+ resources = stmt.get("resources", [])
211
+
212
+ if not actions or not resources:
213
+ logger.warning(f"Incomplete statement in policy {policy_name}, skipping")
214
+ continue
215
+
216
+ policy_statements.append(
217
+ iam.PolicyStatement(
218
+ effect=effect,
219
+ actions=actions,
220
+ resources=resources
221
+ )
222
+ )
223
+
224
+ if policy_statements:
225
+ role.add_to_principal_policy(policy_statements[0])
226
+ for stmt in policy_statements[1:]:
227
+ role.add_to_principal_policy(stmt)
228
+
229
+ logger.info(f"Added inline policy {policy_name} with {len(policy_statements)} statements")
230
+
196
231
  return role
197
232
 
198
233
  def _create_user_data(self) -> ec2.UserData:
@@ -206,6 +241,10 @@ class AutoScalingStack(IStack, EnhancedSsmParameterMixin):
206
241
  for command in self.asg_config.user_data_commands:
207
242
  user_data.add_commands(command)
208
243
 
244
+ # Add user data scripts from files (with variable substitution)
245
+ if self.asg_config.user_data_scripts:
246
+ self._add_user_data_scripts_from_files(user_data)
247
+
209
248
  # Add container configuration if specified
210
249
  container_config = self.asg_config.container_config
211
250
  if container_config:
@@ -213,6 +252,66 @@ class AutoScalingStack(IStack, EnhancedSsmParameterMixin):
213
252
 
214
253
  return user_data
215
254
 
255
+ def _add_user_data_scripts_from_files(self, user_data: ec2.UserData) -> None:
256
+ """
257
+ Add user data scripts from external files with variable substitution.
258
+ Supports loading shell scripts and injecting them into user data with
259
+ placeholder replacement.
260
+ """
261
+ from pathlib import Path
262
+
263
+ for script_config in self.asg_config.user_data_scripts:
264
+ script_type = script_config.get("type", "file")
265
+
266
+ if script_type == "file":
267
+ # Load script from file
268
+ script_path = script_config.get("path")
269
+ if not script_path:
270
+ logger.warning("Script path not specified, skipping")
271
+ continue
272
+
273
+ # Resolve path (relative to project root or absolute)
274
+ path = Path(script_path)
275
+ if not path.is_absolute():
276
+ # Try relative to current working directory
277
+ path = Path.cwd() / script_path
278
+
279
+ if not path.exists():
280
+ logger.warning(f"Script file not found: {path}, skipping")
281
+ continue
282
+
283
+ # Read script content
284
+ try:
285
+ with open(path, 'r') as f:
286
+ script_content = f.read()
287
+ except Exception as e:
288
+ logger.error(f"Failed to read script file {path}: {e}")
289
+ continue
290
+
291
+ elif script_type == "inline":
292
+ # Use inline script content
293
+ script_content = script_config.get("content", "")
294
+ if not script_content:
295
+ logger.warning("Inline script content is empty, skipping")
296
+ continue
297
+ else:
298
+ logger.warning(f"Unknown script type: {script_type}, skipping")
299
+ continue
300
+
301
+ # Perform variable substitution
302
+ variables = script_config.get("variables", {})
303
+ for var_name, var_value in variables.items():
304
+ placeholder = f"{{{{{var_name}}}}}" # {{VAR_NAME}}
305
+ script_content = script_content.replace(placeholder, str(var_value))
306
+
307
+ # Add script to user data
308
+ # Split by lines and add each line as a command
309
+ for line in script_content.split('\n'):
310
+ if line.strip(): # Skip empty lines
311
+ user_data.add_commands(line)
312
+
313
+ logger.info(f"Added user data script from {script_type}: {script_config.get('path', 'inline')}")
314
+
216
315
  def _add_container_user_data(
217
316
  self, user_data: ec2.UserData, container_config: Dict[str, Any]
218
317
  ) -> None:
@@ -0,0 +1,6 @@
1
+ """
2
+ CloudFront Stack Library Module
3
+ """
4
+ from cdk_factory.stack_library.cloudfront.cloudfront_stack import CloudFrontStack
5
+
6
+ __all__ = ["CloudFrontStack"]