aws-cdk-lib.aws_autoscaling.MixedInstancesPolicy

interface MixedInstancesPolicy

LanguageType name
.NETAmazon.CDK.AWS.AutoScaling.MixedInstancesPolicy
Gogithub.com/aws/aws-cdk-go/awscdk/v2/awsautoscaling#MixedInstancesPolicy
Javasoftware.amazon.awscdk.services.autoscaling.MixedInstancesPolicy
Pythonaws_cdk.aws_autoscaling.MixedInstancesPolicy
TypeScript (source)aws-cdk-lib » aws_autoscaling » MixedInstancesPolicy

MixedInstancesPolicy allows you to configure a group that diversifies across On-Demand Instances and Spot Instances of multiple instance types.

For more information, see Auto Scaling groups with multiple instance types and purchase options in the Amazon EC2 Auto Scaling User Guide:

https://docs.aws.amazon.com/autoscaling/ec2/userguide/asg-purchase-options.html

Example

declare const vpc: ec2.Vpc;
declare const launchTemplate1: ec2.LaunchTemplate;
declare const launchTemplate2: ec2.LaunchTemplate;

new autoscaling.AutoScalingGroup(this, 'ASG', {
  vpc,
  mixedInstancesPolicy: {
    instancesDistribution: {
      onDemandPercentageAboveBaseCapacity: 50, // Mix Spot and On-Demand instances
    },
    launchTemplate: launchTemplate1,
    launchTemplateOverrides: [ // Mix multiple instance types
      { instanceType: new ec2.InstanceType('t3.micro') },
      { instanceType: new ec2.InstanceType('t3a.micro') },
      { instanceType: new ec2.InstanceType('t4g.micro'), launchTemplate: launchTemplate2 },
    ],
  }
});

Properties

NameTypeDescription
launchTemplateILaunchTemplateLaunch template to use.
instancesDistribution?InstancesDistributionInstancesDistribution to use.
launchTemplateOverrides?LaunchTemplateOverrides[]Launch template overrides.

launchTemplate

Type: ILaunchTemplate

Launch template to use.


instancesDistribution?

Type: InstancesDistribution (optional, default: The value for each property in it uses a default value.)

InstancesDistribution to use.


launchTemplateOverrides?

Type: LaunchTemplateOverrides[] (optional, default: Do not provide any overrides)

Launch template overrides.

The maximum number of instance types that can be associated with an Auto Scaling group is 40.

The maximum number of distinct launch templates you can define for an Auto Scaling group is 20.