Registry / aws / aws-cdk-aws-autoscaling-hooktargets

aws-cdk-aws-autoscaling-hooktargets

JSON →
library1.204.0pypypiunverified

This library provides high-level constructs for defining targets for AWS Auto Scaling group lifecycle hooks, such as sending notifications to an SNS topic or SQS queue, or invoking a Lambda function. It is part of the AWS Cloud Development Kit (CDK) v1 ecosystem, specifically module version 1.204.0, and follows the CDK's rapid release cadence.

pip install aws-cdk.aws-autoscaling-hooktargets
INSTALL
IMPORT
SIG · AWS-CDK-AWS-AUTOSC
A
aws-cdk-aws-autoscaling-hooktargets
awspythonv1.204.0
Install
9.0s avg
Import
Disk
68MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.204.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 65.2MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 9.0s · import 0.000s · 66MB
68MB installed
● package 68MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

TopicHookTarget
from aws_cdk.aws_autoscaling_hooktargets import TopicHookTarget
from aws_cdk.aws_autoscaling_hooktargets import TopicHookTarget

This quickstart demonstrates how to create an AWS Auto Scaling Group with a lifecycle hook configured to publish notifications to an SNS Topic upon instance launch, using the `TopicHookTarget` from this library. This example is for CDK v1. Make sure to replace `os.environ.get('CDK_DEFAULT_REGION')` with a concrete region if not set.

import os from aws_cdk import ( Stack, App, Duration, aws_ec2 as ec2, aws_autoscaling as autoscaling, aws_sns as sns, ) from aws_cdk.aws_autoscaling_hooktargets import TopicHookTarget from constructs import Construct class AutoScalingHookStack(Stack): def __init__(self, scope: Construct, id: str, **kwargs) -> None: super().__init__(scope, id, **kwargs) vpc = ec2.Vpc(self, "VPC", max_azs=2) # Create an SNS Topic to receive notifications topic = sns.Topic(self, "LifecycleHookTopic") # Create an Auto Scaling Group asg = autoscaling.AutoScalingGroup(self, "ASG", vpc=vpc, instance_type=ec2.InstanceType.of(ec2.InstanceClass.T2, ec2.InstanceSize.MICRO), machine_image=ec2.AmazonLinuxImage(), min_capacity=0, max_capacity=1, desired_capacity=0 # Start at 0 to see hooks fire on scale-out ) # Add a lifecycle hook targeting the SNS Topic asg.add_lifecycle_hook("ScalingOutHook", lifecycle_transition=autoscaling.LifecycleTransition.AUTO_SCALING_LAUNCH, notification_target=TopicHookTarget(topic), default_result=autoscaling.DefaultResult.CONTINUE, heartbeat_timeout=Duration.minutes(5) ) # Example of how to synthesize the stack # app = App() # AutoScalingHookStack(app, "AutoScalingHookExampleStack", # env={'region': os.environ.get('CDK_DEFAULT_REGION', 'us-east-1')}) # app.synth()
Debug
Known issues
breakingThis library (`aws-cdk.aws-autoscaling-hooktargets`) is specific to AWS CDK v1. It is not compatible with AWS CDK v2.
fix
For AWS CDK v2, do not install this package. Its functionality is integrated directly into `aws-cdk-lib.aws_autoscaling`. You should use `aws_cdk.aws_autoscaling.LifecycleHook` and pass appropriate `notification_target` properties or implement `aws_cdk.aws_autoscaling.ILifecycleHookTarget` directly.
affects: All versions (CDK v1 vs CDK v2)
deprecatedAs of CDK v2, dedicated `*-hooktargets` modules are deprecated in favor of direct integration into `aws-cdk-lib`'s primary service modules.
fix
Migrate your CDK application to v2. Install `aws-cdk-lib` and `constructs`, then refactor your lifecycle hook definitions to use the v2 API within `aws_cdk.aws_autoscaling`.
affects: All versions, when considering migration to CDK v2.
gotchaAWS Auto Scaling lifecycle hooks require proper IAM permissions for the Auto Scaling Service-Linked Role to interact with the specified targets (SNS, SQS, Lambda).
fix
Ensure the Auto Scaling Service-Linked Role (`AWSServiceRoleForAutoScaling`) has the necessary permissions (e.g., `sns:Publish` for SNS, `sqs:SendMessage` for SQS, `lambda:InvokeFunction` for Lambda) on the target resources. While CDK often attempts to add these, explicit policies may be needed in complex scenarios or if default permissions are overridden.
affects: All versions.
gotchaIncorrectly configured `heartbeat_timeout` or `default_result` for a lifecycle hook can lead to instances hanging or prematurely continuing/abandoning the lifecycle action.
fix
Carefully consider the expected duration of custom actions performed during the hook and set `heartbeat_timeout` accordingly. Use `default_result=autoscaling.DefaultResult.ABANDON` if you want instances to terminate without completing the action, or `default_result=autoscaling.DefaultResult.CONTINUE` if you want them to proceed even if the hook action fails or times out.
affects: All versions.
Upgrade
Version history
1.204.0latest on PyPI · released Jun 19, 2023
Audit
Dependencies
aws-cdk.corerequiredCore AWS CDK v1 functionality.
aws-cdk.aws-autoscalingrequiredRequired for Auto Scaling Group definitions.
aws-cdk.aws-snsoptionalNeeded for SNS Topic targets.
aws-cdk.aws-sqsoptionalNeeded for SQS Queue targets.
aws-cdk.aws-lambdaoptionalNeeded for Lambda Function targets.
Agent activity
25 hits · last 30 days
node
24
Resources