How to use the @aws-cdk/aws-ecs.ContainerImage 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 nathanpeck / greeter-cdk / index.js View on Github external
// 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
    });

    // Greeting service
    const greetingTaskDefinition = new ecs.Ec2TaskDefinition(this, 'greeting-task-definition', {});
github aws-samples / aws-cdk-changelogs-demo / changelogs-md.js View on Github external
constructor(parent, id, props) {
    super(parent, id, props);

    const broadcast = new ecsPatterns.LoadBalancedFargateService(this, 'Broadcast', {
      image: ecs.ContainerImage.fromAsset('./app/socket-broadcast'),
      publicTasks: true,
      cluster: props.cluster,
      cpu: 256,
      memoryLimitMiB: 512,
      desiredCount: 1,
      environment: {
        REDIS_HOST: props.redis.cluster.attrRedisEndpointAddress,
        REDIS_PORT: props.redis.cluster.attrRedisEndpointPort
      },
      createLogs: true
    });

    // Grant the broadcast service networking access to Redis
    broadcast.service.connections.allowToDefaultPort(props.redis);

    this.dnsName = broadcast.loadBalancer.loadBalancerDnsName;
github nathanpeck / screenshot-service / app.3.js View on Github external
constructor(parent, id, props) {
    super(parent, id, props);

    // Create an API service
    this.api = new ecs.LoadBalancedFargateService(this, 'api', {
      cluster: props.cluster,
      image: ecs.ContainerImage.fromAsset(this, 'api-image', {
        directory: './api'
      }),
      desiredCount: 2,
      cpu: '256',
      memory: '512',
      environment: {
        QUEUE_URL: props.screenshotQueue.queueUrl,
        TABLE: props.screenshotTable.tableName
      },
      createLogs: true
    });

    props.screenshotQueue.grantSendMessages(this.api.service.taskDefinition.taskRole);
    props.screenshotTable.grantReadWriteData(this.api.service.taskDefinition.taskRole);
  }
}
github nathanpeck / greeter-cdk / index.js View on Github external
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,
      desiredCount: 2,
      taskDefinition: greeterTaskDefinition
    });
github duo-labs / cloudmapper / auditor / lib / cloudmapperauditor-stack.js View on Github external
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
    taskDefinition.addToTaskRolePolicy(new iam.PolicyStatement({
      resources: ["arn:aws:iam::*:role/"+config['iam_role']],
      actions: ['sts:AssumeRole']
github humank / EventStormingWorkShop / deployment / coffeeshop-cdk / lib / coffee-shop-code-pipeline.ts View on Github external
const cluster = new ecs.Cluster(this, 'Cluster', {
            clusterName: 'coffeeshop',
            vpc
        });



        const taskDefinition = new ecs.TaskDefinition(this, 'orders-web-Task', {
            compatibility: ecs.Compatibility.FARGATE,
            memoryMiB: '512',
            cpu: '256',
        });

        taskDefinition.addContainer('defaultContainer', {
            image: ecs.ContainerImage.fromRegistry('amazon/amazon-ecs-sample'),
            logging: new ecs.AwsLogDriver({
                streamPrefix: 'coffeeshop',
            })
        }).addPortMappings({
            containerPort: 8080
        });

        const fargatesvc = new ecsPatterns.ApplicationLoadBalancedFargateService(this, 'AlbSvc', {
            cluster,
            taskDefinition,
        })

        const fargateTaskRole = fargatesvc.service.taskDefinition.taskRole;
        fargateTaskRole.addToPolicy(new iam.PolicyStatement({
            resources: ['*'],
            actions: ['events:*']