This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from my_pipeline.configuration import RawConfig, AppConfig, ResourceConfig | |
# ... | |
class PipelineStack(core.Stack): | |
def __init__(self, scope: core.Construct, pipeline_id: str, raw_config: RawConfig, | |
app_config: AppConfig, **kwargs: Any) -> None: | |
super().__init__(scope, pipeline_id, **kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# File where you can extend base configuration classes | |
from dataclasses import dataclass | |
from my_cdk_package.config.base import BaseAppConfig, BaseResourceConfig | |
@dataclass | |
class AppConfig(BaseAppConfig): | |
"""Custom application config class.""" | |
optional_custom_app_config: str |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyStack(core.Stack): | |
"""Example stack.""" | |
def __init__(self, scope: Construct, id: str, config: ResourceConfig, **kwargs: Any): | |
super().__init__(scope, id, env=config.environment, **kwargs) | |
# create resources |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
synth_action = SimpleSynthAction( | |
cloud_assembly_artifact=cloud_assembly_artifact, | |
source_artifact=source_artifact, | |
install_commands=['npm run ci_synth'], | |
build_commands=['npm run ci_build'], | |
install_commands=[ | |
# ... | |
'npm run ci_type_check' | |
] | |
# ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
synth_action = SimpleSynthAction( | |
# ... | |
install_commands=[ | |
# typo in install | |
f'npm insatll -g aws-cdk@{cdk_version}', | |
# ... | |
], | |
# ... | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pathlib import Path | |
from aws_cdk import core | |
from my_pipeline.configuration import RawConfig, AppConfig | |
from my_pipeline.pipeline_stack import PipelineStack | |
# Read config file | |
config_file = Path('config.json') | |
# Process raw config file | |
raw_config = RawConfig(config_file) | |
# Create application config instance |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"application": { | |
"application_name": "<application_name>", | |
"repository_name": "<name_of_the_CodeCommit_mirror_repo>", | |
"branch": "master", | |
"build_environment": { | |
"account": "<account-id-of-build-account>", | |
"region": "<build-aws-region>" | |
} | |
// ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RawConfig: | |
""" | |
Raw JSON configuration of the application and of all infrastructure resources for | |
each environment and. | |
""" | |
def __init__(self, config_file: Path): | |
self._all_config: Any = self._read_config(config_file) | |
self._environments_config: Any = self._all_config['environments'] | |
self._default: Any = self._environments_config['default'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from dataclasses import dataclass | |
from typing import Any, Dict, Type, TypeVar | |
from aws_cdk.core import Environment, RemovalPolicy | |
# https://mypy.readthedocs.io/en/stable/kinds_of_types.html#the-type-of-class-objects | |
# https://github.com/python/typing/issues/58 | |
# Needed to return correct child class types in classmethod constructor | |
ResourceConfigClass = TypeVar('ResourceConfigClass', bound='ResourceConfig') | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vpc = ec2.Vpc.from_vpc_attributes(self, 'vpc', | |
vpc_id=vpc_id, | |
availability_zones=list_of_vpc_availability_zones, | |
private_subnet_ids=list_of_private_subnet_ids | |
) | |
vpc_subnets = ec2.SubnetSelection(subnets=vpc.private_subnets) | |
# ... | |
alb = elbv2.ApplicationLoadBalancer(self, 'alb-name', |
NewerOlder