How to use the @aws-cdk/aws-ecs.FargateTaskDefinition 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-samples / aws-cdk-changelogs-demo / changelogs-md.js View on Github external
super(parent, id, props);

    // Prior to building the image copy the package.json and libs into
    // the build context since Docker can't reference files outside of the
    // build context.
    copydir.sync('./app/lib', './app/npm-follower/lib');
    copydir.sync('./app', './app/npm-follower', function(stat, filepath, filename) {
      if (stat === 'file' && filename === 'package.json') {
        return true;
      }

      return false;
    });

    // Define the follower application.
    const followerDefinition = new ecs.FargateTaskDefinition(this, 'NpmFollowerDefinition', {});

    followerDefinition.addContainer('npm-follower', {
      image: ecs.ContainerImage.fromAsset('./app/npm-follower'),
      memoryMiB: 512,
      cpu: 256,
      environment: {
        CHANGELOGS_TABLE_NAME: props.changelogsTable.tableName,
        DISCOVERED_TOPIC_NAME: props.toCrawlTopic.topicArn
      },
      logging: new ecs.AwsLogDriver({
        streamPrefix: 'npm-follower'
      })
    });

    // Grant this application access to the DynamoDB table and SNS topic
    props.changelogsTable.grantReadWriteData(followerDefinition.taskRole);
github aws / aws-cdk / packages / @aws-cdk / aws-ecs-patterns / lib / fargate / queue-processing-fargate-service.ts View on Github external
constructor(scope: Construct, id: string, props: QueueProcessingFargateServiceProps) {
    super(scope, id, props);

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

    // Create a Fargate 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 FargateService(this, 'QueueProcessingFargateService', {
      cluster: this.cluster,
      desiredCount: this.desiredCount,
github nathanpeck / screenshot-service / app.3.js View on Github external
constructor(parent, id, props) {
    super(parent, id, props);

    // Create a worker service
    this.workerDefinition = new ecs.FargateTaskDefinition(this, 'worker-definition', {
      cpu: '2048',
      memoryMiB: '4096'
    });

    this.container = this.workerDefinition.addContainer('worker', {
      image: ecs.ContainerImage.fromAsset(this, 'worker-image', {
        directory: './worker'
      }),
      cpu: 2048,
      memoryLimitMiB: 4096,
      environment: {
        QUEUE_URL: props.screenshotQueue.queueUrl,
        TABLE: props.screenshotTable.tableName,
        BUCKET: props.screenshotBucket.bucketName
      },
      logging: new ecs.AwsLogDriver(this, 'worker-logs', {
github aws / aws-cdk / packages / @aws-cdk / aws-ecs-patterns / lib / fargate / network-load-balanced-fargate-service.ts View on Github external
constructor(scope: Construct, id: string, props: NetworkLoadBalancedFargateServiceProps = {}) {
    super(scope, id, props);

    this.assignPublicIp = props.assignPublicIp !== undefined ? props.assignPublicIp : false;

    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 FargateTaskDefinition(this, 'TaskDef', {
        memoryLimitMiB: props.memoryLimitMiB,
        cpu: props.cpu,
        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,
github aws / aws-cdk / packages / @aws-cdk / aws-ecs-patterns / lib / fargate / application-load-balanced-fargate-service.ts View on Github external
constructor(scope: Construct, id: string, props: ApplicationLoadBalancedFargateServiceProps = {}) {
    super(scope, id, props);

    this.assignPublicIp = props.assignPublicIp !== undefined ? props.assignPublicIp : false;

    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 FargateTaskDefinition(this, 'TaskDef', {
        memoryLimitMiB: props.memoryLimitMiB,
        cpu: props.cpu,
        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,
github duo-labs / cloudmapper / auditor / lib / cloudmapperauditor-stack.js View on Github external
// want to spend $30/mo on a NAT gateway.
    const vpc = new ec2.Vpc(this, 'CloudMapperVpc', {
        maxAzs: 1,
        natGateways: 0,
        subnetConfiguration: [
          {
            name: 'Public',
            subnetType: ec2.SubnetType.PUBLIC
          }
        ]
    });

    // Define the ECS task
    const cluster = new ecs.Cluster(this, 'Cluster', { vpc });

    const taskDefinition = new ecs.FargateTaskDefinition(this, 'taskDefinition', {});

    taskDefinition.addContainer('cloudmapper-container', {
      image: ecs.ContainerImage.fromAsset('./resources'),
      memoryLimitMiB: 512,
      cpu: 256,
      environment: {
        S3_BUCKET: config['s3_bucket'],
        MINIMUM_ALERT_SEVERITY: config['minimum_alert_severity']
      },
      logging: new ecs.AwsLogDriver({
        streamPrefix: 'cloudmapper',
        logRetention: logs.RetentionDays.TWO_WEEKS
      })
    });

    // Grant the ability to assume the IAM role in any account
github aws / aws-cdk / packages / @aws-cdk / aws-ecs-patterns / lib / fargate / scheduled-fargate-task.ts View on Github external
constructor(scope: Construct, id: string, props: ScheduledFargateTaskProps) {
    super(scope, id, props);

    this.taskDefinition = new FargateTaskDefinition(this, 'ScheduledTaskDef', {
      memoryLimitMiB: props.memoryLimitMiB || 512,
      cpu: props.cpu || 256,
    });
    this.taskDefinition.addContainer('ScheduledContainer', {
      image: props.image,
      command: props.command,
      environment: props.environment,
      secrets: props.secrets,
      logging: this.logDriver
    });

    this.addTaskDefinitionToEventTarget(this.taskDefinition);
  }
}