A reusable AWS CDK module for deploying an ECS Service with advanced deployment and load balancing options.
- Deploys an ECS Service using CloudFormation via AWS CDK
- Supports custom deployment configuration and circuit breaker
- Integrates with existing ECS Cluster and Target Group via CloudFormation exports
- Outputs ECS Service Name, ARN, and ID
pip install ecs_service
- Python 3.8+
- AWS CDK v2
- Install dependencies:
pip install aws-cdk-lib constructs pytest
from aws_cdk import App, Stack
from ecs_service.ecs_service_stack import ECSServiceStack
app = App()
stack = Stack(app, "MyStack")
ECSServiceStack(
scope=stack,
id="ECSService",
ecs_stack_name="MyStack",
desired_count=2,
task_definition_arn="arn:aws:ecs:region:account-id:task-definition/my-task-def",
health_check_grace_period_seconds=60,
container_port=80,
target_group_arn="arn:aws:elasticloadbalancing:region:account-id:targetgroup/my-tg/1234567890abcdef",
containername="my-container",
maximum_percent=200,
minimum_healthy_percent=100
)
Unit tests are provided using pytest
and aws_cdk.assertions
.
To run tests:
pytest
Logical IDs generated by AWS CDK are random and may change between synths. Use resource outputs and exports for stable references.
src/
ecs_service/
ecs_service_stack.py
tests/
test_ecs_service.py
README.md