CDK Constructs for AWS ECS
Project description
CDK Construct library for higher-level ECS Constructs
---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
# Example may have issues. See https://github.com/aws/jsii/issues/826
load_balanced_ecs_service = ecs_patterns.ApplicationLoadBalancedEc2Service(stack, "Service",
cluster=cluster,
memory_limit_mi_b=1024,
task_image_options={
"image": ecs.ContainerImage.from_registry("test"),
"environment": {
"TEST_ENVIRONMENT_VARIABLE1": "test environment variable 1 value",
"TEST_ENVIRONMENT_VARIABLE2": "test environment variable 2 value"
}
},
desired_count=2
)
ApplicationLoadBalancedFargateService
# Example may have issues. See https://github.com/aws/jsii/issues/826
load_balanced_fargate_service = ecs_patterns.ApplicationLoadBalancedFargateService(stack, "Service",
cluster=cluster,
memory_limit_mi_b=1024,
cpu=512,
task_image_options={
"image": ecs.ContainerImage.from_registry("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
# Example may have issues. See https://github.com/aws/jsii/issues/826
load_balanced_ecs_service = ecs_patterns.NetworkLoadBalancedEc2Service(stack, "Service",
cluster=cluster,
memory_limit_mi_b=1024,
task_image_options={
"image": ecs.ContainerImage.from_registry("test"),
"environment": {
"TEST_ENVIRONMENT_VARIABLE1": "test environment variable 1 value",
"TEST_ENVIRONMENT_VARIABLE2": "test environment variable 2 value"
}
},
desired_count=2
)
NetworkLoadBalancedFargateService
# Example may have issues. See https://github.com/aws/jsii/issues/826
load_balanced_fargate_service = ecs_patterns.NetworkLoadBalancedFargateService(stack, "Service",
cluster=cluster,
memory_limit_mi_b=1024,
cpu=512,
task_image_options={
"image": ecs.ContainerImage.from_registry("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
# Example may have issues. See https://github.com/aws/jsii/issues/826
queue_processing_ec2_service = QueueProcessingEc2Service(stack, "Service",
cluster=cluster,
memory_limit_mi_b=1024,
image=ecs.ContainerImage.from_registry("test"),
command=["-c", "4", "amazon.com"],
enable_logging=False,
desired_task_count=2,
environment={
"TEST_ENVIRONMENT_VARIABLE1": "test environment variable 1 value",
"TEST_ENVIRONMENT_VARIABLE2": "test environment variable 2 value"
},
queue=queue,
max_scaling_capacity=5
)
QueueProcessingFargateService
# Example may have issues. See https://github.com/aws/jsii/issues/826
queue_processing_fargate_service = QueueProcessingFargateService(stack, "Service",
cluster=cluster,
memory_limit_mi_b=512,
image=ecs.ContainerImage.from_registry("test"),
command=["-c", "4", "amazon.com"],
enable_logging=False,
desired_task_count=2,
environment={
"TEST_ENVIRONMENT_VARIABLE1": "test environment variable 1 value",
"TEST_ENVIRONMENT_VARIABLE2": "test environment variable 2 value"
},
queue=queue,
max_scaling_capacity=5
)
Scheduled Tasks
To define a task that runs periodically, instantiate an ScheduledEc2Task
:
# Example may have issues. See https://github.com/aws/jsii/issues/826
# Instantiate an Amazon EC2 Task to run at a scheduled interval
ecs_scheduled_task = ScheduledEc2Task(stack, "ScheduledTask",
cluster=cluster,
scheduled_ec2_task_image_options={
"image": ecs.ContainerImage.from_registry("amazon/amazon-ecs-sample"),
"memory_limit_mi_b": 256,
"environment": {"name": "TRIGGER", "value": "CloudWatch Events"}
},
schedule=events.Schedule.expression("rate(1 minute)")
)
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.16.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | ded54c4d320686af07efc979bdb941a2d70efc0f23e6c315e638a764213282d7 |
|
MD5 | ba71a9c5e3a4e0794da9f28b9496b68e |
|
BLAKE2b-256 | f116cb0d14732fb3dd29863be6ba84659940e1ce6ee71700287c59e51bb4eef8 |
Hashes for aws_cdk.aws_ecs_patterns-1.16.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0569dda7544be2e7378d18fcb82888345e8c01c9b3594edb2dd2b27981369881 |
|
MD5 | 0b94151dfc58f3ef5776ccd20f5211c5 |
|
BLAKE2b-256 | cde30be1c4d606f00d6d8d21cddd5d3b2b045aab0208e69db2b128cc9d9bc316 |