コード例 #1
0
    def __init__(self, scope: Construct, id: str, vpc: IVpc, **kwargs) -> None:
        super().__init__(scope, id, **kwargs)

        Tags.of(self).add("Stack", "Common-Ecs")

        self._cluster = Cluster(
            self,
            "Cluster",
            vpc=vpc,
        )

        asg = AutoScalingGroup(
            self,
            "ClusterASG",
            vpc=vpc,
            instance_type=InstanceType("t3a.small"),
            machine_image=EcsOptimizedImage.amazon_linux2(),
            min_capacity=4,
        )
        self._cluster.add_auto_scaling_group(asg)

        # Create a SecurityGroup that the NLB can use to allow traffic from
        # NLB to us. This avoids a cyclic dependency.
        self.security_group = SecurityGroup(
            self,
            "SecurityGroup",
            vpc=vpc,
            allow_all_outbound=False,
        )

        # Only use "source_security_group" to check if flows come from ECS.
        # Do not use it to allow traffic in ECS; use "security_group" for
        # that.
        assert isinstance(asg.node.children[0], SecurityGroup)
        self.source_security_group = asg.node.children[0]

        # We could also make an additional security-group and add that to
        # the ASG, but it keeps adding up. This makes it a tiny bit
        # easier to get an overview what traffic is allowed from the
        # console on AWS.
        asg.node.children[0].add_ingress_rule(
            peer=self.security_group,
            connection=Port.tcp_range(32768, 65535),
            description="NLB-self to target",
        )
        asg.node.children[0].add_ingress_rule(
            peer=self.security_group,
            connection=Port.udp_range(32768, 65535),
            description="NLB-self to target (UDP)",
        )
コード例 #2
0
 def __attach_public_access_rule(self):
     public_access_port = Port.tcp_range(start_port=30000, end_port=32767)
     self._worker_security_group.connections.allow_from_any_ipv4(
         port_range=public_access_port)
コード例 #3
0
 def __attach_api_server_internal_access_rule(self):
     api_server_internal_port = Port.tcp_range(start_port=10250,
                                               end_port=10252)
     self._master_security_group.connections.allow_internally(
         port_range=api_server_internal_port)
コード例 #4
0
 def __attach_etcd_server_access_rule(self):
     etcd_server_access_port = Port.tcp_range(start_port=2379,
                                              end_port=2380)
     self._master_security_group.connections.allow_internally(
         port_range=etcd_server_access_port)