cdk-factory 0.15.21__py3-none-any.whl → 0.15.23__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.
@@ -112,34 +112,59 @@ class LoadBalancerStack(IStack, EnhancedSsmParameterMixin):
112
112
  # Get subnets
113
113
  subnets = self._get_subnets()
114
114
 
115
+ # Prepare vpc_subnets parameter
116
+ # If subnets is None, we'll handle it via escape hatch after creation
117
+ vpc_subnets_param = ec2.SubnetSelection(subnets=subnets) if subnets else None
118
+
115
119
  # Create the Load Balancer based on type
116
120
  if self.lb_config.type == "APPLICATION":
117
- load_balancer = elbv2.ApplicationLoadBalancer(
118
- self,
119
- lb_name,
120
- load_balancer_name=lb_name,
121
- vpc=self.vpc,
122
- internet_facing=self.lb_config.internet_facing,
123
- security_group=(
121
+ # When vpc_subnets is None and we have token-based subnet_ids,
122
+ # we need to create the ALB without vpc_subnets to avoid VPC subnet lookup errors
123
+ alb_props = {
124
+ "load_balancer_name": lb_name,
125
+ "vpc": self.vpc,
126
+ "internet_facing": self.lb_config.internet_facing,
127
+ "security_group": (
124
128
  security_groups[0]
125
129
  if security_groups and len(security_groups) > 0
126
130
  else None
127
131
  ),
128
- deletion_protection=self.lb_config.deletion_protection,
129
- idle_timeout=cdk.Duration.seconds(self.lb_config.idle_timeout),
130
- http2_enabled=self.lb_config.http2_enabled,
131
- vpc_subnets=ec2.SubnetSelection(subnets=subnets) if subnets else None,
132
- )
132
+ "deletion_protection": self.lb_config.deletion_protection,
133
+ "idle_timeout": cdk.Duration.seconds(self.lb_config.idle_timeout),
134
+ "http2_enabled": self.lb_config.http2_enabled,
135
+ }
136
+
137
+ # Only add vpc_subnets if we have concrete subnet objects
138
+ if vpc_subnets_param:
139
+ alb_props["vpc_subnets"] = vpc_subnets_param
140
+
141
+ load_balancer = elbv2.ApplicationLoadBalancer(self, lb_name, **alb_props)
133
142
  else: # NETWORK
134
- load_balancer = elbv2.NetworkLoadBalancer(
135
- self,
136
- lb_name,
137
- load_balancer_name=lb_name,
138
- vpc=self.vpc,
139
- internet_facing=self.lb_config.internet_facing,
140
- deletion_protection=self.lb_config.deletion_protection,
141
- vpc_subnets=ec2.SubnetSelection(subnets=subnets) if subnets else None,
142
- )
143
+ nlb_props = {
144
+ "load_balancer_name": lb_name,
145
+ "vpc": self.vpc,
146
+ "internet_facing": self.lb_config.internet_facing,
147
+ "deletion_protection": self.lb_config.deletion_protection,
148
+ }
149
+
150
+ # Only add vpc_subnets if we have concrete subnet objects
151
+ if vpc_subnets_param:
152
+ nlb_props["vpc_subnets"] = vpc_subnets_param
153
+
154
+ load_balancer = elbv2.NetworkLoadBalancer(self, lb_name, **nlb_props)
155
+
156
+ # If subnets is None, check if we have SSM-imported subnet_ids as a token
157
+ # We need to use Fn.Split to convert the comma-separated string to an array
158
+ if subnets is None and "subnet_ids" in self.ssm_imported_values:
159
+ subnet_ids_value = self.ssm_imported_values["subnet_ids"]
160
+ if cdk.Token.is_unresolved(subnet_ids_value):
161
+ logger.info("Using Fn.Split to convert comma-separated subnet IDs token to array")
162
+ # Use CloudFormation escape hatch to set Subnets property with Fn.Split
163
+ cfn_lb = load_balancer.node.default_child
164
+ cfn_lb.add_property_override(
165
+ "Subnets",
166
+ cdk.Fn.split(",", subnet_ids_value)
167
+ )
143
168
 
144
169
  # Add tags
145
170
  for key, value in self.lb_config.tags.items():
@@ -160,9 +185,16 @@ class LoadBalancerStack(IStack, EnhancedSsmParameterMixin):
160
185
  # Build VPC attributes
161
186
  vpc_attrs = {
162
187
  "vpc_id": vpc_id,
163
- "availability_zones": ["us-east-1a", "us-east-1b"]
188
+ "availability_zones": ["us-east-1a", "us-east-1b"],
164
189
  }
165
190
 
191
+ # If we have subnet_ids from SSM, provide dummy public subnets
192
+ # The actual subnets will be set via CloudFormation escape hatch
193
+ if "subnet_ids" in self.ssm_imported_values:
194
+ # Provide dummy subnet IDs - these will be overridden by the escape hatch
195
+ # We need at least one dummy subnet per AZ to satisfy CDK's validation
196
+ vpc_attrs["public_subnet_ids"] = ["subnet-dummy1", "subnet-dummy2"]
197
+
166
198
  # Use from_vpc_attributes() instead of from_lookup() because SSM imports return tokens
167
199
  self._vpc = ec2.Vpc.from_vpc_attributes(self, "VPC", **vpc_attrs)
168
200
  elif self.lb_config.vpc_id:
@@ -255,15 +287,28 @@ class LoadBalancerStack(IStack, EnhancedSsmParameterMixin):
255
287
 
256
288
  # Check SSM imported values first
257
289
  if "subnet_ids" in self.ssm_imported_values:
258
- subnet_ids = self.ssm_imported_values["subnet_ids"]
259
- # SSM returns comma-separated string for StringList, need to split
260
- if isinstance(subnet_ids, str):
261
- subnet_ids = [s.strip() for s in subnet_ids.split(',')]
262
- elif not isinstance(subnet_ids, list):
263
- subnet_ids = [subnet_ids]
290
+ subnet_ids_value = self.ssm_imported_values["subnet_ids"]
291
+
292
+ # Check if this is a CDK token (unresolved SSM parameter)
293
+ if cdk.Token.is_unresolved(subnet_ids_value):
294
+ # For tokens, we can't split at synth time
295
+ # Return None to signal that subnets should be resolved via SubnetSelection
296
+ # The ALB construct will handle the token-based subnet IDs
297
+ logger.info("Subnet IDs are unresolved tokens, will use vpc_subnets with token resolution")
298
+ return None
299
+ elif isinstance(subnet_ids_value, str):
300
+ # If it's a resolved string, split it
301
+ subnet_ids = [s.strip() for s in subnet_ids_value.split(',')]
302
+ elif isinstance(subnet_ids_value, list):
303
+ subnet_ids = subnet_ids_value
304
+ else:
305
+ subnet_ids = [subnet_ids_value]
264
306
  else:
265
307
  subnet_ids = self.lb_config.subnets
266
308
 
309
+ if not subnet_ids:
310
+ return None
311
+
267
312
  for idx, subnet_id in enumerate(subnet_ids):
268
313
  subnets.append(
269
314
  ec2.Subnet.from_subnet_id(self, f"Subnet-{idx}", subnet_id)
cdk_factory/version.py CHANGED
@@ -1 +1 @@
1
- __version__ = "0.15.21"
1
+ __version__ = "0.15.23"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cdk_factory
3
- Version: 0.15.21
3
+ Version: 0.15.23
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=R3P7A3OIRwLs91Pf7vcKK6okyw2Hfach3FjnAE4bSO8,24
5
+ cdk_factory/version.py,sha256=7op-jiE3Ez13LGI3TOZuMVElwwRvXglYAxFNKJgv7P8,24
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
@@ -97,7 +97,7 @@ cdk_factory/stack_library/ecs/ecs_service_stack.py,sha256=c6K3BjlXyldr8ikvEhfC9C
97
97
  cdk_factory/stack_library/lambda_edge/__init__.py,sha256=ByBJ_CWdc4UtTmFBZH-6pzBMNkjkdtE65AmnB0Fs6lM,156
98
98
  cdk_factory/stack_library/lambda_edge/lambda_edge_stack.py,sha256=CdId_1kcZmYr1lLI9AD3-KqtE6voC3641PIloJmWiNI,16414
99
99
  cdk_factory/stack_library/load_balancer/__init__.py,sha256=wZpKw2OecLJGdF5mPayCYAEhu2H3c2gJFFIxwXftGDU,52
100
- cdk_factory/stack_library/load_balancer/load_balancer_stack.py,sha256=SBB-Cknon7U317iR2chFNWjny-lp8BFmzFMCYLP-8Uo,28253
100
+ cdk_factory/stack_library/load_balancer/load_balancer_stack.py,sha256=5JqBUJCeHjhzJFTBoh63gpCzQjYb5vcAJwC5U7MLhCk,30762
101
101
  cdk_factory/stack_library/monitoring/__init__.py,sha256=k1G_KDx47Aw0UugaL99PN_TKlyLK4nkJVApCaAK7GJg,153
102
102
  cdk_factory/stack_library/monitoring/monitoring_stack.py,sha256=N_1YvEXE7fboH_S3kv_dSKZsufxMuPdFMjGzlNFpuSo,19283
103
103
  cdk_factory/stack_library/rds/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -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=yDI3cRhVI5ELNDcJPLpk9UY54Uind1xQoV3spzT4z7E,6068
132
- cdk_factory-0.15.21.dist-info/METADATA,sha256=gDy99ATFt-hq-9aKupyCd-Quk7VCkRGmyltq4tbvWt8,2452
133
- cdk_factory-0.15.21.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
134
- cdk_factory-0.15.21.dist-info/entry_points.txt,sha256=S1DPe0ORcdiwEALMN_WIo3UQrW_g4YdQCLEsc_b0Swg,53
135
- cdk_factory-0.15.21.dist-info/licenses/LICENSE,sha256=NOtdOeLwg2il_XBJdXUPFPX8JlV4dqTdDGAd2-khxT8,1066
136
- cdk_factory-0.15.21.dist-info/RECORD,,
132
+ cdk_factory-0.15.23.dist-info/METADATA,sha256=TJZXugMYlzyNorvDOrQVTCY8OGPImjY97iso0ro2rhQ,2452
133
+ cdk_factory-0.15.23.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
134
+ cdk_factory-0.15.23.dist-info/entry_points.txt,sha256=S1DPe0ORcdiwEALMN_WIo3UQrW_g4YdQCLEsc_b0Swg,53
135
+ cdk_factory-0.15.23.dist-info/licenses/LICENSE,sha256=NOtdOeLwg2il_XBJdXUPFPX8JlV4dqTdDGAd2-khxT8,1066
136
+ cdk_factory-0.15.23.dist-info/RECORD,,