Skip to content
This repository was archived by the owner on Mar 27, 2023. It is now read-only.

Commit 156efb3

Browse files
committed
added bastion host
1 parent 2b0f8d2 commit 156efb3

File tree

3 files changed

+53
-2
lines changed

3 files changed

+53
-2
lines changed

awscdk/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from aws_cdk import core
55

6-
from awscdk.cdk_app_root import ApplicationStack
6+
from awscdk.app_stack import ApplicationStack
77

88
# naming conventions, also used for ACM certs, DNS Records, resource naming
99
# Dynamically generated resource names created in CDK are used in GitLab CI
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from static_site_bucket import StaticSiteStack
1616
from flower import FlowerServiceStack
1717
from celery_autoscaling import CeleryAutoscalingStack
18+
from bastion_host import BastionHost
1819

1920
from backend import BackendServiceStack
2021
from backend_tasks import BackendTasksStack
@@ -80,7 +81,9 @@ def __init__(
8081

8182
# image used for all django containers: gunicorn, daphne, celery, beat
8283
self.image = ecs.AssetImage(
83-
"./backend", file="scripts/prod/Dockerfile", target="production",
84+
"./backend",
85+
file="scripts/prod/Dockerfile",
86+
target="production",
8487
)
8588

8689
self.variables = Variables(
@@ -110,3 +113,6 @@ def __init__(
110113

111114
# migrate, collectstatic, createsuperuser
112115
self.backend_tasks = BackendTasksStack(self, "BackendTasksStack")
116+
117+
# bastion host
118+
self.bastion_host = BastionHost(self, "BastionHost")

awscdk/awscdk/bastion_host.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import os
2+
3+
from aws_cdk import (
4+
aws_autoscaling as autoscaling,
5+
aws_cloudformation as cloudformation,
6+
aws_ec2 as ec2,
7+
aws_ecs as ecs,
8+
core,
9+
)
10+
11+
12+
class BastionHost(cloudformation.NestedStack):
13+
def __init__(
14+
self,
15+
scope: core.Construct,
16+
id: str,
17+
**kwargs,
18+
) -> None:
19+
super().__init__(
20+
scope,
21+
id,
22+
**kwargs,
23+
)
24+
25+
self.asg = autoscaling.AutoScalingGroup(
26+
self,
27+
"AutoScalingGroup",
28+
instance_type=ec2.InstanceType("t2.micro"),
29+
machine_image=ecs.EcsOptimizedAmi(),
30+
associate_public_ip_address=True,
31+
update_type=autoscaling.UpdateType.REPLACING_UPDATE,
32+
desired_capacity=1,
33+
vpc=scope.vpc,
34+
vpc_subnets={'subnet_type': ec2.SubnetType.PUBLIC},
35+
)
36+
37+
self.cluster = ecs.Cluster(self, 'EcsCluster', vpc=scope.vpc)
38+
39+
self.cluster.add_auto_scaling_group(self.asg)
40+
self.cluster.add_capacity(
41+
"DefaultAutoScalingGroup",
42+
instance_type=ec2.InstanceType("t2.micro"),
43+
max_capacity=2,
44+
key_name=os.environ.get("KEY_NAME"),
45+
)

0 commit comments

Comments
 (0)