ScalableTaskCount
The scalable attribute representing task count.
Example
declare const cluster: ecs.Cluster;
const loadBalancedFargateService = new ecsPatterns.ApplicationLoadBalancedFargateService(this, 'Service', {
cluster,
memoryLimitMiB: 1024,
desiredCount: 1,
cpu: 512,
taskImageOptions: {
image: ecs.ContainerImage.fromRegistry("amazon/amazon-ecs-sample"),
},
minHealthyPercent: 100,
});
const scalableTarget = loadBalancedFargateService.service.autoScaleTaskCount({
minCapacity: 1,
maxCapacity: 20,
});
scalableTarget.scaleOnCpuUtilization('CpuScaling', {
targetUtilizationPercent: 50,
});
scalableTarget.scaleOnMemoryUtilization('MemoryScaling', {
targetUtilizationPercent: 50,
});
# cluster: ecs.Cluster
load_balanced_fargate_service = ecs_patterns.ApplicationLoadBalancedFargateService(self, "Service",
cluster=cluster,
memory_limit_mi_b=1024,
desired_count=1,
cpu=512,
task_image_options=ecsPatterns.ApplicationLoadBalancedTaskImageOptions(
image=ecs.ContainerImage.from_registry("amazon/amazon-ecs-sample")
),
min_healthy_percent=100
)
scalable_target = load_balanced_fargate_service.service.auto_scale_task_count(
min_capacity=1,
max_capacity=20
)
scalable_target.scale_on_cpu_utilization("CpuScaling",
target_utilization_percent=50
)
scalable_target.scale_on_memory_utilization("MemoryScaling",
target_utilization_percent=50
)
Cluster cluster;
ApplicationLoadBalancedFargateService loadBalancedFargateService = ApplicationLoadBalancedFargateService.Builder.create(this, "Service")
.cluster(cluster)
.memoryLimitMiB(1024)
.desiredCount(1)
.cpu(512)
.taskImageOptions(ApplicationLoadBalancedTaskImageOptions.builder()
.image(ContainerImage.fromRegistry("amazon/amazon-ecs-sample"))
.build())
.minHealthyPercent(100)
.build();
ScalableTaskCount scalableTarget = loadBalancedFargateService.service.autoScaleTaskCount(EnableScalingProps.builder()
.minCapacity(1)
.maxCapacity(20)
.build());
scalableTarget.scaleOnCpuUtilization("CpuScaling", CpuUtilizationScalingProps.builder()
.targetUtilizationPercent(50)
.build());
scalableTarget.scaleOnMemoryUtilization("MemoryScaling", MemoryUtilizationScalingProps.builder()
.targetUtilizationPercent(50)
.build());
// Install: dotnet add package Amazon.CDK.Lib
Cluster cluster;
var loadBalancedFargateService = new ApplicationLoadBalancedFargateService(this, "Service", new ApplicationLoadBalancedFargateServiceProps {
Cluster = cluster,
MemoryLimitMiB = 1024,
DesiredCount = 1,
Cpu = 512,
TaskImageOptions = new ApplicationLoadBalancedTaskImageOptions {
Image = ContainerImage.FromRegistry("amazon/amazon-ecs-sample")
},
MinHealthyPercent = 100
});
var scalableTarget = loadBalancedFargateService.Service.AutoScaleTaskCount(new EnableScalingProps {
MinCapacity = 1,
MaxCapacity = 20
});
scalableTarget.ScaleOnCpuUtilization("CpuScaling", new CpuUtilizationScalingProps {
TargetUtilizationPercent = 50
});
scalableTarget.ScaleOnMemoryUtilization("MemoryScaling", new MemoryUtilizationScalingProps {
TargetUtilizationPercent = 50
});
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var cluster Cluster
loadBalancedFargateService := ecsPatterns.NewApplicationLoadBalancedFargateService(this, jsii.String("Service"), &ApplicationLoadBalancedFargateServiceProps{
Cluster: Cluster,
MemoryLimitMiB: jsii.Number(1024),
DesiredCount: jsii.Number(1),
Cpu: jsii.Number(512),
TaskImageOptions: &ApplicationLoadBalancedTaskImageOptions{
Image: ecs.ContainerImage_FromRegistry(jsii.String("amazon/amazon-ecs-sample")),
},
MinHealthyPercent: jsii.Number(100),
})
scalableTarget := loadBalancedFargateService.Service.AutoScaleTaskCount(&EnableScalingProps{
MinCapacity: jsii.Number(1),
MaxCapacity: jsii.Number(20),
})
scalableTarget.ScaleOnCpuUtilization(jsii.String("CpuScaling"), &CpuUtilizationScalingProps{
TargetUtilizationPercent: jsii.Number(50),
})
scalableTarget.ScaleOnMemoryUtilization(jsii.String("MemoryScaling"), &MemoryUtilizationScalingProps{
TargetUtilizationPercent: jsii.Number(50),
})
Initializer
new ScalableTaskCount(scope: Construct, id: string, props: ScalableTaskCountProps)
ScalableTaskCount(scope: Construct, id: str, props: ScalableTaskCountProps)
new ScalableTaskCount(Construct scope, String id, ScalableTaskCountProps props)
new ScalableTaskCount(Construct scope, string id, ScalableTaskCountProps props)
NewScalableTaskCount(Scope Construct, Id *string, Props ScalableTaskCountProps)
Construct Props
maxCapacitynumbermax_capacityint | floatmaxCapacityNumberMaxCapacitydoubleMaxCapacity*float64required#minCapacityoptionalnumbermin_capacityoptionalint | floatminCapacityoptionalNumberMinCapacityoptionaldoubleMinCapacityoptional*float64= 1#serviceNamespaceServiceNamespaceservice_namespaceServiceNamespaceserviceNamespaceServiceNamespaceServiceNamespaceServiceNamespaceServiceNamespaceServiceNamespacerequired#Properties
envResourceEnvironmentenvResourceEnvironmentenvResourceEnvironmentEnvResourceEnvironmentEnvResourceEnvironmentrequired#notes
For resources that are created and managed in a Stack (those created by creating new class instances like new Role(), new Bucket(), etc.), this is always the same as the environment of the stack they belong to.
For referenced resources (those obtained from referencing methods like Role.fromRoleArn(), Bucket.fromBucketName(), etc.), they might be different than the stack they were imported into.
scalableTargetRefScalableTargetReferencescalable_target_refScalableTargetReferencescalableTargetRefScalableTargetReferenceScalableTargetRefScalableTargetReferenceScalableTargetRefScalableTargetReferencerequired#Methods
isConstruct(x: any): boolean@staticmethod def is_construct(x: Any) -> boolpublic static Boolean isConstruct(Object x)public static bool IsConstruct(object x)func IsConstruct(X interface{}) *boolstatic#notes · 1 parameter · returns
Use this method instead of instanceof to properly detect Construct instances, even when the construct library is symlinked.
Explanation: in JavaScript, multiple copies of the constructs library on disk are seen as independent, completely different libraries. As a consequence, the class Construct in each copy of the constructs library is seen as a different class, and an instance of one class will not test as instanceof the other class. npm install will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of the constructs library can be accidentally installed, and instanceof will behave unpredictably. It is safest to avoid using instanceof, and using this type-testing method instead.
Parameters
xxxxX— Any object.
Returns: true if x is an object created from a class which extends Construct.
scaleOnCpuUtilization(id: string, props: CpuUtilizationScalingProps): voiddef scale_on_cpu_utilization(self, id: str, props: CpuUtilizationScalingProps) -> Nonepublic void scaleOnCpuUtilization(String id, CpuUtilizationScalingProps props)public void ScaleOnCpuUtilization(string id, CpuUtilizationScalingProps props)func ScaleOnCpuUtilization(Id *string, Props CpuUtilizationScalingProps)#scaleOnMemoryUtilization(id: string, props: MemoryUtilizationScalingProps): voiddef scale_on_memory_utilization(self, id: str, props: MemoryUtilizationScalingProps) -> Nonepublic void scaleOnMemoryUtilization(String id, MemoryUtilizationScalingProps props)public void ScaleOnMemoryUtilization(string id, MemoryUtilizationScalingProps props)func ScaleOnMemoryUtilization(Id *string, Props MemoryUtilizationScalingProps)#scaleOnMetric(id: string, props: BasicStepScalingPolicyProps): voiddef scale_on_metric(self, id: str, props: BasicStepScalingPolicyProps) -> Nonepublic void scaleOnMetric(String id, BasicStepScalingPolicyProps props)public void ScaleOnMetric(string id, BasicStepScalingPolicyProps props)func ScaleOnMetric(Id *string, Props BasicStepScalingPolicyProps)#scaleOnRequestCount(id: string, props: RequestCountScalingProps): voiddef scale_on_request_count(self, id: str, props: RequestCountScalingProps) -> Nonepublic void scaleOnRequestCount(String id, RequestCountScalingProps props)public void ScaleOnRequestCount(string id, RequestCountScalingProps props)func ScaleOnRequestCount(Id *string, Props RequestCountScalingProps)#scaleOnSchedule(id: string, props: ScalingSchedule): voiddef scale_on_schedule(self, id: str, props: ScalingSchedule) -> Nonepublic void scaleOnSchedule(String id, ScalingSchedule props)public void ScaleOnSchedule(string id, ScalingSchedule props)func ScaleOnSchedule(Id *string, Props ScalingSchedule)#scaleToTrackCustomMetric(id: string, props: TrackCustomMetricProps): voiddef scale_to_track_custom_metric(self, id: str, props: TrackCustomMetricProps) -> Nonepublic void scaleToTrackCustomMetric(String id, TrackCustomMetricProps props)public void ScaleToTrackCustomMetric(string id, TrackCustomMetricProps props)func ScaleToTrackCustomMetric(Id *string, Props TrackCustomMetricProps)#toString(): stringdef to_string(self, ) -> strpublic String toString()public string ToString()func ToString() *string#with(...mixins: IMixin[]): IConstructdef with(self, mixins: IMixin) -> IConstructpublic IConstruct with(IMixin mixins)public IConstruct With(IMixin mixins)func With(Mixins IMixin) IConstruct#Mixins are applied in order. The list of constructs is captured at the start of the call, so constructs added by a mixin will not be visited. Use multiple with() calls if subsequent mixins should apply to added constructs.
1 parameter · returns
Parameters
mixinsmixinsmixinsmixinsMixins— The mixins to apply.
Returns: This construct for chaining