import * as ecs from '@aws-cdk/aws-ecs' ; import * as cdk from '@aws-cdk/core' ; import { ServiceExtension , ServiceBuild } from './extension-interfaces' ; deprecated export interface CpuScalingProps { default readonly initialTaskCount ? : number ; default readonly minTaskCount ? : number ; default readonly maxTaskCount ? : number ; default readonly targetCpuUtilization ? : number ; default readonly scaleOutCooldown ? : cdk . Duration ; default readonly scaleInCooldown ? : cdk . Duration ; } const cpuScalingPropsDefault = { initialTaskCount : 2 , minTaskCount : 2 , maxTaskCount : 8 , targetCpuUtilization : 50 , scaleOutCooldown : cdk . Duration . seconds ( 60 ) , scaleInCooldown : cdk . Duration . seconds ( 60 ) , } ; deprecated export class ScaleOnCpuUtilization extends ServiceExtension { /**
     * How many tasks to launch initially.
     */ public readonly initialTaskCount : number ; /**
     * The minimum number of tasks when scaling in.
     */ public readonly minTaskCount : number ; /**
     * The maximum number of tasks when scaling out.
     */ public readonly maxTaskCount : number ; /**
     * The CPU utilization to try ot maintain.
     */ public readonly targetCpuUtilization : number ; /**
     * How long to wait between scale out actions.
     */ public readonly scaleOutCooldown : cdk . Duration ; /**
     * How long to wait between scale in actions.
     */ public readonly scaleInCooldown : cdk . Duration ; constructor ( props ? ) { super ( 'scale-on-cpu-utilization' ) ; let combinedProps = { ... cpuScalingPropsDefault , ... props , } ; this . initialTaskCount = combinedProps . initialTaskCount ; this . minTaskCount = combinedProps . minTaskCount ; this . maxTaskCount = combinedProps . maxTaskCount ; this . targetCpuUtilization = combinedProps . targetCpuUtilization ; this . scaleOutCooldown = combinedProps . scaleOutCooldown ; this . scaleInCooldown = combinedProps . scaleInCooldown ; } public modifyServiceProps ( props ) { return { ... props , desiredCount : this . initialTaskCount , } as ServiceBuild ; } public useService ( service ) { if ( this . parentService . scalableTaskCount ) { throw Error ( 'Cannot specify \'autoScaleTaskCount\' in the Service construct and also provide a  \'ScaleOnCpuUtilization\' extension. \'ScaleOnCpuUtilization\' is deprecated. Please only provide \'autoScaleTaskCount\'.' ) ; } const scalingTarget = service . autoScaleTaskCount ( { minCapacity : this . minTaskCount , maxCapacity : this . maxTaskCount , } ) ; scalingTarget . scaleOnCpuUtilization ( `${ this . parentService . id }-target-cpu-utilization-${ this . targetCpuUtilization }` , { targetUtilizationPercent : this . targetCpuUtilization , scaleInCooldown : this . scaleInCooldown , scaleOutCooldown : this . scaleOutCooldown , } ) ; this . parentService . enableAutoScalingPolicy ( ) ; } }