Configuration¶
The configuration module provides environment-aware settings for deploying applications across different AWS accounts.
Overview¶
The configuration system automatically selects appropriate settings based on your AWS account ID, including:
- VPC and subnet configuration
- Route53 hosted zones
- Cognito user pools
- WAF rules
- S3 buckets for logging
DeploymentEnvironment¶
gds_idea_cdk_constructs.config.DeploymentEnvironment
¶
Bases: Enum
Source code in src/gds_idea_cdk_constructs/config.py
from_cdk_env
classmethod
¶
Get environment from CDK Environment.
Source code in src/gds_idea_cdk_constructs/config.py
from_account_id
classmethod
¶
Get environment from account ID.
Source code in src/gds_idea_cdk_constructs/config.py
DeploymentConfig¶
gds_idea_cdk_constructs.config.DeploymentConfig
dataclass
¶
Configuration for GDS Idea web applications.
Fetches environment-specific configuration from AWS Systems Manager
Parameter Store, merging three parameters: /gds-idea-auth,
/gds-idea-ecs, and /gds-idea-vpc.
For testing or local development without Parameter Store access, use
the :meth:from_dict classmethod instead.
Source code in src/gds_idea_cdk_constructs/config.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 | |
__init__
¶
Create DeploymentConfig by fetching from Parameter Store.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cdk_env
|
Environment
|
The CDK Environment (must have account and region set). |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the account is unknown, the environment is TESTING, or the parameters are missing required keys. |
Source code in src/gds_idea_cdk_constructs/config.py
from_dict
classmethod
¶
Create DeploymentConfig from an explicit config dict.
Useful for testing or local development without Parameter Store access.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cdk_env
|
Environment
|
The CDK Environment (must have account set). |
required |
config
|
dict[str, str]
|
Dict containing all required configuration keys. |
required |
Returns:
| Type | Description |
|---|---|
DeploymentConfig
|
A configured DeploymentConfig instance. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If config is missing required keys. |
Source code in src/gds_idea_cdk_constructs/config.py
AppConfig¶
gds_idea_cdk_constructs.config.AppConfig
¶
Load web application configuration from pyproject.toml [tool.webapp]
Source code in src/gds_idea_cdk_constructs/config.py
from_pyproject
classmethod
¶
Load config from pyproject.toml [tool.webapp] section
Source code in src/gds_idea_cdk_constructs/config.py
Usage Examples¶
Basic Configuration¶
import os
import aws_cdk as cdk
from gds_idea_cdk_constructs.config import DeploymentConfig, AppConfig
# Create CDK environment from AWS credentials
cdk_env = cdk.Environment(
account=os.environ["CDK_DEFAULT_ACCOUNT"],
region=os.environ["CDK_DEFAULT_REGION"],
)
# Deployment config automatically detects environment
deployment_config = DeploymentConfig(cdk_env)
# Application config
app_config = AppConfig(
app_name="my-app",
framework="streamlit",
)
Custom Health Check¶
app_config = AppConfig(
app_name="my-api",
framework="fastapi",
health_check_path="/api/v1/health",
)
Loading from pyproject.toml¶
# pyproject.toml:
# [tool.webapp]
# app_name = "my-app"
# framework = "streamlit"
app_config = AppConfig.from_pyproject("pyproject.toml")
Environment-Specific Values¶
Environment-specific configuration is fetched from AWS Systems Manager Parameter Store at synth time. Three parameters are fetched and merged into a single config:
Parameter Structure¶
| Parameter | Key | Attribute |
|---|---|---|
/gds-idea-auth |
domain_name |
domain_name |
/gds-idea-auth |
cognito_user_pool_id |
user_pool_id |
/gds-idea-auth |
waf_arn |
waf_arn |
/gds-idea-auth |
waf_big_upload_arn |
waf_big_upload_arn |
/gds-idea-auth |
logs_bucket_name |
log_bucket_name |
/gds-idea-ecs |
ecs_arn |
cluster_name (parsed from ARN) |
/gds-idea-vpc |
vpc_id |
vpc_id |
The external_idp_name attribute is hard-coded to "internal-access" to match
the identity provider configured in the Cognito User Pool.
Environments¶
| Environment | Account |
|---|---|
| Development | 992382722318 |
| Production | 588077357019 |
Region: eu-west-2 (preferred for both)
Alternative Construction¶
For testing or local development without Parameter Store access:
config = DeploymentConfig.from_dict(cdk_env, {
"domain_name": "example.com",
"vpc_id": "vpc-abc123",
"ecs_arn": "arn:aws:ecs:eu-west-2:123456789012:cluster/my-cluster",
"cognito_user_pool_id": "eu-west-2_PoolId",
"waf_arn": "arn:aws:wafv2:...",
"waf_big_upload_arn": "arn:aws:wafv2:...",
"logs_bucket_name": "example.com-logs",
})