private void ConfigureTaskDefinition(IRecipeProps <Configuration> props) { var settings = props.Settings; AppTaskDefinition = new FargateTaskDefinition(this, nameof(AppTaskDefinition), InvokeCustomizeCDKPropsEvent(nameof(AppTaskDefinition), this, new FargateTaskDefinitionProps { TaskRole = AppIAMTaskRole, Cpu = settings.TaskCpu, MemoryLimitMiB = settings.TaskMemory })); AppLogging = new AwsLogDriver(InvokeCustomizeCDKPropsEvent(nameof(AppLogging), this, new AwsLogDriverProps { StreamPrefix = props.StackName })); if (string.IsNullOrEmpty(props.ECRRepositoryName)) { throw new InvalidOrMissingConfigurationException("The provided ECR Repository Name is null or empty."); } var ecrRepository = Repository.FromRepositoryName(this, "ECRRepository", props.ECRRepositoryName); AppContainerDefinition = new ContainerDefinitionOptions { Image = ContainerImage.FromEcrRepository(ecrRepository, props.ECRImageTag), Logging = AppLogging }; AppTaskDefinition.AddContainer(nameof(AppContainerDefinition), InvokeCustomizeCDKPropsEvent(nameof(AppContainerDefinition), this, AppContainerDefinition)); }
public FargateStack(Construct scope, string id, FargateStackProps props = null) : base(scope, id, props) { var cluster = new Cluster(this, "WhatDayOfWeekCluster", new ClusterProps { Vpc = props.Vpc }); var logging = new AwsLogDriver(new AwsLogDriverProps() { StreamPrefix = "WhatDayOfWeek", LogRetention = Amazon.CDK.AWS.Logs.RetentionDays.ONE_DAY }); //container /* * var repo = Repository.FromRepositoryName(this, "myrepo","MyRepositoryName"); * * var containerOptions = new ContainerDefinitionOptions * { * Image = ContainerImage.FromEcrRepository(repo) * }; */ // to build the container image from the app in the local folder, replace lines 29-35 with //var rootDirectory = Directory.GetCurrentDirectory(); //var path = Path.GetFullPath(Path.Combine(rootDirectory, @"App/WhatDayOfWeek")); var containerOptions = new ContainerDefinitionOptions { Image = ContainerImage.FromAsset(@"App/WhatDayOfWeek"), Logging = logging }; var portMapping = new PortMapping() { ContainerPort = 80, HostPort = 80 }; var taskDef = new FargateTaskDefinition(this, "WhatDayOfWeekTaskDefinition"); taskDef.AddContainer("WhatDayOfWeekContainer", containerOptions).AddPortMappings(portMapping); var serviceProps = new ApplicationLoadBalancedFargateServiceProps() { ServiceName = "WhatDayOfWeekService", MemoryLimitMiB = 512, Cpu = 256, TaskDefinition = taskDef, Cluster = cluster }; ApplicationLoadBalancedFargateService service = new ApplicationLoadBalancedFargateService(this, "WhatDayOfWeekService", serviceProps); }
public ContainersStack(Construct parent, string id, IStackProps props) : base(parent, id, props) { var vpc = Vpc.FromLookup(this, id = "DefaultVpc", new VpcLookupOptions { IsDefault = true }); if (vpc == null) { throw new System.NullReferenceException($"Unable to determine default VPC in region {this.Region}"); } var cluster = new Cluster(this, "Cluster", new ClusterProps { Vpc = vpc }); var taskDef = new FargateTaskDefinition(this, "FargateTaskDefinition"); var currentDir = Directory.GetCurrentDirectory(); var path = Path.GetFullPath(Path.Combine(currentDir, @"dotnetapp/")); var containerOptions = new ContainerDefinitionOptions { Image = ContainerImage.FromAsset("dotnetapp") }; var portMapping = new PortMapping() { ContainerPort = 80, HostPort = 80 }; taskDef.AddContainer("Container", containerOptions).AddPortMappings(portMapping); var serviceProps = new ApplicationLoadBalancedFargateServiceProps() { MemoryLimitMiB = 512, Cpu = 256, TaskDefinition = taskDef }; ApplicationLoadBalancedFargateService service = new ApplicationLoadBalancedFargateService(this, "DotnetFargateApp", serviceProps); }
internal FargateStack(Construct scope, string id, IStackProps props = null) : base(scope, id, props) { // Create VPC var vpc = new Vpc(this, "SampleVpc", new VpcProps { MaxAzs = 2 }); // Create ECS cluster var cluster = new Cluster(this, "SampleCluster", new ClusterProps { Vpc = vpc }); var taskDef = new FargateTaskDefinition(this, "FargateTaskDefinition"); // Build container image from local assets var containerOptions = new ContainerDefinitionOptions { Image = ContainerImage.FromAsset("webapp") }; var portMapping = new PortMapping() { ContainerPort = 80, HostPort = 80 }; taskDef .AddContainer("Container", containerOptions) .AddPortMappings(portMapping); // Create Fargate Service behind Application Load Balancer new ApplicationLoadBalancedFargateService(this, "DotnetFargateSampleApp", new ApplicationLoadBalancedFargateServiceProps() { Cluster = cluster, MemoryLimitMiB = 512, Cpu = 256, TaskDefinition = taskDef }); }
public ContainersStack(Construct parent, string id, IStackProps props) : base(parent, id, props) { // The code that defines your stack goes here var vpc = new Vpc(this, "VPC"); var cluster = new Cluster(this, "Cluster", new ClusterProps { Vpc = vpc }); var taskDef = new FargateTaskDefinition(this, "FargateTaskDefinition"); var rootDirectory = Directory.GetCurrentDirectory(); var path = Path.GetFullPath(Path.Combine(rootDirectory, @"dotnetapp/")); var containerOptions = new ContainerDefinitionOptions { Image = ContainerImage.FromAsset("dotnetapp") }; var portMapping = new PortMapping() { ContainerPort = 80, HostPort = 80 }; taskDef.AddContainer("Container", containerOptions).AddPortMappings(portMapping); var serviceProps = new ApplicationLoadBalancedFargateServiceProps() { MemoryLimitMiB = 512, Cpu = 256, TaskDefinition = taskDef }; ApplicationLoadBalancedFargateService service = new ApplicationLoadBalancedFargateService(this, "DotnetFargateApp", serviceProps); }
internal Example3Stack(Construct scope, string id, IStackProps props = null) : base(scope, id, props) { var vpcStack = new VpcStack(this, "someTestVpc"); var cluster = new Cluster(this, "WhatDayOfWeekCluster", new ClusterProps { Vpc = vpcStack.Vpc }); var taskDef = new FargateTaskDefinition(this, "WhatDayOfWeekTaskDefinition"); var rootDirectory = Directory.GetCurrentDirectory(); var path = Path.GetFullPath(Path.Combine(rootDirectory, @"App/WhatDayOfWeek")); var containerOptions = new ContainerDefinitionOptions { Image = ContainerImage.FromAsset("App/WhatDayOfWeek") }; var portMapping = new PortMapping() { ContainerPort = 80, HostPort = 80 }; taskDef.AddContainer("WhatDayOfWeekContainer", containerOptions).AddPortMappings(portMapping); var serviceProps = new ApplicationLoadBalancedFargateServiceProps() { MemoryLimitMiB = 512, Cpu = 256, TaskDefinition = taskDef }; ApplicationLoadBalancedFargateService service = new ApplicationLoadBalancedFargateService(this, "WhatDayOfWeekApp", serviceProps); }