How to use the @aws-cdk/aws-ec2.InstanceType function in @aws-cdk/aws-ec2

To help you get started, we’ve selected a few @aws-cdk/aws-ec2 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nathanpeck / greeter-cdk / index.js View on Github external
constructor(parent, id, props) {
    super(parent, id, props);

    const vpc = new ec2.Vpc(this, 'GreetingVpc', { maxAZs: 2 });

    // Create an ECS cluster
    const cluster = new ecs.Cluster(this, 'Cluster', { vpc });

    // Add capacity to it
    cluster.addCapacity('greeter-capacity', {
      instanceType: new ec2.InstanceType('t3.xlarge'),
      minCapacity: 3,
      maxCapacity: 3
    });

    // Name service
    const nameTaskDefinition = new ecs.Ec2TaskDefinition(this, 'name-task-definition', {});

    const nameContainer = nameTaskDefinition.addContainer('name', {
      image: ecs.ContainerImage.fromRegistry('nathanpeck/name'),
      memoryLimitMiB: 128
    });

    nameContainer.addPortMappings({
      containerPort: 3000
    });
github aws / aws-cdk / examples / cdk-examples-typescript / hello-cdk-ecs / index.ts View on Github external
constructor(scope: cdk.App, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    // For better iteration speed, it might make sense to put this VPC into
    // a separate stack and import it here. We then have two stacks to
    // deploy, but VPC creation is slow so we'll only have to do that once
    // and can iterate quickly on consuming stacks. Not doing that for now.
    const vpc = new ec2.VpcNetwork(this, 'MyVpc', { maxAZs: 2 });
    const cluster = new ecs.Cluster(this, 'Ec2Cluster', { vpc });
    cluster.addDefaultAutoScalingGroupCapacity({
      instanceType: new InstanceType("t2.xlarge"),
      instanceCount: 3,
    });

    // Instantiate ECS Service with just cluster and image
    const ecsService = new ecs.LoadBalancedEc2Service(this, "Ec2Service", {
      cluster,
      memoryLimitMiB: 512,
      image: ecs.ContainerImage.fromDockerHub("amazon/amazon-ecs-sample"),
    });

    // ecsService.addTracing

    // Output the DNS where you can access your service
    new cdk.Output(this, 'LoadBalancerDNS', { value: ecsService.loadBalancer.dnsName });
  }
}
github aws-samples / aws-cdk-examples / typescript / ecs / cluster / index.ts View on Github external
constructor(scope: cdk.App, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    const vpc = new ec2.VpcNetwork(this, 'MyVpc', { maxAZs: 2 });

    const asg = new autoscaling.AutoScalingGroup(this, 'MyFleet', {
      instanceType: new InstanceType("t2.xlarge"),
      machineImage: new ecs.EcsOptimizedAmi(),
      associatePublicIpAddress: true,
      updateType: autoscaling.UpdateType.ReplacingUpdate,
      desiredCapacity: 3,
      vpc
    });

    const cluster = new ecs.Cluster(this, 'EcsCluster', { vpc });
    cluster.addAutoScalingGroup(asg);

      cluster.addCapacity('DefaultAutoScalingGroup', {
        instanceType: new ec2.InstanceType('t2.micro')
      });

  }
}