cdk-factory 0.16.15__py3-none-any.whl → 0.20.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 (66) hide show
  1. cdk_factory/configurations/base_config.py +23 -24
  2. cdk_factory/configurations/cdk_config.py +1 -1
  3. cdk_factory/configurations/deployment.py +12 -0
  4. cdk_factory/configurations/devops.py +1 -1
  5. cdk_factory/configurations/resources/acm.py +9 -2
  6. cdk_factory/configurations/resources/auto_scaling.py +7 -5
  7. cdk_factory/configurations/resources/cloudfront.py +7 -2
  8. cdk_factory/configurations/resources/ecr.py +1 -1
  9. cdk_factory/configurations/resources/ecs_cluster.py +12 -5
  10. cdk_factory/configurations/resources/ecs_service.py +30 -3
  11. cdk_factory/configurations/resources/lambda_edge.py +18 -4
  12. cdk_factory/configurations/resources/load_balancer.py +8 -9
  13. cdk_factory/configurations/resources/monitoring.py +8 -3
  14. cdk_factory/configurations/resources/rds.py +8 -9
  15. cdk_factory/configurations/resources/route53.py +5 -0
  16. cdk_factory/configurations/resources/rum.py +7 -2
  17. cdk_factory/configurations/resources/s3.py +10 -2
  18. cdk_factory/configurations/resources/security_group_full_stack.py +7 -8
  19. cdk_factory/configurations/resources/vpc.py +19 -0
  20. cdk_factory/configurations/workload.py +32 -2
  21. cdk_factory/constructs/cloudfront/cloudfront_distribution_construct.py +1 -1
  22. cdk_factory/constructs/ecr/ecr_construct.py +9 -2
  23. cdk_factory/constructs/lambdas/policies/policy_docs.py +4 -4
  24. cdk_factory/interfaces/istack.py +4 -4
  25. cdk_factory/interfaces/networked_stack_mixin.py +6 -6
  26. cdk_factory/interfaces/standardized_ssm_mixin.py +684 -0
  27. cdk_factory/interfaces/vpc_provider_mixin.py +64 -33
  28. cdk_factory/lambdas/edge/ip_gate/handler.py +42 -40
  29. cdk_factory/pipeline/pipeline_factory.py +3 -3
  30. cdk_factory/stack_library/__init__.py +3 -2
  31. cdk_factory/stack_library/acm/acm_stack.py +7 -17
  32. cdk_factory/stack_library/api_gateway/api_gateway_stack.py +84 -59
  33. cdk_factory/stack_library/auto_scaling/auto_scaling_stack.py +454 -537
  34. cdk_factory/stack_library/cloudfront/cloudfront_stack.py +76 -22
  35. cdk_factory/stack_library/code_artifact/code_artifact_stack.py +5 -27
  36. cdk_factory/stack_library/cognito/cognito_stack.py +152 -92
  37. cdk_factory/stack_library/dynamodb/dynamodb_stack.py +19 -15
  38. cdk_factory/stack_library/ecr/ecr_stack.py +2 -2
  39. cdk_factory/stack_library/ecs/__init__.py +1 -3
  40. cdk_factory/stack_library/ecs/ecs_cluster_stack.py +159 -75
  41. cdk_factory/stack_library/ecs/ecs_service_stack.py +59 -52
  42. cdk_factory/stack_library/lambda_edge/EDGE_LOG_RETENTION_TODO.md +226 -0
  43. cdk_factory/stack_library/lambda_edge/LAMBDA_EDGE_LOG_RETENTION_BLOG.md +215 -0
  44. cdk_factory/stack_library/lambda_edge/lambda_edge_stack.py +240 -83
  45. cdk_factory/stack_library/load_balancer/load_balancer_stack.py +139 -212
  46. cdk_factory/stack_library/rds/rds_stack.py +74 -98
  47. cdk_factory/stack_library/route53/route53_stack.py +246 -40
  48. cdk_factory/stack_library/rum/rum_stack.py +108 -91
  49. cdk_factory/stack_library/security_group/security_group_full_stack.py +10 -53
  50. cdk_factory/stack_library/security_group/security_group_stack.py +12 -19
  51. cdk_factory/stack_library/simple_queue_service/sqs_stack.py +1 -34
  52. cdk_factory/stack_library/stack_base.py +5 -0
  53. cdk_factory/stack_library/vpc/vpc_stack.py +171 -130
  54. cdk_factory/stack_library/websites/static_website_stack.py +7 -3
  55. cdk_factory/utilities/api_gateway_integration_utility.py +24 -16
  56. cdk_factory/utilities/environment_services.py +5 -5
  57. cdk_factory/utilities/json_loading_utility.py +1 -1
  58. cdk_factory/validation/config_validator.py +483 -0
  59. cdk_factory/version.py +1 -1
  60. {cdk_factory-0.16.15.dist-info → cdk_factory-0.20.0.dist-info}/METADATA +1 -1
  61. {cdk_factory-0.16.15.dist-info → cdk_factory-0.20.0.dist-info}/RECORD +64 -62
  62. cdk_factory/interfaces/enhanced_ssm_parameter_mixin.py +0 -321
  63. cdk_factory/interfaces/ssm_parameter_mixin.py +0 -454
  64. {cdk_factory-0.16.15.dist-info → cdk_factory-0.20.0.dist-info}/WHEEL +0 -0
  65. {cdk_factory-0.16.15.dist-info → cdk_factory-0.20.0.dist-info}/entry_points.txt +0 -0
  66. {cdk_factory-0.16.15.dist-info → cdk_factory-0.20.0.dist-info}/licenses/LICENSE +0 -0
@@ -13,6 +13,8 @@ from aws_cdk import (
13
13
  aws_cloudfront as cloudfront,
14
14
  aws_cloudfront_origins as origins,
15
15
  aws_certificatemanager as acm,
16
+ aws_route53 as route53,
17
+ aws_s3 as s3,
16
18
  aws_lambda as _lambda,
17
19
  aws_ssm as ssm,
18
20
  CfnOutput,
@@ -143,7 +145,7 @@ class CloudFrontStack(IStack):
143
145
  return
144
146
 
145
147
  # Check if certificate ARN is provided
146
- cert_arn = cert_config.get("arn")
148
+ cert_arn = self.resolve_ssm_value(self, cert_config.get("arn"), "CertificateARN")
147
149
  if cert_arn:
148
150
  self.certificate = acm.Certificate.from_certificate_arn(
149
151
  self, "Certificate", certificate_arn=cert_arn
@@ -161,8 +163,36 @@ class CloudFrontStack(IStack):
161
163
  logger.info(f"Using certificate from SSM: {ssm_param}")
162
164
  return
163
165
 
166
+ # Create new certificate from domain name
167
+ domain_name = cert_config.get("domain_name")
168
+ if domain_name and self.cf_config.aliases:
169
+ # CloudFront certificates must be in us-east-1
170
+ if self.region != "us-east-1":
171
+ logger.warning(
172
+ f"Certificate creation requested but stack is in {self.region}. "
173
+ "CloudFront certificates must be created in us-east-1"
174
+ )
175
+ return
176
+
177
+ # Create the certificate
178
+ # Get hosted zone from SSM imports
179
+ hosted_zone_id = cert_config.get("hosted_zone_id")
180
+ hosted_zone = route53.HostedZone.from_hosted_zone_id(
181
+ self, "HostedZone", hosted_zone_id
182
+ )
183
+
184
+ self.certificate = acm.Certificate(
185
+ self,
186
+ "Certificate",
187
+ domain_name=domain_name,
188
+ subject_alternative_names=self.cf_config.aliases,
189
+ validation=acm.CertificateValidation.from_dns(hosted_zone=hosted_zone),
190
+ )
191
+ logger.info(f"Created new ACM certificate for domain: {domain_name}")
192
+ return
193
+
164
194
  logger.warning(
165
- "No certificate ARN provided - CloudFront will use default certificate"
195
+ "No certificate ARN or domain name provided - CloudFront will use default certificate"
166
196
  )
167
197
 
168
198
  def _create_origins(self) -> None:
@@ -193,27 +223,29 @@ class CloudFrontStack(IStack):
193
223
 
194
224
  def _create_custom_origin(self, config: Dict[str, Any]) -> cloudfront.IOrigin:
195
225
  """Create custom origin (ALB, API Gateway, etc.)"""
196
- domain_name = config.get("domain_name")
226
+ domain_name = self.resolve_ssm_value(
227
+ self, config.get("domain_name"), config.get("domain_name")
228
+ )
197
229
  origin_id = config.get("id")
198
230
 
199
231
  if not domain_name:
200
232
  raise ValueError("domain_name is required for custom origin")
201
233
 
202
- # Check if domain name is a placeholder from ssm_imports
203
- if domain_name.startswith("{{") and domain_name.endswith("}}"):
204
- placeholder_key = domain_name[2:-2] # Remove {{ and }}
205
- if placeholder_key in self.ssm_imported_values:
206
- domain_name = self.ssm_imported_values[placeholder_key]
207
- logger.info(f"Resolved domain from SSM import: {placeholder_key}")
208
- else:
209
- logger.warning(f"Placeholder {domain_name} not found in SSM imports")
210
-
211
- # Legacy support: Check if domain name is an SSM parameter reference
212
- elif domain_name.startswith("{{ssm:") and domain_name.endswith("}}"):
213
- # Extract SSM parameter name
214
- ssm_param = domain_name[6:-2] # Remove {{ssm: and }}
215
- domain_name = ssm.StringParameter.value_from_lookup(self, ssm_param)
216
- logger.info(f"Resolved domain from SSM lookup {ssm_param}: {domain_name}")
234
+ # # Check if domain name is a placeholder from ssm_imports
235
+ # if domain_name.startswith("{{") and domain_name.endswith("}}"):
236
+ # placeholder_key = domain_name[2:-2] # Remove {{ and }}
237
+ # if placeholder_key in self.ssm_imported_values:
238
+ # domain_name = self.ssm_imported_values[placeholder_key]
239
+ # logger.info(f"Resolved domain from SSM import: {placeholder_key}")
240
+ # else:
241
+ # logger.warning(f"Placeholder {domain_name} not found in SSM imports")
242
+
243
+ # # Legacy support: Check if domain name is an SSM parameter reference
244
+ # elif domain_name.startswith("{{ssm:") and domain_name.endswith("}}"):
245
+ # # Extract SSM parameter name
246
+ # ssm_param = domain_name[6:-2] # Remove {{ssm: and }}
247
+ # domain_name = ssm.StringParameter.value_from_lookup(self, ssm_param)
248
+ # logger.info(f"Resolved domain from SSM lookup {ssm_param}: {domain_name}")
217
249
 
218
250
  # Build custom headers (e.g., X-Origin-Secret)
219
251
  custom_headers = {}
@@ -267,12 +299,34 @@ class CloudFrontStack(IStack):
267
299
 
268
300
  def _create_s3_origin(self, config: Dict[str, Any]) -> cloudfront.IOrigin:
269
301
  """Create S3 origin"""
270
- # S3 origin implementation
271
- # This would use origins.S3Origin
272
- raise NotImplementedError(
273
- "S3 origin support - use existing static_website_stack for S3"
302
+ bucket_name = self.resolve_ssm_value(
303
+ self, config.get("bucket_name"), config.get("bucket_name")
304
+ )
305
+
306
+ origin_path = config.get("origin_path", "")
307
+
308
+ if not bucket_name:
309
+ raise ValueError("S3 origin requires 'bucket_name' configuration")
310
+
311
+ # For S3 origins, we need to import the bucket by name
312
+ bucket = s3.Bucket.from_bucket_name(
313
+ self,
314
+ id=f"S3OriginBucket-{config.get('id', 'unknown')}",
315
+ bucket_name=bucket_name,
274
316
  )
275
317
 
318
+ # Create S3 origin with OAC (Origin Access Control) for security
319
+ origin = origins.S3BucketOrigin.with_origin_access_control(
320
+ bucket,
321
+ origin_path=origin_path,
322
+ origin_access_levels=[
323
+ cloudfront.AccessLevel.READ,
324
+ cloudfront.AccessLevel.LIST,
325
+ ],
326
+ )
327
+
328
+ return origin
329
+
276
330
  def _create_distribution(self) -> None:
277
331
  """Create CloudFront distribution"""
278
332
 
@@ -15,7 +15,7 @@ from cdk_factory.configurations.deployment import DeploymentConfig
15
15
  from cdk_factory.configurations.stack import StackConfig
16
16
  from cdk_factory.configurations.resources.code_artifact import CodeArtifactConfig
17
17
  from cdk_factory.interfaces.istack import IStack
18
- from cdk_factory.interfaces.enhanced_ssm_parameter_mixin import EnhancedSsmParameterMixin
18
+ from cdk_factory.interfaces.standardized_ssm_mixin import StandardizedSsmMixin
19
19
  from cdk_factory.stack.stack_module_registry import register_stack
20
20
  from cdk_factory.workload.workload_factory import WorkloadConfig
21
21
 
@@ -24,7 +24,7 @@ logger = Logger(service="CodeArtifactStack")
24
24
 
25
25
  @register_stack("code_artifact_library_module")
26
26
  @register_stack("code_artifact_stack")
27
- class CodeArtifactStack(IStack, EnhancedSsmParameterMixin):
27
+ class CodeArtifactStack(IStack, StandardizedSsmMixin):
28
28
  """
29
29
  Reusable stack for AWS CodeArtifact.
30
30
  Supports creating domains and repositories with configurable settings.
@@ -140,32 +140,10 @@ class CodeArtifactStack(IStack, EnhancedSsmParameterMixin):
140
140
 
141
141
  def _add_outputs(self) -> None:
142
142
  """Add CloudFormation outputs for the CodeArtifact resources"""
143
+
144
+
143
145
  # Domain outputs
144
146
  if self.domain:
145
147
  domain_name = self.code_artifact_config.domain_name
146
148
 
147
- # Domain ARN
148
- cdk.CfnOutput(
149
- self,
150
- f"{domain_name}-domain-arn",
151
- value=self.domain.attr_arn,
152
- export_name=f"{self.deployment.build_resource_name(domain_name)}-domain-arn"
153
- )
154
-
155
- # Domain URL
156
- cdk.CfnOutput(
157
- self,
158
- f"{domain_name}-domain-url",
159
- value=f"https://{self.code_artifact_config.account}.d.codeartifact.{self.code_artifact_config.region}.amazonaws.com/",
160
- export_name=f"{self.deployment.build_resource_name(domain_name)}-domain-url"
161
- )
162
-
163
- # Repository outputs
164
- for repo_name, repo in self.repositories.items():
165
- # Repository ARN
166
- cdk.CfnOutput(
167
- self,
168
- f"{repo_name}-repo-arn",
169
- value=repo.attr_arn,
170
- export_name=f"{self.deployment.build_resource_name(repo_name)}-repo-arn"
171
- )
149
+