AWS CDK Auto Scaling Common Library
The `aws-cdk-aws-autoscaling-common` package provides shared implementation details for the AWS Cloud Development Kit's `@aws-cdk/aws-autoscaling` and `@aws-cdk/aws-applicationautoscaling` libraries. It is an internal dependency and is not intended for direct use by CDK users. As of version 1.204.0, this package is part of AWS CDK v1, which has reached End-of-Support. Users are encouraged to migrate to AWS CDK v2 and utilize `aws-cdk-lib.aws_autoscaling` and `aws-cdk-lib.aws_applicationautoscaling` directly.
Common errors
-
ERROR: Cannot install aws-cdk-lib==2.x.y and constructs<4.0.0 and >=3.3.69 because these package versions have conflicting dependencies.
cause This error typically occurs when trying to install `aws-cdk-lib` (CDK v2) alongside older CDK v1 packages like `aws-cdk-aws-autoscaling-common` or other `aws-cdk.aws-*` modules, which require an older `constructs` version (e.g., `<4.0.0`), while `aws-cdk-lib` requires a newer one (e.g., `>=10.0.0`).fixEnsure you are working in a clean Python virtual environment. Install either only AWS CDK v2 (`pip install aws-cdk-lib`) or only AWS CDK v1 components (e.g., `pip install aws-cdk.aws-autoscaling-common==1.204.0`), but do not mix them. The recommended approach is to migrate entirely to AWS CDK v2. -
ModuleNotFoundError: No module named 'aws_cdk.aws_autoscaling_common'
cause You are attempting to directly import `aws_cdk.aws_autoscaling_common`. This package is not designed for direct user interaction and its components are typically exposed through higher-level `aws_cdk.aws_autoscaling` or `aws_cdk.aws_applicationautoscaling` modules. This error might occur if you are expecting it to behave like a standalone construct library in CDK v2.fixInstead of importing `aws_cdk.aws_autoscaling_common`, import `aws_cdk.aws_autoscaling` or `aws_cdk.aws_applicationautoscaling` from `aws-cdk-lib` (for CDK v2) or directly from the respective v1 packages if you are intentionally using v1. All user-facing autoscaling constructs are available there.
Warnings
- breaking `aws-cdk-aws-autoscaling-common` is a v1 package and has reached End-of-Support. Continued use of AWS CDK v1 constructs with AWS CDK v2 libraries (like `aws-cdk-lib`) can lead to dependency conflicts, particularly with the `constructs` library.
- gotcha Do not attempt to directly import or use constructs from `aws-cdk-aws-autoscaling-common`. It is an internal implementation detail and not part of the public API for users.
- deprecated AWS CDK v1, including `aws-cdk-aws-autoscaling-common`, reached End-of-Support on 2023-06-01. While the package might still be installable, it no longer receives updates, security patches, or new features.
Install
-
pip install aws-cdk.aws-autoscaling-common==1.204.0 -
pip install aws-cdk-lib
Imports
- AutoScalingGroup
from aws_cdk import aws_autoscaling as autoscaling # ... autoscaling.AutoScalingGroup
Quickstart
import os
from aws_cdk import (
App,
Stack,
aws_ec2 as ec2,
aws_autoscaling as autoscaling,
Duration
)
class AutoScalingStack(Stack):
def __init__(self, scope: App, id: str, **kwargs) -> None:
super().__init__(scope, id, **kwargs)
vpc = ec2.Vpc(self, "MyVpc", max_azs=2)
asg = autoscaling.AutoScalingGroup(self, "MyASG",
vpc=vpc,
instance_type=ec2.InstanceType.of(
ec2.InstanceClass.BURSTABLE2,
ec2.InstanceSize.MICRO
),
machine_image=ec2.MachineImage.latest_amazon_linux2(),
min_capacity=1,
max_capacity=3
)
asg.scale_on_cpu_utilization("CpuScaling",
target_utilization_percent=50,
cooldown=Duration.minutes(5)
)
app = App()
AutoScalingStack(app, "AutoScalingExampleStack")
app.synth()