Skip to main content

CDK Constructs for AWS ECS

Project description

CDK Construct library for higher-level ECS Constructs


Stability: Experimental

This is a developer preview (public beta) module. Releases might lack important features and might have future breaking changes.

This API is still under active development and subject to non-backward compatible changes or removal in any future version. Use of the API is not recommended in production environments. Experimental APIs are not subject to the Semantic Versioning model.


This library provides higher-level ECS constructs which follow common architectural patterns. It contains:

  • Load Balanced Services
  • Queue Processing Services
  • Scheduled Tasks (cron jobs)

Load Balanced Services

To define a service that is behind a load balancer, instantiate one of the following:

  • LoadBalancedEc2Service
const loadBalancedEcsService = new ecsPatterns.LoadBalancedEc2Service(stack, 'Service', {
  cluster,
  memoryLimitMiB: 1024,
  image: ecs.ContainerImage.fromRegistry('test'),
  desiredCount: 2,
  environment: {
    TEST_ENVIRONMENT_VARIABLE1: "test environment variable 1 value",
    TEST_ENVIRONMENT_VARIABLE2: "test environment variable 2 value"
  }
});
  • LoadBalancedFargateService
const loadBalancedFargateService = new ecsPatterns.LoadBalancedFargateService(stack, 'Service', {
  cluster,
  memoryLimitMiB: 1024,
  cpu: 512,
  image: ecs.ContainerImage.fromRegistry("amazon/amazon-ecs-sample"),
});

Instead of providing a cluster you can specify a VPC and CDK will create a new ECS cluster. If you deploy multiple services CDK will only create on cluster per VPC.

You can omit cluster and vpc to let CDK create a new VPC with two AZs and create a cluster inside this VPC.

Queue Processing Services

To define a service that creates a queue and reads from that queue, instantiate one of the following:

  • QueueProcessingEc2Service
const queueProcessingEc2Service = new QueueProcessingEc2Service(stack, 'Service', {
  cluster,
  memoryLimitMiB: 1024,
  image: ecs.ContainerImage.fromRegistry('test'),
  command: ["-c", "4", "amazon.com"],
  enableLogging: false,
  desiredTaskCount: 2,
  environment: {
    TEST_ENVIRONMENT_VARIABLE1: "test environment variable 1 value",
    TEST_ENVIRONMENT_VARIABLE2: "test environment variable 2 value"
  },
  queue,
  maxScalingCapacity: 5
});
  • QueueProcessingFargateService
const queueProcessingFargateService = new QueueProcessingFargateService(stack, 'Service', {
  cluster,
  memoryLimitMiB: 512,
  image: ecs.ContainerImage.fromRegistry('test'),
  command: ["-c", "4", "amazon.com"],
  enableLogging: false,
  desiredTaskCount: 2,
  environment: {
    TEST_ENVIRONMENT_VARIABLE1: "test environment variable 1 value",
    TEST_ENVIRONMENT_VARIABLE2: "test environment variable 2 value"
  },
  queue,
  maxScalingCapacity: 5
});

Scheduled Tasks

To define a task that runs periodically, instantiate an ScheduledEc2Task:

// Instantiate an Amazon EC2 Task to run at a scheduled interval
const ecsScheduledTask = new ScheduledEc2Task(this, 'ScheduledTask', {
  cluster,
  image: ecs.ContainerImage.fromRegistry("amazon/amazon-ecs-sample"),
  scheduleExpression: 'rate(1 minute)',
  environment: [{ name: 'TRIGGER', value: 'CloudWatch Events' }],
  memoryLimitMiB: 256
});

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aws-cdk.aws-ecs-patterns-1.5.0.tar.gz (105.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aws_cdk.aws_ecs_patterns-1.5.0-py3-none-any.whl (102.2 kB view details)

Uploaded Python 3

File details

Details for the file aws-cdk.aws-ecs-patterns-1.5.0.tar.gz.

File metadata

  • Download URL: aws-cdk.aws-ecs-patterns-1.5.0.tar.gz
  • Upload date:
  • Size: 105.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.34.0 CPython/3.6.5

File hashes

Hashes for aws-cdk.aws-ecs-patterns-1.5.0.tar.gz
Algorithm Hash digest
SHA256 5297e39635d7cc0cdb18e73e5867096de95bbe7ceaf25ae81710b155f5b0ff3e
MD5 8f4ea847e90aef71c17033d3e71de2d8
BLAKE2b-256 848bbd08f520fdc0a9afa254efa1d53b4aac374c5a3c0a5e1cdd7a4edd6d082c

See more details on using hashes here.

File details

Details for the file aws_cdk.aws_ecs_patterns-1.5.0-py3-none-any.whl.

File metadata

  • Download URL: aws_cdk.aws_ecs_patterns-1.5.0-py3-none-any.whl
  • Upload date:
  • Size: 102.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.34.0 CPython/3.6.5

File hashes

Hashes for aws_cdk.aws_ecs_patterns-1.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f1e01e55e0f79492b0a499f2cb180f88ecfad831b574fff8dea8f0a868f1b246
MD5 9d61f3fd74707ca0d2f3e68c8fd8c4d0
BLAKE2b-256 229604548f7019ef30f5fae86eb991067473131d76e4ee31f5d4cf0e138f749e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page