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:
- Load Balanced Services
- Queue Processing Services
- Scheduled Tasks (cron jobs)
Load Balanced Services
To define an Amazon ECS 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"),
});
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.6.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4392d805ef44aaa11e26712ffcf79e081e792a643d391909ded8cc98f5c2890e |
|
MD5 | 2aa6386cb743d67e782e61175f2d97bc |
|
BLAKE2b-256 | fc7aafc34e31e13e9c5e38779b285b6d984107861cc4c074e8afda72914d5caf |
Hashes for aws_cdk.aws_ecs_patterns-1.6.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e5823b3a1e8522d963b5f70fffd237602292f857543730195500c7bcb0ffb6a0 |
|
MD5 | c136e42e23103e8ed028650ddca586fa |
|
BLAKE2b-256 | 86d517553b077bfc25c6650afd50c5bdb94612ddd0df88d0d7085ad7189fb18e |