All files / src/aws target.ts

100% Statements 16/16
50% Branches 1/2
100% Functions 2/2
100% Lines 16/16
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 2x                               2x          
import Resource from './resource'
 
export default class Target extends Resource {
  private readonly type = 'AWS::ApplicationAutoScaling::ScalableTarget'
 
  constructor (
    options: Options,
    private read: boolean,
    private min: number,
    private max: number
  ) { super(options) }
 
  public toJSON(): any {
    consEt resource = [ 'table/', { Ref: this.options.table } ]
 
    if (this.options.index !== '') {
      resource.push('/index/', this.options.index)
    }
 
    const nameTarget = this.name.target(this.read)
    const nameRole = this.name.role()
    const nameDimension = this.name.dimension(this.read)
 
    const DependsOn = [ this.options.table, nameRole ].concat(this.dependencies)
 
    return {
      [nameTarget]: {
        DependsOn,
        Properties: {
          MaxCapacity: this.max,
          MinCapacity: this.min,
          ResourceId: { 'Fn::Join': [ '', resource ] },
          RoleARN: { 'Fn::GetAtt': [ nameRole, 'Arn' ] },
          ScalableDimension: nameDimension,
          ServiceNamespace: 'dynamodb'
        },
        Type: this.type
      }
    }
  }
}