class ScalableTarget (construct)
Language | Type name |
---|---|
.NET | Amazon.CDK.AWS.ApplicationAutoScaling.ScalableTarget |
Java | software.amazon.awscdk.services.applicationautoscaling.ScalableTarget |
Python | aws_cdk.aws_applicationautoscaling.ScalableTarget |
TypeScript (source) | @aws-cdk/aws-applicationautoscaling » ScalableTarget |
Implements
IConstruct
, IConstruct
, IDependable
, IResource
, IScalable
Define a scalable target.
Example
import * as lambda from '@aws-cdk/aws-lambda';
declare const code: lambda.Code;
const handler = new lambda.Function(this, 'MyFunction', {
runtime: lambda.Runtime.PYTHON_3_7,
handler: 'index.handler',
code,
reservedConcurrentExecutions: 2,
});
const fnVer = handler.currentVersion;
const target = new appscaling.ScalableTarget(this, 'ScalableTarget', {
serviceNamespace: appscaling.ServiceNamespace.LAMBDA,
maxCapacity: 100,
minCapacity: 10,
resourceId: `function:${handler.functionName}:${fnVer.version}`,
scalableDimension: 'lambda:function:ProvisionedConcurrency',
})
target.scaleToTrackMetric('PceTracking', {
targetValue: 0.9,
predefinedMetric: appscaling.PredefinedMetric.LAMBDA_PROVISIONED_CONCURRENCY_UTILIZATION,
})
Initializer
new ScalableTarget(scope: Construct, id: string, props: ScalableTargetProps)
Parameters
- scope
Construct
- id
string
- props
Scalable
Target Props
Construct Props
Name | Type | Description |
---|---|---|
max | number | The maximum value that Application Auto Scaling can use to scale a target during a scaling activity. |
min | number | The minimum value that Application Auto Scaling can use to scale a target during a scaling activity. |
resource | string | The resource identifier to associate with this scalable target. |
scalable | string | The scalable dimension that's associated with the scalable target. |
service | Service | The namespace of the AWS service that provides the resource or custom-resource for a resource provided by your own application or service. |
role? | IRole | Role that allows Application Auto Scaling to modify your scalable target. |
maxCapacity
Type:
number
The maximum value that Application Auto Scaling can use to scale a target during a scaling activity.
minCapacity
Type:
number
The minimum value that Application Auto Scaling can use to scale a target during a scaling activity.
resourceId
Type:
string
The resource identifier to associate with this scalable target.
This string consists of the resource type and unique identifier.
Example value: service/ecsStack-MyECSCluster-AB12CDE3F4GH/ecsStack-MyECSService-AB12CDE3F4GH
scalableDimension
Type:
string
The scalable dimension that's associated with the scalable target.
Specify the service namespace, resource type, and scaling property.
Example value: ecs:service:DesiredCount
serviceNamespace
Type:
Service
The namespace of the AWS service that provides the resource or custom-resource for a resource provided by your own application or service.
For valid AWS service namespace values, see the RegisterScalableTarget action in the Application Auto Scaling API Reference.
role?
Type:
IRole
(optional, default: A role is automatically created)
Role that allows Application Auto Scaling to modify your scalable target.
Properties
Name | Type | Description |
---|---|---|
env | Resource | The environment this resource belongs to. |
node | Construct | The construct tree node associated with this construct. |
role | IRole | The role used to give AutoScaling permissions to your resource. |
scalable | string | ID of the Scalable Target. |
stack | Stack | The stack in which this resource is defined. |
env
Type:
Resource
The environment this resource belongs to.
For resources that are created and managed by the CDK (generally, those created by creating new class instances like Role, Bucket, etc.), this is always the same as the environment of the stack they belong to; however, for imported resources (those obtained from static methods like fromRoleArn, fromBucketName, etc.), that might be different than the stack they were imported into.
node
Type:
Construct
The construct tree node associated with this construct.
role
Type:
IRole
The role used to give AutoScaling permissions to your resource.
scalableTargetId
Type:
string
ID of the Scalable Target.
Example value: service/ecsStack-MyECSCluster-AB12CDE3F4GH/ecsStack-MyECSService-AB12CDE3F4GH|ecs:service:DesiredCount|ecs
stack
Type:
Stack
The stack in which this resource is defined.
Methods
Name | Description |
---|---|
add | Add a policy statement to the role's policy. |
apply | Apply the given removal policy to this resource. |
scale | Scale out or in, in response to a metric. |
scale | Scale out or in based on time. |
scale | Scale out or in in order to keep a metric around a target value. |
to | Returns a string representation of this construct. |
static from |
ToRolePolicy(statement)
addpublic addToRolePolicy(statement: PolicyStatement): void
Parameters
- statement
Policy
Statement
Add a policy statement to the role's policy.
RemovalPolicy(policy)
applypublic applyRemovalPolicy(policy: RemovalPolicy): void
Parameters
- policy
Removal
Policy
Apply the given removal policy to this resource.
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
).
OnMetric(id, props)
scalepublic scaleOnMetric(id: string, props: BasicStepScalingPolicyProps): StepScalingPolicy
Parameters
- id
string
- props
Basic
Step Scaling Policy Props
Returns
Scale out or in, in response to a metric.
OnSchedule(id, action)
scalepublic scaleOnSchedule(id: string, action: ScalingSchedule): void
Parameters
- id
string
- action
Scaling
Schedule
Scale out or in based on time.
ToTrackMetric(id, props)
scalepublic scaleToTrackMetric(id: string, props: BasicTargetTrackingScalingPolicyProps): TargetTrackingScalingPolicy
Parameters
- id
string
- props
Basic
Target Tracking Scaling Policy Props
Returns
Scale out or in in order to keep a metric around a target value.
String()
topublic toString(): string
Returns
string
Returns a string representation of this construct.
ScalableTargetId(scope, id, scalableTargetId)
static frompublic static fromScalableTargetId(scope: Construct, id: string, scalableTargetId: string): IScalableTarget
Parameters
- scope
Construct
- id
string
- scalableTargetId
string
Returns