Skip to content

Commit 4ad16c9

Browse files
authored
feat: validate CDK apps before deployment (#23)
* feat: validate CDK apps before deployment * refactor: centralize CDK validation task config * refactor: keep test setup unchanged * chore: align Projen and disable CDK telemetry
1 parent ff7caf4 commit 4ad16c9

10 files changed

Lines changed: 189 additions & 83 deletions

File tree

‎.github/workflows/cdk-deploy-dev.yml‎

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎.github/workflows/cdk-deploy-test.yml‎

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎.projen/deps.json‎

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎.projen/tasks.json‎

Lines changed: 96 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎.projenrc.py‎

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,16 @@
99
from projen.awscdk import AwsCdkPythonApp
1010

1111
from src.bin.cicd_helper import github_cicd
12-
from src.bin.env_helper import cdk_action_task
12+
from src.bin.env_helper import CDK_VALIDATE_COMMAND, cdk_action_task
1313

1414
# Define the python module name and set the python version
1515
project_name = "aws-cdk-python-starter-kit"
1616
python_module_name = "src"
1717
python_version = "3.13"
1818
python_major, python_minor = map(int, python_version.split("."))
1919
python_requires = f">={python_version},<{python_major}.{python_minor + 1}"
20+
cdk_version = "2.263.0"
21+
cdk_cli_version = "2.1130.0"
2022

2123
# Define the AWS region for the CDK app and github workflows
2224
# Default to us-east-1 if AWS_REGION is not set in your environment variables
@@ -26,16 +28,26 @@
2628
author_email="danny@towardsthecloud.com",
2729
author_name="Danny Steenman",
2830
cdk_version_pinning=True,
29-
cdk_version="2.254.0", # Find the latest CDK version here: https://pypi.org/project/aws-cdk-lib
30-
cdk_cli_version="2.1117.0", # Find the latest CDK CLI version https://pypi.org/project/aws-cdk-cli/
31+
cdk_version=cdk_version, # Find the latest CDK version here: https://pypi.org/project/aws-cdk-lib
32+
cdk_cli_version=cdk_cli_version, # Find the latest CDK CLI version https://pypi.org/project/aws-cdk-cli/
33+
context={
34+
"@aws-cdk/core:annotationsInValidationReport": True,
35+
"@aws-cdk/core:validateAgainstDefaultRules": True,
36+
"cli-telemetry": False,
37+
},
3138
module_name=python_module_name,
3239
name=project_name,
3340
projen_command="uv run projen",
3441
description="Create and deploy an AWS CDK app on your AWS account in less than 5 minutes using GitHub actions!",
3542
version="2.101.0",
3643
app_entrypoint=f"{python_module_name}/app.py",
3744
deps=["aws-cdk-github-oidc"],
38-
dev_deps=["projen@0.99.62", "ruff", "ty"], # Find the latest projen version here: https://pypi.org/project/projen/
45+
dev_deps=[
46+
"projen@0.101.11",
47+
"ruff",
48+
"ty",
49+
], # Find the latest projen version here: https://pypi.org/project/projen/
50+
pytest_options={"version": "9.0.3"},
3951
uv=True,
4052
uv_options={
4153
"python_exec": f"python{python_version}",
@@ -47,7 +59,18 @@
4759
github_options={
4860
"pull_request_lint_options": {
4961
"semantic_title_options": {
50-
"types": ["feat", "fix", "chore", "refactor", "perf", "docs", "style", "test", "build", "ci"],
62+
"types": [
63+
"feat",
64+
"fix",
65+
"chore",
66+
"refactor",
67+
"perf",
68+
"docs",
69+
"style",
70+
"test",
71+
"build",
72+
"ci",
73+
],
5174
},
5275
},
5376
},
@@ -74,6 +97,13 @@
7497
# so the CDK CLI knows which region to use
7598
project.tasks.add_environment("CDK_DEFAULT_REGION", aws_region)
7699

100+
project.add_task(
101+
"validate",
102+
description="Validate the CDK app offline against the default CloudFormation rules",
103+
exec=f"{CDK_VALIDATE_COMMAND} --no-online",
104+
receive_args=True,
105+
)
106+
77107
# Define the target AWS accounts for the different environments
78108
target_accounts = {
79109
"dev": "987654321012",
@@ -113,7 +143,9 @@
113143
)
114144

115145
# Add auto-merge step to the auto-approve workflow
116-
auto_approve_workflow = project.try_find_object_file(".github/workflows/auto-approve.yml")
146+
auto_approve_workflow = project.try_find_object_file(
147+
".github/workflows/auto-approve.yml"
148+
)
117149
if auto_approve_workflow:
118150
auto_approve_workflow.add_override("jobs.approve.permissions.contents", "write")
119151
# Add checkout step before the merge step
@@ -143,6 +175,6 @@
143175
)
144176

145177
# Adds GitHub action workflows for deploying the CDK stacks to the target AWS account
146-
github_cicd(gh, account, env, python_version, aws_region)
178+
github_cicd(gh, account, env, python_version, aws_region, cdk_cli_version)
147179

148180
project.synth()

‎cdk.json‎

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎pyproject.toml‎

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)