CDK Constructs for AWS ECS
Project description
CDK Construct library for higher-level ECS Constructs
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 Amazon ECS constructs which follow common architectural patterns. It contains:
- Application Load Balanced Services
- Network Load Balanced Services
- Queue Processing Services
- Scheduled Tasks (cron jobs)
Application Load Balanced Services
To define an Amazon ECS service that is behind an application load balancer, instantiate one of the following:
ApplicationLoadBalancedEc2Service
const loadBalancedEcsService = new ecsPatterns.ApplicationLoadBalancedEc2Service(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"
}
});
ApplicationLoadBalancedFargateService
const loadBalancedFargateService = new ecsPatterns.ApplicationLoadBalancedFargateService(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 one 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.
Network Load Balanced Services
To define an Amazon ECS service that is behind a network load balancer, instantiate one of the following:
NetworkLoadBalancedEc2Service
const loadBalancedEcsService = new ecsPatterns.NetworkLoadBalancedEc2Service(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"
}
});
NetworkLoadBalancedFargateService
const loadBalancedFargateService = new ecsPatterns.NetworkLoadBalancedFargateService(stack, 'Service', {
cluster,
memoryLimitMiB: 1024,
cpu: 512,
image: ecs.ContainerImage.fromRegistry("amazon/amazon-ecs-sample"),
});
The CDK will create a new Amazon ECS cluster if you specify a VPC and omit cluster
. If you deploy multiple services the CDK will only create one cluster per VPC.
If cluster
and vpc
are omitted, the CDK creates a new VPC with subnets in two Availability Zones and a cluster within 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
Built Distribution
Hashes for aws-cdk.aws-ecs-patterns-1.11.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0cce92f5d19febb528436f39472ce1d957a9a23a6b255f5632d804bf6fb95d44 |
|
MD5 | b01a9ed95d20ffcd37526c69d0b93c22 |
|
BLAKE2b-256 | b643329adc24f7e379818c9cf3ffb1bd6ae27f71b380030b57d3a09893b6201e |
Hashes for aws_cdk.aws_ecs_patterns-1.11.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 29389723d8c150a2a8606e328d9eb7aad7ca353331233498d2f7e6dc0d7967c0 |
|
MD5 | 69f0176881ac6ab1f3dfec58e719f315 |
|
BLAKE2b-256 | 24bb50e99056ba84a7f9668ddb78e0a15d227b9bc712b6ad9fb22fcc9920ec14 |