@@ -21,13 +21,13 @@ def __init__(self, scope: constructs.Construct, construct_id: str, **kwargs) ->
2121 self ,
2222 "VPC" ,
2323 nat_gateways = 1 ,
24- cidr = "10.0.0.0/16" ,
24+ ipaddress = ec2 . IpAddresses . cidr ( "10.0.0.0/16" ) ,
2525 subnet_configuration = [
2626 ec2 .SubnetConfiguration (
2727 name = "public" , subnet_type = ec2 .SubnetType .PUBLIC , cidr_mask = 24
2828 ),
2929 ec2 .SubnetConfiguration (
30- name = "private" , subnet_type = ec2 .SubnetType .PRIVATE_WITH_NAT , cidr_mask = 24
30+ name = "private" , subnet_type = ec2 .SubnetType .PRIVATE_WITH_EGRESS , cidr_mask = 24
3131 ),
3232 ],
3333 )
@@ -43,7 +43,7 @@ def __init__(self, scope: constructs.Construct, construct_id: str, **kwargs) ->
4343 self ,
4444 "WordpressDatabase" ,
4545 credentials = rds .Credentials .from_password (
46- username = db_user , password = cdk .SecretValue .plain_text (db_password )
46+ username = db_user , password = cdk .SecretValue .unsafe_plain_text (db_password )
4747 ),
4848 database_name = db_name ,
4949 engine = rds .DatabaseInstanceEngine .MARIADB ,
@@ -53,15 +53,20 @@ def __init__(self, scope: constructs.Construct, construct_id: str, **kwargs) ->
5353 # ECS cluster
5454 cluster = ecs .Cluster (self , "ServiceCluster" , vpc = self .vpc )
5555
56+ wp_health_check = ecs .HealthCheck (
57+ command = ['CMD-SHELL' , 'curl -s -o /dev/null -w "%{http_code}" http://localhost | grep -qE "200|301|302"' ],
58+ start_period = cdk .Duration .minutes (2 )
59+ )
60+
5661 docker_image = ecs .ContainerImage .from_registry ("wordpress" )
5762 web_service = ecs_patterns .ApplicationLoadBalancedFargateService (
5863 self ,
5964 "Wordpress" ,
6065 cluster = cluster ,
6166 target_protocol = elbv2 .ApplicationProtocol .HTTP ,
6267 protocol = elbv2 .ApplicationProtocol .HTTP ,
68+ health_check = wp_health_check ,
6369 desired_count = 1 ,
64- # container size
6570 cpu = 512 ,
6671 memory_limit_mib = 2048 ,
6772 task_image_options = ecs_patterns .ApplicationLoadBalancedTaskImageOptions (
@@ -78,4 +83,13 @@ def __init__(self, scope: constructs.Construct, construct_id: str, **kwargs) ->
7883 ),
7984 )
8085
86+ web_service .target_group .configure_health_check (
87+ path = "/index.php" ,
88+ healthy_http_codes = "200,301,302" ,
89+ interval = cdk .Duration .seconds (120 ),
90+ unhealthy_threshold_count = 10
91+ )
92+
93+ database .connections .allow_default_port_from (web_service .service .connections )
94+
8195 # TODO: add APIGW and dns + cert
0 commit comments