How to use the @aws-cdk/aws-ecs.Ec2TaskDefinition function in @aws-cdk/aws-ecs

To help you get started, we’ve selected a few @aws-cdk/aws-ecs 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 aws / aws-cdk / packages / @aws-cdk / aws-ecs-patterns / lib / ecs / queue-processing-ecs-service.ts View on Github external
constructor(scope: Construct, id: string, props: QueueProcessingEc2ServiceProps) {
    super(scope, id, props);

    // Create a Task Definition for the container to start
    this.taskDefinition = new Ec2TaskDefinition(this, 'QueueProcessingTaskDef');
    this.taskDefinition.addContainer('QueueProcessingContainer', {
      image: props.image,
      memoryLimitMiB: props.memoryLimitMiB,
      memoryReservationMiB: props.memoryReservationMiB,
      cpu: props.cpu,
      command: props.command,
      environment: this.environment,
      secrets: this.secrets,
      logging: this.logDriver
    });

    // Create an ECS service with the previously defined Task Definition and configure
    // autoscaling based on cpu utilization and number of messages visible in the SQS queue.
    this.service = new Ec2Service(this, 'QueueProcessingService', {
      cluster: this.cluster,
      desiredCount: this.desiredCount,
github nathanpeck / greeter-cdk / index.js View on Github external
internalListener.addTargets('name', {
      port: 80,
      pathPattern: '/name*',
      priority: 1,
      targets: [nameService]
    });

    internalListener.addTargets('greeting', {
      port: 80,
      pathPattern: '/greeting*',
      priority: 2,
      targets: [greetingService]
    });

    // Greeter service
    const greeterTaskDefinition = new ecs.Ec2TaskDefinition(this, 'greeter-task-definition', {});

    const greeterContainer = greeterTaskDefinition.addContainer('greeter', {
      image: ecs.ContainerImage.fromRegistry('nathanpeck/greeter'),
      memoryLimitMiB: 128,
      environment: {
        GREETING_URL: 'http://' + internalLB.loadBalancerDnsName + '/greeting',
        NAME_URL: 'http://' + internalLB.loadBalancerDnsName + '/name'
      }
    });

    greeterContainer.addPortMappings({
      containerPort: 3000
    });

    const greeterService = new ecs.Ec2Service(this, 'greeter-service', {
      cluster: cluster,
github nathanpeck / greeter-cdk / index.js View on Github external
image: ecs.ContainerImage.fromRegistry('nathanpeck/name'),
      memoryLimitMiB: 128
    });

    nameContainer.addPortMappings({
      containerPort: 3000
    });

    const nameService = new ecs.Ec2Service(this, 'name-service', {
      cluster: cluster,
      desiredCount: 2,
      taskDefinition: nameTaskDefinition
    });

    // Greeting service
    const greetingTaskDefinition = new ecs.Ec2TaskDefinition(this, 'greeting-task-definition', {});

    const greetingContainer = greetingTaskDefinition.addContainer('greeting', {
      image: ecs.ContainerImage.fromRegistry('nathanpeck/greeting'),
      memoryLimitMiB: 128
    });

    greetingContainer.addPortMappings({
      containerPort: 3000
    });

    const greetingService = new ecs.Ec2Service(this, 'greeting-service', {
      cluster: cluster,
      desiredCount: 2,
      taskDefinition: greetingTaskDefinition
    });
github aws / aws-cdk / packages / @aws-cdk / aws-ecs-patterns / lib / ecs / scheduled-ecs-task.ts View on Github external
constructor(scope: Construct, id: string, props: ScheduledEc2TaskProps) {
    super(scope, id, props);

    // Create a Task Definition for the container to start, also creates a log driver
    this.taskDefinition = new Ec2TaskDefinition(this, 'ScheduledTaskDef');
    this.taskDefinition.addContainer('ScheduledContainer', {
      image: props.image,
      memoryLimitMiB: props.memoryLimitMiB,
      memoryReservationMiB: props.memoryReservationMiB,
      cpu: props.cpu,
      command: props.command,
      environment: props.environment,
      secrets: props.secrets,
      logging: this.logDriver
    });

    this.addTaskDefinitionToEventTarget(this.taskDefinition);
  }
}
github aws / aws-cdk / packages / @aws-cdk / aws-ecs-patterns / lib / ecs / application-load-balanced-ecs-service.ts View on Github external
constructor(scope: Construct, id: string, props: ApplicationLoadBalancedEc2ServiceProps = {}) {
    super(scope, id, props);

    if (props.taskDefinition && props.taskImageOptions) {
      throw new Error('You must specify either a taskDefinition or taskImageOptions, not both.');
    } else if (props.taskDefinition) {
      this.taskDefinition = props.taskDefinition;
    } else if (props.taskImageOptions) {
      const taskImageOptions = props.taskImageOptions;
      this.taskDefinition = new Ec2TaskDefinition(this, 'TaskDef', {
        executionRole: taskImageOptions.executionRole,
        taskRole: taskImageOptions.taskRole,
        family: taskImageOptions.family,
      });

      // Create log driver if logging is enabled
      const enableLogging = taskImageOptions.enableLogging !== undefined ? taskImageOptions.enableLogging : true;
      const logDriver = taskImageOptions.logDriver !== undefined
                          ? taskImageOptions.logDriver : enableLogging
                            ? this.createAWSLogDriver(this.node.id) : undefined;

      const containerName = taskImageOptions.containerName !== undefined ? taskImageOptions.containerName : 'web';
      const container = this.taskDefinition.addContainer(containerName, {
        image: taskImageOptions.image,
        cpu: props.cpu,
        memoryLimitMiB: props.memoryLimitMiB,
github aws / aws-cdk / packages / @aws-cdk / aws-ecs-patterns / lib / ecs / network-load-balanced-ecs-service.ts View on Github external
constructor(scope: Construct, id: string, props: NetworkLoadBalancedEc2ServiceProps = {}) {
    super(scope, id, props);

    if (props.taskDefinition && props.taskImageOptions) {
      throw new Error('You must specify either a taskDefinition or an image, not both.');
    } else if (props.taskDefinition) {
      this.taskDefinition = props.taskDefinition;
    } else if (props.taskImageOptions) {
      const taskImageOptions = props.taskImageOptions;
      this.taskDefinition = new Ec2TaskDefinition(this, 'TaskDef', {
        executionRole: taskImageOptions.executionRole,
        taskRole: taskImageOptions.taskRole,
        family: taskImageOptions.family,
      });

      // Create log driver if logging is enabled
      const enableLogging = taskImageOptions.enableLogging !== undefined ? taskImageOptions.enableLogging : true;
      const logDriver = taskImageOptions.logDriver !== undefined
                          ? taskImageOptions.logDriver : enableLogging
                            ? this.createAWSLogDriver(this.node.id) : undefined;

      const containerName = taskImageOptions.containerName !== undefined ? taskImageOptions.containerName : 'web';
      const container = this.taskDefinition.addContainer(containerName, {
        image: taskImageOptions.image,
        cpu: props.cpu,
        memoryLimitMiB: props.memoryLimitMiB,
github nathanpeck / greeter-cdk / index.js View on Github external
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
    });

    const nameService = new ecs.Ec2Service(this, 'name-service', {
      cluster: cluster,
      desiredCount: 2,
      taskDefinition: nameTaskDefinition
    });