Skip to content

Commit

Permalink
chore(ecs-patterns): Add examples to README (aws#5079)
Browse files Browse the repository at this point in the history
  • Loading branch information
piradeepk authored and mergify[bot] committed Nov 18, 2019
1 parent 7a3a3b1 commit d68e836
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions packages/@aws-cdk/aws-ecs-patterns/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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,
});
```

0 comments on commit d68e836

Please sign in to comment.