예제 #1
0
        private IApplicationTargetGroup AddHttpsTargetGroup(BenchNetwork benchNetwork, Vpc vpc, DnsValidatedCertificate certificate, ApplicationLoadBalancer lb)
        {
            var targetGroup = new ApplicationTargetGroup(this, $"{StackName}-https-target-group", new ApplicationTargetGroupProps
            {
                Port        = benchNetwork.AlbHttpsPort.targetgroupPort,
                Protocol    = ApplicationProtocol.HTTP,
                Vpc         = vpc,
                TargetType  = TargetType.INSTANCE,
                HealthCheck = new Amazon.CDK.AWS.ElasticLoadBalancingV2.HealthCheck
                {
                    Enabled  = true,
                    Protocol = Amazon.CDK.AWS.ElasticLoadBalancingV2.Protocol.HTTP,
                    HealthyThresholdCount = 2,
                    Interval = Duration.Seconds(15),
                    Timeout  = Duration.Seconds(10),
                    Path     = "/health",
                },
                DeregistrationDelay = Duration.Seconds(30),
            });
            var listener = lb.AddListener("HttpsListener", new BaseApplicationListenerProps
            {
                Port         = benchNetwork.AlbHttpsPort.listenerPort,
                Protocol     = ApplicationProtocol.HTTPS,
                Certificates = new[] { new ListenerCertificate(certificate.CertificateArn) },
            });

            listener.AddTargetGroups("HttpsTargetGroupAttachment", new AddApplicationTargetGroupsProps
            {
                TargetGroups = new[] { targetGroup },
            });
            return(targetGroup);
        }
예제 #2
0
        private IApplicationTargetGroup AddGrpcTargetGroup(BenchNetwork benchNetwork, Vpc vpc, DnsValidatedCertificate certificate, ApplicationLoadBalancer lb)
        {
            var grpcTargetGroupResource = CreateGrpcTargetGroup(vpc, new Dictionary <string, object>()
            {
                { "Name", "MagicOnionBench-grpc-target" },
                { "Port", benchNetwork.AlbGrpcPort.targetgroupPort },
                { "Protocol", ApplicationProtocol.HTTP.ToString() },
                { "ProtocolVersion", "GRPC" },
                { "VpcId", vpc.VpcId },
                { "TargetType", "instance" },
                { "HealthCheckEnabled", true },
                { "HealthCheckProtocol", Amazon.CDK.AWS.ElasticLoadBalancingV2.Protocol.HTTP.ToString() },
                { "HealthyThresholdCount", 2 },
                { "HealthCheckIntervalSeconds", 15 },
                { "HealthCheckTimeoutSeconds", 10 },
                { "HealthCheckPath", "/grpc.health.v1.Health/Check" },
                { "Matcher", new Dictionary <string, string> {
                      { "GrpcCode", "0-99" }
                  } },
            });
            var targetGroup = ApplicationTargetGroup.FromTargetGroupAttributes(this, "grpc-target-group", new TargetGroupAttributes
            {
                TargetGroupArn = grpcTargetGroupResource.Ref,
            });
            var listener = lb.AddListener("GrpcListener", new BaseApplicationListenerProps
            {
                Port         = benchNetwork.AlbGrpcPort.listenerPort,
                Protocol     = ApplicationProtocol.HTTPS,
                Certificates = new[] { new ListenerCertificate(certificate.CertificateArn) },
            });

            listener.AddTargetGroups("GrpcTargetGroupAttachment", new AddApplicationTargetGroupsProps
            {
                TargetGroups = new[] { targetGroup },
            });
            listener.Node.AddDependency(grpcTargetGroupResource);

            return(targetGroup);
        }