All files / src/aws policy.ts

100% Statements 14/14
100% Branches 0/0
100% Functions 2/2
100% Lines 14/14
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42  2x 2x     2x 2x 2x 2x 2x 2x     2x 2x 2x 2x 2x                                         2x      
import Resource from './resource'
 
export default class Policy extends Resource {
  private readonly type: string = 'AWS::ApplicationAutoScaling::ScalingPolicy'
 
  constructor (
    options: Options,
    private read: boolean,
    private value: number,
    private scaleIn: number,
    private scaleOut: number
  ) { super(options) }
 
  public toJSON(): any {
    const PredefinedMetricType = this.name.metric(this.read)
    const PolicyName = this.name.policyScale(this.read)
    const Target = this.name.target(this.read)
 
    const DependsOn = [ this.options.table, Target ].concat(this.dependencies)
 
    return {
      [PolicyName]: {
        DependsOn,
        Properties: {
          PolicyName,
          PolicyType: 'TargetTrackingScaling',
          ScalingTargetId: { Ref: Target },
          TargetTrackingScalingPolicyConfiguration: {
            PredefinedMetricSpecification: {
              PredefinedMetricType
            },
            ScaleInCooldown: this.scaleIn,
            ScaleOutCooldown: this.scaleOut,
            TargetValue: this.value
          }
        },
        Type: this.type
      }
    }
  }
}