{"id":9509,"library":"aws-cdk-aws-autoscaling","title":"AWS CDK Auto Scaling Constructs","description":"The `aws-cdk-aws-autoscaling` package provides CDK constructs for AWS Auto Scaling services, enabling infrastructure-as-code deployment of Auto Scaling Groups, lifecycle hooks, and scaling policies. This specific package is part of the AWS CDK v1 ecosystem. As of version 1.204.0, it is actively maintained within the v1 branch but the primary development focus has shifted to AWS CDK v2, which consolidates all constructs into `aws-cdk-lib`. CDK releases are frequent, typically weekly or bi-weekly.","status":"active","version":"1.204.0","language":"en","source_language":"en","source_url":"https://github.com/aws/aws-cdk.git","tags":["aws","cdk","autoscaling","cloud infrastructure","infrastructure-as-code","python"],"install":[{"cmd":"pip install aws-cdk-aws-autoscaling aws-cdk.core aws-cdk.aws-ec2","lang":"bash","label":"For AWS CDK v1.x (this package)"},{"cmd":"pip install aws-cdk-lib","lang":"bash","label":"For AWS CDK v2.x (recommended)"}],"dependencies":[],"imports":[{"note":"This package (`aws-cdk-aws-autoscaling`) is for AWS CDK v1.x. The v2 import style (`from aws_cdk import aws_autoscaling`) is used with `aws-cdk-lib`.","wrong":"from aws_cdk import aws_autoscaling","symbol":"AutoScalingGroup","correct":"from aws_cdk.aws_autoscaling import AutoScalingGroup"},{"note":"CDK v1 L1 (CloudFormation) construct import.","symbol":"CfnAutoScalingGroup","correct":"from aws_cdk.aws_autoscaling import CfnAutoScalingGroup"}],"quickstart":{"code":"import os\nfrom aws_cdk import (\n    core as cdk,\n    aws_ec2 as ec2,\n    aws_autoscaling as autoscaling,\n)\n\nclass MyAutoScalingStack(cdk.Stack):\n    def __init__(self, scope: cdk.Construct, construct_id: str, **kwargs) -> None:\n        super().__init__(scope, construct_id, **kwargs)\n\n        # Create a VPC for the Auto Scaling Group\n        vpc = ec2.Vpc(self, \"MyVpc\", max_azs=2) \n\n        # Define an Auto Scaling Group\n        asg = autoscaling.AutoScalingGroup(\n            self, \"ASG\",\n            vpc=vpc,\n            instance_type=ec2.InstanceType.of(ec2.InstanceClass.T3, ec2.InstanceSize.MICRO),\n            machine_image=ec2.AmazonLinuxImage(generation=ec2.AmazonLinuxGeneration.AMAZON_LINUX_2),\n            min_capacity=1,\n            max_capacity=1,\n            group_metrics=[autoscaling.GroupMetrics.all()], # Example for monitoring\n            health_check=autoscaling.HealthCheck.ec2()\n        )\n\napp = cdk.App()\nMyAutoScalingStack(app, \"MyAutoScalingStack\",\n                     env=cdk.Environment(account=os.environ.get('CDK_DEFAULT_ACCOUNT', ''), \n                                         region=os.environ.get('CDK_DEFAULT_REGION', ''))\n)\napp.synth()","lang":"python","description":"This quickstart demonstrates how to define a basic AWS Auto Scaling Group using AWS CDK v1 constructs. It creates a new VPC, an Auto Scaling Group with a specified instance type and Amazon Linux 2 AMI, and sets min/max capacity. To deploy, run `cdk bootstrap` (if not already done) and then `cdk deploy`."},"warnings":[{"fix":"For CDK v2, install `aws-cdk-lib` (`pip install aws-cdk-lib`) and update your import statements from `from aws_cdk.aws_autoscaling import ...` to `from aws_cdk import aws_autoscaling` and access constructs via `aws_autoscaling.AutoScalingGroup`.","message":"AWS CDK v2 consolidates all constructs into a single `aws-cdk-lib` package. This `aws-cdk-aws-autoscaling` package is specifically for CDK v1. If you are using CDK v2, you should install `aws-cdk-lib` and use the v2 import paths.","severity":"breaking","affected_versions":"All versions of aws-cdk-aws-autoscaling (v1.x) when migrating to CDK v2."},{"fix":"Ensure all required individual construct libraries for your CDK v1 project are installed via `pip install <package-name>`. For most projects, `aws-cdk.core` and relevant `aws-cdk.aws-*` packages are needed.","message":"CDK v1 requires installing individual construct libraries (e.g., `aws-cdk.core`, `aws-cdk.aws-ec2`, `aws-cdk-aws-autoscaling`) separately. Missing a dependency will lead to `ModuleNotFoundError`.","severity":"gotcha","affected_versions":"All v1.x versions."},{"fix":"Ensure your Python environment is compatible with the installed CDK v1 packages, ideally Python 3.7. Consider migrating to AWS CDK v2 for broader Python version support and ongoing updates.","message":"Python version compatibility for CDK v1.x packages is typically limited to `~=3.7`. Newer Python versions might cause issues or not be supported by older CDK v1 dependencies.","severity":"gotcha","affected_versions":"All v1.x versions with Python 3.8+."}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"If using CDK v1, run `pip install aws-cdk-aws-autoscaling`. If using CDK v2, ensure `pip install aws-cdk-lib` and update your imports to `from aws_cdk import aws_autoscaling`.","cause":"Attempting to import `aws_cdk.aws_autoscaling` but the `aws-cdk-aws-autoscaling` package is not installed, or you are using CDK v2 style imports (`from aws_cdk import aws_autoscaling`) without `aws-cdk-lib` installed.","error":"ModuleNotFoundError: No module named 'aws_cdk.aws_autoscaling'"},{"fix":"With CDK v2 (`aws-cdk-lib`), import `aws_autoscaling` directly: `from aws_cdk import aws_autoscaling` and then use `aws_autoscaling.AutoScalingGroup(...)`.","cause":"You likely have `aws-cdk-lib` (CDK v2) installed and are trying to access the AutoScalingGroup directly as `aws_cdk.aws_autoscaling.AutoScalingGroup`. In v2, `aws_autoscaling` is a module within the main `aws_cdk` namespace.","error":"AttributeError: module 'aws_cdk.aws_autoscaling' has no attribute 'AutoScalingGroup'"},{"fix":"Review the construct's documentation and ensure all required properties are explicitly provided with valid, non-None values. For `AutoScalingGroup`, `vpc`, `instance_type`, and `machine_image` are essential.","cause":"A required property for a construct (e.g., `vpc` for `AutoScalingGroup`) was not provided, or a variable assigned to a property evaluated to `None` when the construct expected a valid object.","error":"TypeError: 'NoneType' object is not callable"}]}