AutoScalingGroup Constructor: Overloaded Constructor / Different Props #26439
Labels
@aws-cdk/aws-autoscaling
Related to Amazon EC2 Auto Scaling
closed-for-staleness
This issue was automatically closed because it hadn't received any attention in a while.
documentation
This is a problem with documentation.
feature-request
A feature should be added or improved.
p2
response-requested
Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.
Describe the feature
Create overloaded constructor(s) for
AutoScalingGroup
with different properties. These alternate constructors can contain eitherlaunchTemplate
ormixedInstancesPolicy
while simultaneously removing all properties that must not be specified when either of these two props are passed into the original constructor.Use Case
When migrating my CFN templates to CDK, it is difficult for me to debug my AutoScalingGroup CDK code because of the way ASGs are described in the CDK documentation and because of the way ASGs are defined in code. Building my templates takes a long time (even for a single package), and running into an error with
launchTemplate
,mixedInstancesPolicy
andmachineImage
is frustrating.Properties such as
instanceType
specify that thelaunchTemplate
/mixedInstancesPolicy
must not be specified. However,launchTemplate
andmixedInstancesPolicy
do not specify the other properties that break them in return.To fix these issues, we can both add more detail to
launchTemplate
/mixedInstancesPolicy
in the documentation and split the AutoScalingGroupProps interface into different interfaces to prevent this collision in the first place.Proposed Solution
constructor(scope: Construct, id: string, props: ASGLaunchTemplateProps);
// ASGLaunchTemplateProps is the same as AutoScalingGroupProps minus the properties
// that state
launchTemplate
must not be specifiedexport interface ASGLaunchTemplateProps extends CommonASGLaunchTemplateProps {
readonly vpc: ec2.IVpc;
readonly launchTemplate?: ec2.ILaunchTemplate;
readonly init?: ec2.CloudFormationInit;
readonly initOptions?: ApplyCloudFormationInitOptions;
readonly requireImdsv2?: boolean;
}
// CommonASGLaunchTemplateProps is the same as CommonAutoScalingGroupProps minus the properties
// that state
launchTemplate
must not be specifiedexport interface CommonAutoScalingGroupProps {
readonly minCapacity?: number;
readonly maxCapacity?: number;
readonly desiredCapacity?: number;
readonly vpcSubnets?: ec2.SubnetSelection;
readonly notifications?: NotificationConfiguration[];
readonly allowAllOutbound?: boolean;
readonly ignoreUnmodifiedSizeProperties?: boolean;
readonly cooldown?: Duration;
readonly healthCheck?: HealthCheck;
readonly maxInstanceLifetime?: Duration;
readonly groupMetrics?: GroupMetrics[];
readonly signals?: Signals;
readonly updatePolicy?: UpdatePolicy;
readonly newInstancesProtectedFromScaleIn?: boolean;
readonly autoScalingGroupName?: string;
readonly terminationPolicies?: TerminationPolicy[];
readonly defaultInstanceWarmup?: Duration;
readonly ssmSessionPermissions?: boolean;
}
// Note: The original CommonAutoScalingGroupProps can also be modified to move the properties
// that state "
launchTemplate
must not be specified" to AutoScalingGroupPropsOther Information
No response
Acknowledgements
CDK version used
2.87.0
Environment details (OS name and version, etc.)
OSX / Using AL2_x86_64
The text was updated successfully, but these errors were encountered: