in dcv_session_manager_infrastructure/dcv_session_manager_infrastructure_stack.py [0:0]
def __init__(self, scope: core.Construct, construct_id: str, config: list, **kwargs) -> None:
super().__init__(scope, construct_id, **kwargs)
# Copy the required files to S3
closing_hook = assets.Asset(
self, "ClosingHook", path='scripts/alb.session.closing.hook.sh')
starting_hook = assets.Asset(
self, "StartingHook", path='scripts/alb.session.starting.hook.sh')
interactive_builtin_linux_desktop = assets.Asset(
self, "LinuxDesktop", path='scripts/interactive_builtin_linux_desktop.xml')
interactive_builtin_windows_desktop = assets.Asset(
self, "WindowsDesktop", path='scripts/interactive_builtin_windows_desktop.xml')
# VPC creation
vpc = ec2.Vpc(self, "VPC",
max_azs=2,
cidr="10.0.0.0/16",
subnet_configuration=[ec2.SubnetConfiguration(
subnet_type=ec2.SubnetType.PUBLIC,
name="Public",
cidr_mask=24
)])
# Create ALB
alb_security_group, lb_enginframe = self.create_alb(vpc)
# Create the EF and DCV security groups
ef_security_group, dcv_security_group = self.create_security_groups(
vpc, alb_security_group)
# Create the SSM parameters that will contain the hostname of the EnginFrame instance and the certificate of the DCVSM broker
ef_nodename_parameter, dcvsm_certificate = self.create_parameters()
# ROLES
role_ef = self.create_ef_role(
ef_nodename_parameter, dcvsm_certificate, config, closing_hook, starting_hook, interactive_builtin_linux_desktop, interactive_builtin_windows_desktop)
role_dcv = self.create_dcv_role(
ef_nodename_parameter, dcvsm_certificate, config)
# create EF and DCV instances
asg_enginframe = self.create_enginframe(
config, lb_enginframe, vpc, role_ef, ef_security_group, closing_hook, starting_hook, interactive_builtin_linux_desktop, interactive_builtin_windows_desktop)
asg_dcv_linux = self.create_dcv_linux(
config, vpc, role_dcv, dcv_security_group)
asg_dcv_windows = self.create_dcv_windows(
config, vpc, role_dcv, dcv_security_group)
# Create Lambda
lambda_function = self.create_lambda(lb_enginframe)
# Get the ACM certificate ARM from the lambda function
certificate_arn = lambda_function.get_att_string("ACMCertificateArn")
certificate = acm.Certificate.from_certificate_arn(
self, 'Certificate', certificate_arn)
# ALB listener
listener_enginframe = lb_enginframe.add_listener(
"Listener", port=443, certificates=[certificate])
listener_enginframe.add_targets(
"Target", port=8443, targets=[asg_enginframe])
listener_enginframe.connections.allow_default_port_from_any_ipv4(
"Open to the world")
# ASG dependency
asg_dcv_linux.node.add_dependency(asg_enginframe)
asg_dcv_windows.node.add_dependency(asg_enginframe)
# Return the ALB url
core.CfnOutput(self, "EnginFramePortalURL",
value="https://"+lb_enginframe.load_balancer_dns_name)