Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/serverless-service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ jobs:
publish_github_pages:
runs-on: ubuntu-latest
needs: [tests]
environment: dev
permissions:
contents: write # for docs push
if: contains('refs/heads/main', github.ref)
Expand Down
69 changes: 33 additions & 36 deletions cdk/service/configuration/configuration_construct.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from pathlib import Path

import aws_cdk.aws_appconfig as appconfig
import aws_cdk.aws_appconfig_alpha as appconfig
from aws_cdk import Duration, RemovalPolicy
from constructs import Construct

from cdk.service.configuration.schema import FeatureFlagsConfiguration
Expand All @@ -25,55 +26,51 @@ def __init__(self, scope: Construct, id_: str, environment: str, service_name: s
super().__init__(scope, id_)

configuration_str = self._get_and_validate_configuration(environment)

self.config_app = appconfig.CfnApplication(
self.app_name = f'{id_}{service_name}'
self.config_app = appconfig.Application(
self,
id=f'{id_}{service_name}',
name=f'{id_}{service_name}',
id=self.app_name,
name=self.app_name,
)
self.config_env = appconfig.CfnEnvironment(

self.config_app.apply_removal_policy(RemovalPolicy.DESTROY)

self.config_env = appconfig.Environment(
self,
id=f'{id_}env',
application_id=self.config_app.ref,
application=self.config_app,
name=environment,
)
self.config_profile = appconfig.CfnConfigurationProfile(
self,
id=f'{id_}profile',
application_id=self.config_app.ref,
location_uri='hosted',
name=configuration_name,
)
self.hosted_cfg_version = appconfig.CfnHostedConfigurationVersion(
self,
f'{id_}version',
application_id=self.config_app.ref,
configuration_profile_id=self.config_profile.ref,
content=configuration_str,
content_type='application/json',
)

self.cfn_deployment_strategy = appconfig.CfnDeploymentStrategy(
self.config_env.apply_removal_policy(RemovalPolicy.DESTROY)

# zero minutes, zero bake, 100 growth all at once
self.config_dep_strategy = appconfig.DeploymentStrategy(
self,
f'{id_}zero',
deployment_duration_in_minutes=0,
growth_factor=100,
name='zero',
replicate_to='NONE',
description='zero minutes, zero bake, 100 growth all at once',
final_bake_time_in_minutes=0,
rollout_strategy=appconfig.RolloutStrategy.linear(
growth_factor=100,
deployment_duration=Duration.minutes(0),
final_bake_time=Duration.minutes(0),
),
)

self.app_config_deployment = appconfig.CfnDeployment(
self.config_dep_strategy.apply_removal_policy(RemovalPolicy.DESTROY)

self.config = appconfig.HostedConfiguration(
self,
id=f'{id_}deploy',
application_id=self.config_app.ref,
configuration_profile_id=self.config_profile.ref,
configuration_version=self.hosted_cfg_version.ref,
deployment_strategy_id=self.cfn_deployment_strategy.ref,
environment_id=self.config_env.ref,
f'{id_}version',
application=self.config_app,
name=configuration_name,
content=appconfig.ConfigurationContent.from_inline(configuration_str),
type=appconfig.ConfigurationType.FREEFORM,
deployment_strategy=self.config_dep_strategy,
deploy_to=[self.config_env],
)

# workaround until https://github.com/aws/aws-cdk/issues/26804 is resolved
self.config.node.default_child.apply_removal_policy(RemovalPolicy.DESTROY) # type: ignore

def _get_and_validate_configuration(self, environment: str) -> str:
current = Path(__file__).parent
conf_filepath = current / (f'json/{environment}_configuration.json')
Expand Down
2 changes: 1 addition & 1 deletion cdk/service/service_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def __init__(self, scope: Construct, id: str, **kwargs) -> None:
# from running the service pipeline and without redeploying the service lambdas. For the sake of this template
# example, it is deployed as part of the service stack
self.dynamic_configuration = ConfigurationStore(self, f'{id}dynamic_conf'[0:64], ENVIRONMENT, SERVICE_NAME, CONFIGURATION_NAME)
self.api = ApiConstruct(self, f'{id}Service'[0:64], self.dynamic_configuration.config_app.name)
self.api = ApiConstruct(self, f'{id}Service'[0:64], self.dynamic_configuration.app_name)

# add security check
self._add_security_tests()
Expand Down
48 changes: 33 additions & 15 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ aws-lambda-env-modeler = "*"
[tool.poetry.dev-dependencies]
# CDK
service-cdk = {path = "cdk", develop = true}
aws-cdk-lib = ">=2.88.0"
aws-cdk-lib = ">=2.93.0"
constructs = ">=10.0.0"
cdk-nag = ">2.0.0"
"aws-cdk.aws-lambda-python-alpha" = "^2.88.0-alpha.0"
"aws-cdk.aws-lambda-python-alpha" = "^2.93.0-alpha.0"
"aws-cdk.aws-appconfig-alpha" = "^2.93.0-alpha.0"
# DEV
pytest = "*"
pytest-mock = "*"
Expand Down