Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import * as appscaling from '@aws-cdk/aws-applicationautoscaling';
import { UtilizationScalingProps } from './scalable-attribute-api';
/**
* A scalable table attribute
*/
export class ScalableTableAttribute extends appscaling.BaseScalableAttribute {
/**
* Scale out or in based on time
*/
public scaleOnSchedule(id: string, action: appscaling.ScalingSchedule) {
super.doScaleOnSchedule(id, action);
}
/**
* Scale out or in to keep utilization at a given level
*/
public scaleOnUtilization(props: UtilizationScalingProps) {
if (props.targetUtilizationPercent < 10 || props.targetUtilizationPercent > 90) {
// tslint:disable-next-line:max-line-length
throw new RangeError(`targetUtilizationPercent for DynamoDB scaling must be between 10 and 90 percent, got: ${props.targetUtilizationPercent}`);
}
const predefinedMetric = this.props.dimension.indexOf('ReadCapacity') === -1
import * as cloudwatch from '@aws-cdk/aws-cloudwatch';
import * as elbv2 from '@aws-cdk/aws-elasticloadbalancingv2';
import { Construct } from '@aws-cdk/core';
/**
* The properties of a scalable attribute representing task count.
*/
// tslint:disable-next-line:no-empty-interface
export interface ScalableTaskCountProps extends appscaling.BaseScalableAttributeProps {
}
/**
* The scalable attribute representing task count.
*/
export class ScalableTaskCount extends appscaling.BaseScalableAttribute {
/**
* Constructs a new instance of the ScalableTaskCount class.
*/
constructor(scope: Construct, id: string, props: ScalableTaskCountProps) {
super(scope, id, props);
}
/**
* Scales in or out based on a specified scheduled time.
*/
public scaleOnSchedule(id: string, props: appscaling.ScalingSchedule) {
return super.doScaleOnSchedule(id, props);
}
/**
public scaleOnUtilization(props: UtilizationScalingProps) {
if (props.targetUtilizationPercent < 10 || props.targetUtilizationPercent > 90) {
// tslint:disable-next-line:max-line-length
throw new RangeError(`targetUtilizationPercent for DynamoDB scaling must be between 10 and 90 percent, got: ${props.targetUtilizationPercent}`);
}
const predefinedMetric = this.props.dimension.indexOf('ReadCapacity') === -1
? appscaling.PredefinedMetric.DYANMODB_WRITE_CAPACITY_UTILIZATION
: appscaling.PredefinedMetric.DYNAMODB_READ_CAPACITY_UTILIZATION;
super.doScaleToTrackMetric('Tracking', {
policyName: props.policyName,
disableScaleIn: props.disableScaleIn,
scaleInCooldown: props.scaleInCooldown,
scaleOutCooldown: props.scaleOutCooldown,
targetValue: props.targetUtilizationPercent,
predefinedMetric,
});
}
}
public scaleOnCpuUtilization(id: string, props: CpuUtilizationScalingProps) {
return super.doScaleToTrackMetric(id, {
predefinedMetric: appscaling.PredefinedMetric.ECS_SERVICE_AVERAGE_CPU_UTILIZATION,
policyName: props.policyName,
disableScaleIn: props.disableScaleIn,
targetValue: props.targetUtilizationPercent,
scaleInCooldown: props.scaleInCooldown,
scaleOutCooldown: props.scaleOutCooldown
});
}