cdk-factory 0.15.3__py3-none-any.whl → 0.15.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.

@@ -78,10 +78,87 @@ class CloudFrontDistributionConstruct(Construct):
78
78
  """
79
79
  return CloudFrontDistributionConstruct.AWS_HOSTED_ZONE_ID
80
80
 
81
+ def __validate_function_associations(self):
82
+ """
83
+ Validate CloudFront function association configuration.
84
+ Provides clear error messages for common misconfigurations.
85
+
86
+ CloudFront limits:
87
+ - 1 CloudFront Function (JavaScript) per event type
88
+ - 1 Lambda@Edge (Python/Node) per event type
89
+ - Different types CAN coexist at same event type
90
+ """
91
+ if not self.stack_config or not isinstance(self.stack_config, StackConfig):
92
+ return # No config to validate
93
+
94
+ cloudfront_config = self.stack_config.dictionary.get("cloudfront", {})
95
+
96
+ # Get configuration flags
97
+ enable_url_rewrite = cloudfront_config.get("enable_url_rewrite", False)
98
+ enable_ip_gating = cloudfront_config.get("enable_ip_gating", False)
99
+ restrict_to_known_hosts = cloudfront_config.get("restrict_to_known_hosts", self.restrict_to_known_hosts)
100
+
101
+ # Count CloudFront Functions at viewer-request
102
+ cloudfront_functions_at_viewer_request = 0
103
+ if enable_url_rewrite:
104
+ cloudfront_functions_at_viewer_request += 1
105
+ if restrict_to_known_hosts and self.aliases:
106
+ cloudfront_functions_at_viewer_request += 1
107
+
108
+ # Note: Multiple CloudFront Functions are OK - we combine them automatically
109
+ if cloudfront_functions_at_viewer_request > 1:
110
+ logger.info(
111
+ f"Multiple CloudFront Functions at viewer-request detected. "
112
+ f"Will combine into single function. "
113
+ f"Features: enable_url_rewrite={enable_url_rewrite}, "
114
+ f"restrict_to_known_hosts={restrict_to_known_hosts}"
115
+ )
116
+
117
+ # Check for manual Lambda@Edge associations that might conflict
118
+ lambda_edge_associations = cloudfront_config.get("lambda_edge_associations", [])
119
+ manual_viewer_request = any(
120
+ assoc.get("event_type") == "viewer-request"
121
+ for assoc in lambda_edge_associations
122
+ )
123
+
124
+ # ERROR: Manual Lambda@Edge + enable_ip_gating both at viewer-request
125
+ if enable_ip_gating and manual_viewer_request:
126
+ raise ValueError(
127
+ "Configuration conflict: Cannot use both 'enable_ip_gating: true' "
128
+ "and manual 'lambda_edge_associations' with 'event_type: viewer-request'. "
129
+ "\n\nSolution 1 (Recommended): Use only 'enable_ip_gating: true' "
130
+ "and remove manual lambda_edge_associations."
131
+ "\n\nSolution 2: Use only manual lambda_edge_associations "
132
+ "and set 'enable_ip_gating: false'."
133
+ "\n\nCurrent config:"
134
+ f"\n enable_ip_gating: {enable_ip_gating}"
135
+ f"\n lambda_edge_associations with viewer-request: {manual_viewer_request}"
136
+ )
137
+
138
+ # WARNING: Both Lambda@Edge IP gating and CloudFront Functions enabled
139
+ # This is VALID but might indicate misconfiguration
140
+ if enable_ip_gating and cloudfront_functions_at_viewer_request > 0:
141
+ features = []
142
+ if enable_url_rewrite:
143
+ features.append("URL rewrite")
144
+ if restrict_to_known_hosts:
145
+ features.append("Host restrictions")
146
+
147
+ logger.info(
148
+ f"✓ CloudFront configuration at viewer-request:"
149
+ f"\n - CloudFront Function: {', '.join(features)}"
150
+ f"\n - Lambda@Edge: IP gating"
151
+ f"\nThis is valid: CloudFront Functions and Lambda@Edge can coexist "
152
+ f"at the same event type."
153
+ )
154
+
81
155
  def __setup(self):
82
156
  """
83
157
  Any setup / init logic goes here
84
158
  """
159
+ # Validate CloudFront function association configuration
160
+ self.__validate_function_associations()
161
+
85
162
  self.oai = cloudfront.OriginAccessIdentity(
86
163
  self, "OAI", comment="OAI for accessing S3 bucket content securely"
87
164
  )
@@ -135,6 +135,10 @@ class StaticWebSiteStack(IStack):
135
135
  version = self.__get_version_number(assets_path)
136
136
  logger.info(f"👉 WEBSITE VERSION NUMBER: {version}")
137
137
 
138
+ # Get cloudfront config options
139
+ cloudfront_config = stack_config.dictionary.get("cloudfront", {})
140
+ restrict_to_known_hosts = cloudfront_config.get("restrict_to_known_hosts", True)
141
+
138
142
  cloudfront_distribution = CloudFrontDistributionConstruct(
139
143
  scope=self,
140
144
  id=deployment.build_resource_name("CloudFrontDistribution"),
@@ -142,6 +146,7 @@ class StaticWebSiteStack(IStack):
142
146
  aliases=aliases,
143
147
  source_bucket_sub_directory=version,
144
148
  certificate=certificate,
149
+ restrict_to_known_hosts=restrict_to_known_hosts,
145
150
  stack_config=stack_config,
146
151
  )
147
152
 
cdk_factory/version.py CHANGED
@@ -1 +1 @@
1
- __version__ = "0.15.3"
1
+ __version__ = "0.15.4"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cdk_factory
3
- Version: 0.15.3
3
+ Version: 0.15.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=WbcBdqaNCRHsRqs6rGd3pRLP4kQSII2td9dR0Fl6HcU,23
5
+ cdk_factory/version.py,sha256=Ypoj4dM4zqbnGvYnOqiUlHcf_l1wO2M39u5_-ECRTQU,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=J56ui5cR4ULcT-20LdK43UNXhcicB2M45Wl8Y9SIWCA,2202
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=gFQw96rfSX7n3-YaK4AWyF2NNzJezgZpmnAcxZpmgxs,22036
53
+ cdk_factory/constructs/cloudfront/cloudfront_distribution_construct.py,sha256=LHgjvTNghCMTpHh90VWl7AbE100Er-S9EgyEVt12J_c,25809
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=O8aiHpNQ59eE3qEttEHVxbvp06v4byXOeYCVTAOI_Cg,9993
@@ -112,7 +112,7 @@ cdk_factory/stack_library/security_group/security_group_stack.py,sha256=2zxd5ozg
112
112
  cdk_factory/stack_library/simple_queue_service/sqs_stack.py,sha256=jJksWrvrvgZUMM01RZ317DOIxqIJbkYYSYu38w0jHpc,6039
113
113
  cdk_factory/stack_library/vpc/__init__.py,sha256=7pIqP97Gf2AJbv9Ebp1WbQGHYhgEbWJ52L1MzeXBybA,42
114
114
  cdk_factory/stack_library/vpc/vpc_stack.py,sha256=UZuzb5uSOi4ghuLGPvsKqc3gwe6XI89jHV4WHX8MelA,11472
115
- cdk_factory/stack_library/websites/static_website_stack.py,sha256=hcdZQxyhupCy7n7UpNaX8egc2oI9TrssyOufj-oJuo8,10343
115
+ cdk_factory/stack_library/websites/static_website_stack.py,sha256=XtrqJaMnrs1XvSz5-8LFaohtY68mtprIOrrizyjnS0w,10608
116
116
  cdk_factory/stages/websites/static_website_stage.py,sha256=X4fpKXkhb0zIbSHx3QyddBhVSLBryb1vf1Cg2fMTqog,755
117
117
  cdk_factory/templates/README.md,sha256=ATBEjG6beYvbEAdLtZ_8xnxgFD5X0cgZoI_6pToqH90,2679
118
118
  cdk_factory/templates/app.py.template,sha256=aM60x0nNV80idtCL8jm1EddY63F5tDITYOlavg-BPMU,1069
@@ -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.15.3.dist-info/METADATA,sha256=lsyCL4kq-zec5qwMBoMGoK5UWnJw3J1Gqri5Gg7ffLY,2451
133
- cdk_factory-0.15.3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
134
- cdk_factory-0.15.3.dist-info/entry_points.txt,sha256=S1DPe0ORcdiwEALMN_WIo3UQrW_g4YdQCLEsc_b0Swg,53
135
- cdk_factory-0.15.3.dist-info/licenses/LICENSE,sha256=NOtdOeLwg2il_XBJdXUPFPX8JlV4dqTdDGAd2-khxT8,1066
136
- cdk_factory-0.15.3.dist-info/RECORD,,
132
+ cdk_factory-0.15.4.dist-info/METADATA,sha256=f7hhvfGsvbMtz0P6ahc_dLgJQyMEZz-VOTZ38w9MQIM,2451
133
+ cdk_factory-0.15.4.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
134
+ cdk_factory-0.15.4.dist-info/entry_points.txt,sha256=S1DPe0ORcdiwEALMN_WIo3UQrW_g4YdQCLEsc_b0Swg,53
135
+ cdk_factory-0.15.4.dist-info/licenses/LICENSE,sha256=NOtdOeLwg2il_XBJdXUPFPX8JlV4dqTdDGAd2-khxT8,1066
136
+ cdk_factory-0.15.4.dist-info/RECORD,,