Last active
December 29, 2020 20:15
-
-
Save OksanaH/67b285d3036b0cc66460044d04e0fa31 to your computer and use it in GitHub Desktop.
FargateStack.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Amazon.CDK; | |
using Amazon.CDK.AWS.EC2; | |
using Amazon.CDK.AWS.ECR; | |
using Amazon.CDK.AWS.ECS; | |
using Amazon.CDK.AWS.ECS.Patterns; | |
namespace Fargate | |
{ | |
public class RandomNumStack : Stack | |
{ | |
internal RandomNumStack(Construct scope, string id, IStackProps props = null) : base(scope, id, props) | |
{ | |
var vpc = new Vpc(this, "VPC"); | |
var cluster = new Cluster(this, "Cluster", new ClusterProps{ | |
Vpc = vpc, | |
ClusterName = "RandomNumGeneratorAppCluster" | |
}); | |
var taskDefinition = new FargateTaskDefinition(this, "RandomNumGeneratorTaskDefinition", new FargateTaskDefinitionProps | |
{ | |
Family = "RandomNumGeneratorTaskDefinition" | |
}); | |
var repo = Repository.FromRepositoryName(this, "RandomNumGeneratorECR", "number-generator"); | |
var logging = new AwsLogDriver(new AwsLogDriverProps() { | |
StreamPrefix = "RandomNumGeneratorApp", | |
LogRetention = Amazon.CDK.AWS.Logs.RetentionDays.ONE_DAY | |
}); | |
var containerOptions = new ContainerDefinitionOptions | |
{ | |
Image = ContainerImage.FromEcrRepository(repo), | |
Logging = logging | |
}; | |
var portMapping = new PortMapping() | |
{ | |
ContainerPort = 80, | |
HostPort = 80 | |
}; | |
taskDefinition.AddContainer("RandomNumGeneratorAppContainer", containerOptions).AddPortMappings(portMapping); | |
var serviceProps = new ApplicationLoadBalancedFargateServiceProps() | |
{ | |
MemoryLimitMiB = 512, | |
Cpu = 256, | |
TaskDefinition = taskDefinition, | |
ServiceName = "RandomNumGeneratorAppService", | |
Cluster = cluster | |
}; | |
ApplicationLoadBalancedFargateService service = new ApplicationLoadBalancedFargateService(this, "RandomNumGeneratorAppService", serviceProps); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment