Skip to content

Commit e83c258

Browse files
authored
make sample aws deployable
2 parents 7607306 + a48996d commit e83c258

File tree

7 files changed

+47
-30
lines changed

7 files changed

+47
-30
lines changed

Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,22 @@ deploy-local:
3030
cdklocal bootstrap || true; \
3131
cdklocal deploy --all --require-approval never
3232

33+
deploy-aws:
34+
$(VENV_RUN); \
35+
cd deployments/cdk; \
36+
cdk bootstrap || true; \
37+
cdk deploy --all --require-approval never
38+
3339
destroy-local:
3440
$(VENV_RUN); \
3541
cd deployments/cdk; \
3642
cdklocal destroy --all
3743

44+
destroy-aws:
45+
$(VENV_RUN); \
46+
cd deployments/cdk; \
47+
cdk destroy --all
48+
3849
format:
3950
$(VENV_ACTIVATE); python -m isort .; python -m black .
4051

deployments/cdk/app.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import aws_cdk as cdk
2-
import env
32
from wordpress import WordpressStack
43

54

65
def main():
76
app = cdk.App()
87

9-
WordpressStack(app, "WordpressStack", env=env.ENV_LOCAL)
8+
WordpressStack(app, "WordpressStack")
109

1110
app.synth()
1211

deployments/cdk/env.py

Lines changed: 0 additions & 7 deletions
This file was deleted.

deployments/cdk/wordpress.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

package-lock.json

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

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"dependencies": {
3-
"aws-cdk": "^2.20.0",
4-
"aws-cdk-local": "^2.15.0"
3+
"aws-cdk": "^2.139.1",
4+
"aws-cdk-local": "^2.18.0"
55
}
66
}

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ dev =
3434
%(deploy)s
3535

3636
deploy =
37-
aws-cdk-lib==2.20.0
37+
aws-cdk-lib==2.139.1
3838
constructs>=10.0.0,<11.0.0
3939

4040
[options.package_data]

0 commit comments

Comments
 (0)