{"id":8852,"library":"aws-cdk-aws-applicationautoscaling","title":"AWS CDK Application Auto Scaling","description":"The `aws-cdk-aws-applicationautoscaling` library provides constructs for defining application auto-scaling policies within the AWS Cloud Development Kit (CDK). It enables users to programmatically configure scalable targets and scaling policies for various AWS services like ECS services, DynamoDB tables, and Aurora clusters. This library is part of the AWS CDK v1, which receives frequent updates and is distinct from the consolidated v2 package.","status":"active","version":"1.204.0","language":"en","source_language":"en","source_url":"https://github.com/aws/aws-cdk.git","tags":["aws","cdk","cloud","autoscaling","infrastructure-as-code"],"install":[{"cmd":"pip install aws-cdk.aws-applicationautoscaling","lang":"bash","label":"Install v1 library"}],"dependencies":[{"reason":"Core CDK constructs and app definition for v1.","package":"aws-cdk.core","optional":false}],"imports":[{"note":"While direct import works, aliasing to `appautoscaling` is a common and recommended pattern in CDK examples.","wrong":"from aws_cdk.aws_applicationautoscaling import ScalableTarget","symbol":"ScalableTarget","correct":"from aws_cdk import aws_applicationautoscaling as appautoscaling"}],"quickstart":{"code":"import os\nfrom aws_cdk import App, Stack, Duration\nfrom aws_cdk import aws_applicationautoscaling as appautoscaling\n\nclass ApplicationAutoScalingStack(Stack):\n    def __init__(self, scope: App, id: str, **kwargs) -> None:\n        super().__init__(scope, id, **kwargs)\n\n        # Define a scalable target for an ECS service's desired count.\n        # In a real application, 'resource_id' would refer to an existing\n        # ECS service ARN or logical ID. Adjust 'resource_id' to your target service.\n        scalable_target = appautoscaling.ScalableTarget(\n            self, \"MyEcsScalableTarget\",\n            service_namespace=appautoscaling.ServiceNamespace.ECS,\n            min_capacity=1,\n            max_capacity=10,\n            # IMPORTANT: Replace with your actual ECS Cluster/Service name\n            resource_id=\"service/YourEcsClusterName/YourEcsServiceName\",\n            scalable_dimension=\"ecs:service:DesiredCount\"\n        )\n\n        # Scale out based on CPU utilization\n        scalable_target.scale_on_cpu_utilization(\n            \"CpuScalingPolicy\",\n            target_utilization_percent=70,\n            scale_in_cooldown=Duration.seconds(60),\n            scale_out_cooldown=Duration.seconds(60)\n        )\n\napp = App()\nApplicationAutoScalingStack(app, \"ApplicationAutoScalingStack\",\n    env={\n        'account': os.environ.get('CDK_DEFAULT_ACCOUNT', '123456789012'),\n        'region': os.environ.get('CDK_DEFAULT_REGION', 'us-east-1')\n    }\n)\napp.synth()","lang":"python","description":"This example demonstrates how to define a `ScalableTarget` for an ECS service's desired count and apply a CPU utilization scaling policy. Remember to replace the placeholder `resource_id` with your actual service details and ensure your environment variables `CDK_DEFAULT_ACCOUNT` and `CDK_DEFAULT_REGION` are set."},"warnings":[{"fix":"For new projects, consider using AWS CDK v2 (install `aws-cdk` instead of individual modules). For existing v1 projects, ensure `pip install aws-cdk.aws-applicationautoscaling` is used.","message":"This library is for AWS CDK v1. AWS CDK v2 consolidated all construct libraries into a single `aws-cdk` package. Migrating from v1 to v2 requires updating imports and potentially some API changes.","severity":"breaking","affected_versions":"All versions up to 1.x.x (v1)"},{"fix":"Consult the AWS documentation for Application Auto Scaling to find the exact `resource_id` and `scalable_dimension` formats for your target service (e.g., ECS, DynamoDB, RDS Aurora, AppStream 2.0).","message":"The `resource_id` and `scalable_dimension` parameters for `ScalableTarget` are highly specific to the AWS service you are scaling. Incorrect formats will lead to CloudFormation deployment failures.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure the IAM role used by CloudFormation and the implicitly created service-linked role for Application Auto Scaling have adequate permissions (e.g., `ecs:UpdateService`, `dynamodb:UpdateTable`, `cloudwatch:GetMetricData`).","message":"Application Auto Scaling requires specific IAM permissions to describe the target resource and its metrics, as well as to update its capacity. Deployment might fail with permission errors if the CDK's execution role or the auto-scaling service-linked role lacks these permissions.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Run `pip install aws-cdk.aws-applicationautoscaling`. Ensure your import statement is `from aws_cdk import aws_applicationautoscaling as appautoscaling`.","cause":"The `aws-cdk.aws-applicationautoscaling` package is not installed or the import path is incorrect for CDK v1.","error":"ModuleNotFoundError: No module named 'aws_cdk.aws_applicationautoscaling'"},{"fix":"Verify the `resource_id` format based on the `service_namespace`. For ECS, it's typically `service/<cluster-name>/<service-name>`. For DynamoDB, `table/<table-name>` or `table/<table-name>/index/<index-name>`.","cause":"The `resource_id` provided to `appautoscaling.ScalableTarget` does not conform to the expected format for the specified `service_namespace`.","error":"AWS CloudFormation Error: Parameter 'ResourceId' must be in the format 'service/<service_name>' for ECS (or similar for other services like 'table/<table_name>' for DynamoDB)."},{"fix":"Ensure your CDK version (v1) matches the documentation you are following. For v1, methods like `scale_on_cpu_utilization`, `scale_on_request_count`, and `scale_on_metric` are valid directly on the `ScalableTarget` object.","cause":"This error can occur if you are mixing CDK v1 constructs with v2 API patterns, or vice-versa, or if you're trying to call a method that doesn't exist on the `ScalableTarget` object.","error":"AttributeError: 'ScalableTarget' object has no attribute 'scale_on_cpu_utilization' (or 'scale_on_metric', etc.)"}]}