From d68e83691eb5c1b8cf7200ebab4cb2fcc061ac7d Mon Sep 17 00:00:00 2001 From: Piradeep Kandasamy Date: Mon, 18 Nov 2019 11:52:27 -0800 Subject: [PATCH] chore(ecs-patterns): Add examples to README (#5079) --- packages/@aws-cdk/aws-ecs-patterns/README.md | 37 ++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/packages/@aws-cdk/aws-ecs-patterns/README.md b/packages/@aws-cdk/aws-ecs-patterns/README.md index c7fa1ee1063e9..0c43db0ba0550 100644 --- a/packages/@aws-cdk/aws-ecs-patterns/README.md +++ b/packages/@aws-cdk/aws-ecs-patterns/README.md @@ -15,6 +15,7 @@ This library provides higher-level Amazon ECS constructs which follow common arc * Network Load Balanced Services * Queue Processing Services * Scheduled Tasks (cron jobs) +* Additional Examples ## Application Load Balanced Services @@ -151,3 +152,39 @@ const ecsScheduledTask = new ScheduledEc2Task(stack, 'ScheduledTask', { schedule: events.Schedule.expression('rate(1 minute)') }); ``` + +## Additional Examples + +In addition to using the constructs, users can also add logic to customize these constructs: + +### Add Schedule-Based Auto-Scaling to an ApplicationLoadBalancedFargateService + +```ts +import { Schedule } from '@aws-cdk/aws-applicationautoscaling'; +import { ApplicationLoadBalancedFargateService, ApplicationLoadBalancedFargateServiceProps } from './application-load-balanced-fargate-service'; + +const loadBalancedFargateService = new ApplicationLoadBalancedFargateService(stack, 'Service', { + cluster, + memoryLimitMiB: 1024, + desiredCount: 1, + cpu: 512, + taskImageOptions: { + image: ecs.ContainerImage.fromRegistry("amazon/amazon-ecs-sample"), + }, +}); + +const scalableTarget = loadBalancedFargateService.service.autoScaleTaskCount({ + minCapacity: 5, + maxCapacity: 20, +}); + +scalableTarget.scaleOnSchedule('DaytimeScaleDown', { + schedule: Schedule.cron({ hour: '8', minute: '0'}), + minCapacity: 1, +}); + +scalableTarget.scaleOnSchedule('EveningRushScaleUp', { + schedule: Schedule.cron({ hour: '20', minute: '0'}), + minCapacity: 10, +}); +``` \ No newline at end of file