ScalableTarget L2 construct
Define a scalable target.
Example
const shardsScalableTarget = new appscaling.ScalableTarget(this, 'ElastiCacheRedisShardsScalableTarget', {
serviceNamespace: appscaling.ServiceNamespace.ELASTICACHE,
scalableDimension: 'elasticache:replication-group:NodeGroups',
minCapacity: 2,
maxCapacity: 10,
resourceId: 'replication-group/main-cluster',
});
shardsScalableTarget.scaleToTrackMetric('ElastiCacheRedisShardsCPUUtilization', {
targetValue: 20,
predefinedMetric: appscaling.PredefinedMetric.ELASTICACHE_PRIMARY_ENGINE_CPU_UTILIZATION,
});
shards_scalable_target = appscaling.ScalableTarget(self, "ElastiCacheRedisShardsScalableTarget",
service_namespace=appscaling.ServiceNamespace.ELASTICACHE,
scalable_dimension="elasticache:replication-group:NodeGroups",
min_capacity=2,
max_capacity=10,
resource_id="replication-group/main-cluster"
)
shards_scalable_target.scale_to_track_metric("ElastiCacheRedisShardsCPUUtilization",
target_value=20,
predefined_metric=appscaling.PredefinedMetric.ELASTICACHE_PRIMARY_ENGINE_CPU_UTILIZATION
)
ScalableTarget shardsScalableTarget = ScalableTarget.Builder.create(this, "ElastiCacheRedisShardsScalableTarget")
.serviceNamespace(ServiceNamespace.ELASTICACHE)
.scalableDimension("elasticache:replication-group:NodeGroups")
.minCapacity(2)
.maxCapacity(10)
.resourceId("replication-group/main-cluster")
.build();
shardsScalableTarget.scaleToTrackMetric("ElastiCacheRedisShardsCPUUtilization", BasicTargetTrackingScalingPolicyProps.builder()
.targetValue(20)
.predefinedMetric(PredefinedMetric.ELASTICACHE_PRIMARY_ENGINE_CPU_UTILIZATION)
.build());
// Install: dotnet add package Amazon.CDK.Lib
var shardsScalableTarget = new ScalableTarget(this, "ElastiCacheRedisShardsScalableTarget", new ScalableTargetProps {
ServiceNamespace = ServiceNamespace.ELASTICACHE,
ScalableDimension = "elasticache:replication-group:NodeGroups",
MinCapacity = 2,
MaxCapacity = 10,
ResourceId = "replication-group/main-cluster"
});
shardsScalableTarget.ScaleToTrackMetric("ElastiCacheRedisShardsCPUUtilization", new BasicTargetTrackingScalingPolicyProps {
TargetValue = 20,
PredefinedMetric = PredefinedMetric.ELASTICACHE_PRIMARY_ENGINE_CPU_UTILIZATION
});
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
shardsScalableTarget := appscaling.NewScalableTarget(this, jsii.String("ElastiCacheRedisShardsScalableTarget"), &ScalableTargetProps{
ServiceNamespace: appscaling.ServiceNamespace_ELASTICACHE,
ScalableDimension: jsii.String("elasticache:replication-group:NodeGroups"),
MinCapacity: jsii.Number(2),
MaxCapacity: jsii.Number(10),
ResourceId: jsii.String("replication-group/main-cluster"),
})
shardsScalableTarget.ScaleToTrackMetric(jsii.String("ElastiCacheRedisShardsCPUUtilization"), &BasicTargetTrackingScalingPolicyProps{
TargetValue: jsii.Number(20),
PredefinedMetric: appscaling.PredefinedMetric_ELASTICACHE_PRIMARY_ENGINE_CPU_UTILIZATION,
})
Initializer
new ScalableTarget(scope: Construct, id: string, props: ScalableTargetProps)
ScalableTarget(scope: Construct, id: str, props: ScalableTargetProps)
new ScalableTarget(Construct scope, String id, ScalableTargetProps props)
new ScalableTarget(Construct scope, string id, ScalableTargetProps props)
NewScalableTarget(Scope Construct, Id *string, Props ScalableTargetProps)
Construct Props
maxCapacitynumbermax_capacityint | floatmaxCapacityNumberMaxCapacitydoubleMaxCapacity*float64required#minCapacitynumbermin_capacityint | floatminCapacityNumberMinCapacitydoubleMinCapacity*float64required#This string consists of the resource type and unique identifier.
Example value: service/ecsStack-MyECSCluster-AB12CDE3F4GH/ecsStack-MyECSService-AB12CDE3F4GH
scalableDimensionstringscalable_dimensionstrscalableDimensionStringScalableDimensionstringScalableDimension*stringrequired#Specify the service namespace, resource type, and scaling property.
Example value: ecs:service:DesiredCount
serviceNamespaceServiceNamespaceservice_namespaceServiceNamespaceserviceNamespaceServiceNamespaceServiceNamespaceServiceNamespaceServiceNamespaceServiceNamespacerequired#For valid AWS service namespace values, see the RegisterScalableTarget action in the Application Auto Scaling API Reference.
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.
PROPERTY_INJECTION_IDstringproperty_injection_idstrPROPERTY_INJECTION_IDStringPROPERTY_INJECTION_IDstringPROPERTY_INJECTION_ID*stringrequiredstatic#scalableTargetIdstringscalable_target_idstrscalableTargetIdStringScalableTargetIdstringScalableTargetId*stringrequired#Example value: service/ecsStack-MyECSCluster-AB12CDE3F4GH/ecsStack-MyECSService-AB12CDE3F4GH|ecs:service:DesiredCount|ecs
scalableTargetRefScalableTargetReferencescalable_target_refScalableTargetReferencescalableTargetRefScalableTargetReferenceScalableTargetRefScalableTargetReferenceScalableTargetRefScalableTargetReferencerequired#Methods
addToRolePolicy(statement: PolicyStatement): voiddef add_to_role_policy(self, statement: PolicyStatement) -> Nonepublic void addToRolePolicy(PolicyStatement statement)public void AddToRolePolicy(PolicyStatement statement)func AddToRolePolicy(Statement PolicyStatement)#applyCrossStackReferenceStrength(strength: ReferenceStrength): voiddef apply_cross_stack_reference_strength(self, strength: ReferenceStrength) -> Nonepublic void applyCrossStackReferenceStrength(ReferenceStrength strength)public void ApplyCrossStackReferenceStrength(ReferenceStrength strength)func ApplyCrossStackReferenceStrength(Strength ReferenceStrength)#notes · 1 parameter
When set, any cross-stack reference to this resource will use the specified mechanism instead of the global default determined by the @aws-cdk/core:defaultCrossStackReferences context key. This is useful for selectively weakening specific references to avoid the "deadly embrace" problem without changing the app-wide default.
Parameters
strengthstrengthstrengthstrengthStrength— - The reference strength to use for this resource.
applyRemovalPolicy(policy: RemovalPolicy): voiddef apply_removal_policy(self, policy: RemovalPolicy) -> Nonepublic void applyRemovalPolicy(RemovalPolicy policy)public void ApplyRemovalPolicy(RemovalPolicy policy)func ApplyRemovalPolicy(Policy RemovalPolicy)#notes
The Removal Policy controls what happens to this resource when it stops being managed by CloudFormation, either because you've removed it from the CDK application or because you've made a change that requires the resource to be replaced.
The resource can be deleted (RemovalPolicy.DESTROY), or left in your AWS account for data recovery and cleanup later (RemovalPolicy.RETAIN).
fromScalableTargetAttributes(scope: Construct, id: string, attrs: ScalableTargetAttributes): IScalableTarget@staticmethod def from_scalable_target_attributes(scope: Construct, id: str, attrs: ScalableTargetAttributes) -> IScalableTargetpublic static IScalableTarget fromScalableTargetAttributes(Construct scope, String id, ScalableTargetAttributes attrs)public static IScalableTarget FromScalableTargetAttributes(Construct scope, string id, ScalableTargetAttributes attrs)func FromScalableTargetAttributes(Scope Construct, Id *string, Attrs ScalableTargetAttributes) IScalableTargetstatic#fromScalableTargetId(scope: Construct, id: string, scalableTargetId: string): IScalableTarget@staticmethod def from_scalable_target_id(scope: Construct, id: str, scalable_target_id: str) -> IScalableTargetpublic static IScalableTarget fromScalableTargetId(Construct scope, String id, String scalableTargetId)public static IScalableTarget FromScalableTargetId(Construct scope, string id, string scalableTargetId)func FromScalableTargetId(Scope Construct, Id *string, ScalableTargetId *string) IScalableTargetstatic#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.
isOwnedResource(construct: IConstruct): boolean@staticmethod def is_owned_resource(construct: IConstruct) -> boolpublic static Boolean isOwnedResource(IConstruct construct)public static bool IsOwnedResource(IConstruct construct)func IsOwnedResource(Construct IConstruct) *boolstatic#isResource(construct: IConstruct): boolean@staticmethod def is_resource(construct: IConstruct) -> boolpublic static Boolean isResource(IConstruct construct)public static bool IsResource(IConstruct construct)func IsResource(Construct IConstruct) *boolstatic#scaleOnMetric(id: string, props: BasicStepScalingPolicyProps): StepScalingPolicydef scale_on_metric(self, id: str, props: BasicStepScalingPolicyProps) -> StepScalingPolicypublic StepScalingPolicy scaleOnMetric(String id, BasicStepScalingPolicyProps props)public StepScalingPolicy ScaleOnMetric(string id, BasicStepScalingPolicyProps props)func ScaleOnMetric(Id *string, Props BasicStepScalingPolicyProps) StepScalingPolicy#scaleOnSchedule(id: string, action: ScalingSchedule): voiddef scale_on_schedule(self, id: str, action: ScalingSchedule) -> Nonepublic void scaleOnSchedule(String id, ScalingSchedule action)public void ScaleOnSchedule(string id, ScalingSchedule action)func ScaleOnSchedule(Id *string, Action ScalingSchedule)#scaleToTrackMetric(id: string, props: BasicTargetTrackingScalingPolicyProps): TargetTrackingScalingPolicydef scale_to_track_metric(self, id: str, props: BasicTargetTrackingScalingPolicyProps) -> TargetTrackingScalingPolicypublic TargetTrackingScalingPolicy scaleToTrackMetric(String id, BasicTargetTrackingScalingPolicyProps props)public TargetTrackingScalingPolicy ScaleToTrackMetric(string id, BasicTargetTrackingScalingPolicyProps props)func ScaleToTrackMetric(Id *string, Props BasicTargetTrackingScalingPolicyProps) TargetTrackingScalingPolicy#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.