cdk-factory 0.11.0__py3-none-any.whl → 0.13.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.
- cdk_factory/stack_library/lambda_edge/lambda_edge_stack.py +78 -5
- cdk_factory/stack_library/websites/static_website_stack.py +59 -0
- cdk_factory/version.py +1 -1
- {cdk_factory-0.11.0.dist-info → cdk_factory-0.13.0.dist-info}/METADATA +1 -1
- {cdk_factory-0.11.0.dist-info → cdk_factory-0.13.0.dist-info}/RECORD +8 -8
- {cdk_factory-0.11.0.dist-info → cdk_factory-0.13.0.dist-info}/WHEEL +0 -0
- {cdk_factory-0.11.0.dist-info → cdk_factory-0.13.0.dist-info}/entry_points.txt +0 -0
- {cdk_factory-0.11.0.dist-info → cdk_factory-0.13.0.dist-info}/licenses/LICENSE +0 -0
|
@@ -8,6 +8,7 @@ MIT License. See Project Root for the license information.
|
|
|
8
8
|
|
|
9
9
|
from typing import Optional, Dict
|
|
10
10
|
from pathlib import Path
|
|
11
|
+
import json
|
|
11
12
|
|
|
12
13
|
import aws_cdk as cdk
|
|
13
14
|
from aws_cdk import aws_lambda as _lambda
|
|
@@ -139,6 +140,22 @@ class LambdaEdgeStack(IStack, EnhancedSsmParameterMixin):
|
|
|
139
140
|
|
|
140
141
|
logger.info(f"Loading Lambda code from: {code_path}")
|
|
141
142
|
|
|
143
|
+
# Create runtime configuration file for Lambda@Edge
|
|
144
|
+
# Since Lambda@Edge doesn't support environment variables, we bundle a config file
|
|
145
|
+
runtime_config = {
|
|
146
|
+
'environment': self.deployment.environment,
|
|
147
|
+
'function_name': self.edge_config.name,
|
|
148
|
+
'region': self.deployment.region
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
runtime_config_path = code_path / 'runtime_config.json'
|
|
152
|
+
logger.info(f"Creating runtime config at: {runtime_config_path}")
|
|
153
|
+
|
|
154
|
+
with open(runtime_config_path, 'w') as f:
|
|
155
|
+
json.dump(runtime_config, f, indent=2)
|
|
156
|
+
|
|
157
|
+
logger.info(f"Runtime config: {runtime_config}")
|
|
158
|
+
|
|
142
159
|
# Map runtime string to CDK Runtime
|
|
143
160
|
runtime_map = {
|
|
144
161
|
"python3.11": _lambda.Runtime.PYTHON_3_11,
|
|
@@ -154,10 +171,23 @@ class LambdaEdgeStack(IStack, EnhancedSsmParameterMixin):
|
|
|
154
171
|
_lambda.Runtime.PYTHON_3_11
|
|
155
172
|
)
|
|
156
173
|
|
|
157
|
-
#
|
|
158
|
-
|
|
174
|
+
# Lambda@Edge does NOT support environment variables
|
|
175
|
+
# Configuration must be handled via:
|
|
176
|
+
# 1. Hardcoded in the function code
|
|
177
|
+
# 2. Fetched from SSM Parameter Store at runtime
|
|
178
|
+
# 3. Other configuration mechanisms
|
|
159
179
|
|
|
160
|
-
#
|
|
180
|
+
# Log warning if environment variables are configured
|
|
181
|
+
if self.edge_config.environment:
|
|
182
|
+
logger.warning(
|
|
183
|
+
f"Lambda@Edge function '{function_name}' has environment variables configured, "
|
|
184
|
+
"but Lambda@Edge does not support environment variables. "
|
|
185
|
+
"The function must fetch these values from SSM Parameter Store at runtime."
|
|
186
|
+
)
|
|
187
|
+
for key, value in self.edge_config.environment.items():
|
|
188
|
+
logger.warning(f" - {key}: {value}")
|
|
189
|
+
|
|
190
|
+
# Create execution role with CloudWatch Logs and SSM permissions
|
|
161
191
|
execution_role = iam.Role(
|
|
162
192
|
self,
|
|
163
193
|
f"{function_name}-Role",
|
|
@@ -173,7 +203,23 @@ class LambdaEdgeStack(IStack, EnhancedSsmParameterMixin):
|
|
|
173
203
|
]
|
|
174
204
|
)
|
|
175
205
|
|
|
176
|
-
#
|
|
206
|
+
# Add SSM read permissions if environment variables reference SSM parameters
|
|
207
|
+
if self.edge_config.environment:
|
|
208
|
+
execution_role.add_to_policy(
|
|
209
|
+
iam.PolicyStatement(
|
|
210
|
+
effect=iam.Effect.ALLOW,
|
|
211
|
+
actions=[
|
|
212
|
+
"ssm:GetParameter",
|
|
213
|
+
"ssm:GetParameters",
|
|
214
|
+
"ssm:GetParametersByPath"
|
|
215
|
+
],
|
|
216
|
+
resources=[
|
|
217
|
+
f"arn:aws:ssm:*:{cdk.Aws.ACCOUNT_ID}:parameter/*"
|
|
218
|
+
]
|
|
219
|
+
)
|
|
220
|
+
)
|
|
221
|
+
|
|
222
|
+
# Create the Lambda function WITHOUT environment variables
|
|
177
223
|
self.function = _lambda.Function(
|
|
178
224
|
self,
|
|
179
225
|
function_name,
|
|
@@ -185,7 +231,7 @@ class LambdaEdgeStack(IStack, EnhancedSsmParameterMixin):
|
|
|
185
231
|
timeout=cdk.Duration.seconds(self.edge_config.timeout),
|
|
186
232
|
description=self.edge_config.description,
|
|
187
233
|
role=execution_role,
|
|
188
|
-
environment
|
|
234
|
+
# Lambda@Edge does NOT support environment variables
|
|
189
235
|
log_retention=logs.RetentionDays.ONE_WEEK,
|
|
190
236
|
)
|
|
191
237
|
|
|
@@ -256,3 +302,30 @@ class LambdaEdgeStack(IStack, EnhancedSsmParameterMixin):
|
|
|
256
302
|
param_path,
|
|
257
303
|
description=f"{key} for Lambda@Edge function {function_name}"
|
|
258
304
|
)
|
|
305
|
+
|
|
306
|
+
# Export environment variables as SSM parameters
|
|
307
|
+
# Since Lambda@Edge doesn't support environment variables, we export them
|
|
308
|
+
# to SSM so the Lambda function can fetch them at runtime
|
|
309
|
+
if self.edge_config.environment:
|
|
310
|
+
logger.info("Exporting Lambda@Edge environment variables as SSM parameters")
|
|
311
|
+
env_ssm_exports = self.edge_config.dictionary.get("environment_ssm_exports", {})
|
|
312
|
+
|
|
313
|
+
# If no explicit environment_ssm_exports, create default SSM paths
|
|
314
|
+
if not env_ssm_exports:
|
|
315
|
+
# Auto-generate SSM parameter names based on environment variable names
|
|
316
|
+
for env_key in self.edge_config.environment.keys():
|
|
317
|
+
# Use snake_case version of the key for SSM path
|
|
318
|
+
ssm_key = env_key.lower().replace('_', '-')
|
|
319
|
+
env_ssm_exports[env_key] = f"/{self.deployment.environment}/{function_name}/{ssm_key}"
|
|
320
|
+
|
|
321
|
+
# Resolve and export environment variables to SSM
|
|
322
|
+
resolved_env = self._resolve_environment_variables()
|
|
323
|
+
for env_key, ssm_path in env_ssm_exports.items():
|
|
324
|
+
if env_key in resolved_env:
|
|
325
|
+
self.export_ssm_parameter(
|
|
326
|
+
self,
|
|
327
|
+
f"env-{env_key}-param",
|
|
328
|
+
resolved_env[env_key],
|
|
329
|
+
ssm_path,
|
|
330
|
+
description=f"Configuration for Lambda@Edge: {env_key}"
|
|
331
|
+
)
|
|
@@ -169,6 +169,13 @@ class StaticWebSiteStack(IStack):
|
|
|
169
169
|
aliases=aliases,
|
|
170
170
|
distribution=cloudfront_distribution.distribution,
|
|
171
171
|
)
|
|
172
|
+
|
|
173
|
+
# Export SSM parameters if configured
|
|
174
|
+
self.__export_ssm_parameters(
|
|
175
|
+
stack_config=stack_config,
|
|
176
|
+
bucket=bucket,
|
|
177
|
+
cloudfront_distribution=cloudfront_distribution,
|
|
178
|
+
)
|
|
172
179
|
|
|
173
180
|
def __setup_route53_records(
|
|
174
181
|
self,
|
|
@@ -200,6 +207,58 @@ class StaticWebSiteStack(IStack):
|
|
|
200
207
|
zone_name=hosted_zone_name,
|
|
201
208
|
)
|
|
202
209
|
|
|
210
|
+
def __export_ssm_parameters(
|
|
211
|
+
self,
|
|
212
|
+
stack_config: StackConfig,
|
|
213
|
+
bucket: s3.IBucket,
|
|
214
|
+
cloudfront_distribution: CloudFrontDistributionConstruct,
|
|
215
|
+
) -> None:
|
|
216
|
+
"""
|
|
217
|
+
Export stack outputs to SSM Parameter Store if ssm_exports is configured.
|
|
218
|
+
|
|
219
|
+
Args:
|
|
220
|
+
stack_config: Stack configuration containing ssm_exports
|
|
221
|
+
bucket: The S3 bucket
|
|
222
|
+
cloudfront_distribution: The CloudFront distribution construct
|
|
223
|
+
"""
|
|
224
|
+
ssm_exports = stack_config.dictionary.get("ssm_exports", {})
|
|
225
|
+
|
|
226
|
+
if not ssm_exports:
|
|
227
|
+
logger.debug("No SSM exports configured for this stack")
|
|
228
|
+
return
|
|
229
|
+
|
|
230
|
+
# Export bucket name if configured
|
|
231
|
+
if "bucket_name" in ssm_exports:
|
|
232
|
+
self.export_ssm_parameter(
|
|
233
|
+
scope=self,
|
|
234
|
+
id="SsmExportBucketName",
|
|
235
|
+
value=bucket.bucket_name,
|
|
236
|
+
parameter_name=ssm_exports["bucket_name"],
|
|
237
|
+
description=f"S3 bucket name for {stack_config.name}",
|
|
238
|
+
)
|
|
239
|
+
|
|
240
|
+
# Export CloudFront domain if configured
|
|
241
|
+
if "cloudfront_domain" in ssm_exports and cloudfront_distribution.distribution:
|
|
242
|
+
self.export_ssm_parameter(
|
|
243
|
+
scope=self,
|
|
244
|
+
id="SsmExportCloudFrontDomain",
|
|
245
|
+
value=cloudfront_distribution.dns_name,
|
|
246
|
+
parameter_name=ssm_exports["cloudfront_domain"],
|
|
247
|
+
description=f"CloudFront domain name for {stack_config.name}",
|
|
248
|
+
)
|
|
249
|
+
|
|
250
|
+
# Export CloudFront distribution ID if configured
|
|
251
|
+
if "cloudfront_distribution_id" in ssm_exports and cloudfront_distribution.distribution:
|
|
252
|
+
self.export_ssm_parameter(
|
|
253
|
+
scope=self,
|
|
254
|
+
id="SsmExportCloudFrontDistributionId",
|
|
255
|
+
value=cloudfront_distribution.distribution_id,
|
|
256
|
+
parameter_name=ssm_exports["cloudfront_distribution_id"],
|
|
257
|
+
description=f"CloudFront distribution ID for {stack_config.name}",
|
|
258
|
+
)
|
|
259
|
+
|
|
260
|
+
logger.info(f"Exported {len(ssm_exports)} SSM parameters for stack {stack_config.name}")
|
|
261
|
+
|
|
203
262
|
def __get_version_number(self, assets_path: str) -> str:
|
|
204
263
|
version = "0.0.1.ckd.factory"
|
|
205
264
|
|
cdk_factory/version.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = "0.
|
|
1
|
+
__version__ = "0.13.0"
|
|
@@ -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=
|
|
5
|
+
cdk_factory/version.py,sha256=DgpLNbv0e1LIEOOe54Db8_390i9pelMEFEnsBsNmyhA,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
|
|
@@ -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=
|
|
98
|
+
cdk_factory/stack_library/lambda_edge/lambda_edge_stack.py,sha256=WDLoARmn-ehGnfm8m9Kt88Mp1GQ6ZdqkQaDWE65hXD4,13478
|
|
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
|
|
@@ -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=zdDiGilf03esxuya5Z8zVYSVMAIuZBeD-ZKgfnEd6aw,10077
|
|
115
|
-
cdk_factory/stack_library/websites/static_website_stack.py,sha256=
|
|
115
|
+
cdk_factory/stack_library/websites/static_website_stack.py,sha256=VoQOUZ_HFdRErBo0mpw73uXSNbjftxqdF5vbnZQHq4A,10351
|
|
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.
|
|
133
|
-
cdk_factory-0.
|
|
134
|
-
cdk_factory-0.
|
|
135
|
-
cdk_factory-0.
|
|
136
|
-
cdk_factory-0.
|
|
132
|
+
cdk_factory-0.13.0.dist-info/METADATA,sha256=u2EL937XENu8doeidJ_nCCJIY0h18_KGWwTk2nQ7ADQ,2451
|
|
133
|
+
cdk_factory-0.13.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
134
|
+
cdk_factory-0.13.0.dist-info/entry_points.txt,sha256=S1DPe0ORcdiwEALMN_WIo3UQrW_g4YdQCLEsc_b0Swg,53
|
|
135
|
+
cdk_factory-0.13.0.dist-info/licenses/LICENSE,sha256=NOtdOeLwg2il_XBJdXUPFPX8JlV4dqTdDGAd2-khxT8,1066
|
|
136
|
+
cdk_factory-0.13.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|