Beispiel #1
0
        public FargateStack(Construct parent, string id, IStackProps props) : base(parent, id, props)
        {
            var vpc = new VpcNetwork(this, "MyVpc", new VpcNetworkProps()
            {
                MaxAZs = 2
            });
            var cluster = new Cluster(this, "Cluster", new ClusterProps()
            {
                Vpc = VpcNetwork.Import(this, "vpc2", vpc.Export())
            });
            var env = new Dictionary <string, string>();

            // Instantiate Fargate Service with just cluster and image
            var fargateService = new LoadBalancedFargateService(this, "FargateService",
                                                                new LoadBalancedFargateServiceProps()
            {
                Cluster = cluster,
                //Image = ContainerImage.FromRegistry("amazon/amazon-ecs-sample", null),
                Image              = ContainerImage.FromRegistry("karthequian/helloworld", null),
                Environment        = env,
                PublicLoadBalancer = true,
                CreateLogs         = true
            });

            // Output the DNS where you can access your service
            new CfnOutput(this, "LoadBalancerDNS", new CfnOutputProps()
            {
                Value = fargateService.LoadBalancer.DnsName
            });
        }
        internal DotnetStack(Construct scope, string id, IStackProps props = null) : base(scope, id, props)
        {
            var vpc = new Vpc(this, "MyVpc", new VpcProps
            {
                MaxAzs = 3 // Max zones
            });

            var cluster = new Cluster(this, "MyCluster", new ClusterProps
            {
                Vpc = vpc
            });

            var serviceProps = new ApplicationLoadBalancedFargateServiceProps()
            {
                Cluster          = cluster, // Required
                DesiredCount     = 5,       // Default is 1
                TaskImageOptions = new ApplicationLoadBalancedTaskImageOptions
                {
                    Image = ContainerImage.FromRegistry("amazon/amazon-ecs-sample") // PHP Sample :-( my bad => https://hub.docker.com/r/amazon/amazon-ecs-sample
                },
                MemoryLimitMiB     = 2048,                                          // Default is 256
                PublicLoadBalancer = true,                                          // Default is false
            };

            // Create Loadbalancer fargate and make it public

            new ApplicationLoadBalancedFargateService(this, "MyFargateService",
                                                      serviceProps);
        }
Beispiel #3
0
 public PingPongServices(Construct scope, string id, PingPongServicesProps props) : base(scope, id)
 {
     var pingImage  = ContainerImage.FromAsset($"ping-service");
     var pongImage  = ContainerImage.FromAsset($"pong-service");
     var envoyImage = ContainerImage.FromRegistry($"840364872350.dkr.ecr.{props.Env.Region}.amazonaws.com/aws-appmesh-envoy:v1.12.3.0-prod");
     // TODO: Maybe just create this role here as part of the stack. I think it gets created with the ECS cluster automatically.
     var taskExecRole = Role.FromRoleArn(this, "task-execution-role", $"arn:aws:iam::{props.Env.Account}:role/ecsTaskExecutionRole");
     var pingService  = new PingPongServiceConstruct(this, $"{id}_ping-master", new PingPongServiceConstructProps()
     {
         ServiceContainerImage = pingImage,
         EnvoyImage            = envoyImage,
         TaskExecutionRole     = taskExecRole,
         ServiceName           = "ping",
         Branch            = "master",
         Mesh              = props.Mesh,
         CloudmapNamespace = props.CloudmapNamespace,
         VirturalNodeName  = $"ping-service-master-node",
         Cluster           = props.Cluster,
         Vpc           = props.Vpc,
         Backends      = new VirtualService[] { props.PongVirtualService },
         VirtualRouter = props.PingVirtualRouter,
         RoutePriority = 0
     });
     var pongMasterService = new PingPongServiceConstruct(this, $"{id}_pong-master", new PingPongServiceConstructProps()
     {
         ServiceContainerImage = pongImage,
         EnvoyImage            = envoyImage,
         TaskExecutionRole     = taskExecRole,
         ServiceName           = "pong",
         Branch            = "master",
         Mesh              = props.Mesh,
         CloudmapNamespace = props.CloudmapNamespace,
         VirturalNodeName  = $"pong-service-master-node",
         Cluster           = props.Cluster,
         Vpc           = props.Vpc,
         Backends      = new VirtualService[] { },
         VirtualRouter = props.PongVirtualRouter,
         RoutePriority = 2
     });
     var pongBranchService = new PingPongServiceConstruct(this, $"{id}_pong-testbranch", new PingPongServiceConstructProps()
     {
         ServiceContainerImage = pongImage,
         EnvoyImage            = envoyImage,
         TaskExecutionRole     = taskExecRole,
         ServiceName           = "pong",
         Branch            = "testbranch",
         Mesh              = props.Mesh,
         CloudmapNamespace = props.CloudmapNamespace,
         VirturalNodeName  = $"pong-service-testbranch-node",
         Cluster           = props.Cluster,
         Vpc           = props.Vpc,
         Backends      = new VirtualService[] { },
         VirtualRouter = props.PongVirtualRouter,
         RoutePriority = 1
     });
 }