Skip to content
v2.277.0

MixedInstancesPolicyProperty Struct ​

Use this structure to launch multiple instance types and On-Demand Instances and Spot Instances within a single Auto Scaling group.

A mixed instances policy contains information that Amazon EC2 Auto Scaling can use to launch instances and help optimize your costs. For more information, see Auto Scaling groups with multiple instance types and purchase options in the Amazon EC2 Auto Scaling User Guide .

You can create a mixed instances policy for new and existing Auto Scaling groups. You must use a launch template to configure the policy. You cannot use a launch configuration.

There are key differences between Spot Instances and On-Demand Instances:

  • The price for Spot Instances varies based on demand
  • Amazon EC2 can terminate an individual Spot Instance as the availability of, or price for, Spot Instances changes

When a Spot Instance is terminated, Amazon EC2 Auto Scaling group attempts to launch a replacement instance to maintain the desired capacity for the group.

MixedInstancesPolicy is a property of the AWS::AutoScaling::AutoScalingGroup resource.

Example ​

ts
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import { aws_autoscaling as autoscaling } from 'aws-cdk-lib';
const mixedInstancesPolicyProperty: autoscaling.CfnAutoScalingGroup.MixedInstancesPolicyProperty = {
  launchTemplate: {
    launchTemplateSpecification: {
      version: 'version',

      // the properties below are optional
      launchTemplateId: 'launchTemplateId',
      launchTemplateName: 'launchTemplateName',
    },

    // the properties below are optional
    overrides: [{
      imageId: 'imageId',
      instanceRequirements: {
        memoryMiB: {
          max: 123,
          min: 123,
        },
        vCpuCount: {
          max: 123,
          min: 123,
        },

        // the properties below are optional
        acceleratorCount: {
          max: 123,
          min: 123,
        },
        acceleratorManufacturers: ['acceleratorManufacturers'],
        acceleratorNames: ['acceleratorNames'],
        acceleratorTotalMemoryMiB: {
          max: 123,
          min: 123,
        },
        acceleratorTypes: ['acceleratorTypes'],
        allowedInstanceTypes: ['allowedInstanceTypes'],
        bareMetal: 'bareMetal',
        baselineEbsBandwidthMbps: {
          max: 123,
          min: 123,
        },
        baselinePerformanceFactors: {
          cpu: {
            references: [{
              instanceFamily: 'instanceFamily',
            }],
          },
        },
        burstablePerformance: 'burstablePerformance',
        cpuManufacturers: ['cpuManufacturers'],
        excludedInstanceTypes: ['excludedInstanceTypes'],
        instanceGenerations: ['instanceGenerations'],
        localStorage: 'localStorage',
        localStorageTypes: ['localStorageTypes'],
        maxSpotPriceAsPercentageOfOptimalOnDemandPrice: 123,
        memoryGiBPerVCpu: {
          max: 123,
          min: 123,
        },
        networkBandwidthGbps: {
          max: 123,
          min: 123,
        },
        networkInterfaceCount: {
          max: 123,
          min: 123,
        },
        onDemandMaxPricePercentageOverLowestPrice: 123,
        requireHibernateSupport: false,
        spotMaxPricePercentageOverLowestPrice: 123,
        totalLocalStorageGb: {
          max: 123,
          min: 123,
        },
      },
      instanceType: 'instanceType',
      launchTemplateSpecification: {
        version: 'version',

        // the properties below are optional
        launchTemplateId: 'launchTemplateId',
        launchTemplateName: 'launchTemplateName',
      },
      weightedCapacity: 'weightedCapacity',
    }],
  },

  // the properties below are optional
  instancesDistribution: {
    distributionSegments: [{
      targetCapacityTypes: ['targetCapacityTypes'],
    }],
    onDemandAllocationStrategy: 'onDemandAllocationStrategy',
    onDemandBaseCapacity: 123,
    onDemandPercentageAboveBaseCapacity: 123,
    spotAllocationStrategy: 'spotAllocationStrategy',
    spotInstancePools: 123,
    spotMaxPrice: 'spotMaxPrice',
  },
};
python
# The code below shows an example of how to instantiate this type.
# The values are placeholders you should change.
from aws_cdk import aws_autoscaling as autoscaling

mixed_instances_policy_property = autoscaling.CfnAutoScalingGroup.MixedInstancesPolicyProperty(
    launch_template=autoscaling.CfnAutoScalingGroup.LaunchTemplateProperty(
        launch_template_specification=autoscaling.CfnAutoScalingGroup.LaunchTemplateSpecificationProperty(
            version="version",

            # the properties below are optional
            launch_template_id="launchTemplateId",
            launch_template_name="launchTemplateName"
        ),

        # the properties below are optional
        overrides=[autoscaling.CfnAutoScalingGroup.LaunchTemplateOverridesProperty(
            image_id="imageId",
            instance_requirements=autoscaling.CfnAutoScalingGroup.InstanceRequirementsProperty(
                memory_mi_b=autoscaling.CfnAutoScalingGroup.MemoryMiBRequestProperty(
                    max=123,
                    min=123
                ),
                v_cpu_count=autoscaling.CfnAutoScalingGroup.VCpuCountRequestProperty(
                    max=123,
                    min=123
                ),

                # the properties below are optional
                accelerator_count=autoscaling.CfnAutoScalingGroup.AcceleratorCountRequestProperty(
                    max=123,
                    min=123
                ),
                accelerator_manufacturers=["acceleratorManufacturers"],
                accelerator_names=["acceleratorNames"],
                accelerator_total_memory_mi_b=autoscaling.CfnAutoScalingGroup.AcceleratorTotalMemoryMiBRequestProperty(
                    max=123,
                    min=123
                ),
                accelerator_types=["acceleratorTypes"],
                allowed_instance_types=["allowedInstanceTypes"],
                bare_metal="bareMetal",
                baseline_ebs_bandwidth_mbps=autoscaling.CfnAutoScalingGroup.BaselineEbsBandwidthMbpsRequestProperty(
                    max=123,
                    min=123
                ),
                baseline_performance_factors=autoscaling.CfnAutoScalingGroup.BaselinePerformanceFactorsRequestProperty(
                    cpu=autoscaling.CfnAutoScalingGroup.CpuPerformanceFactorRequestProperty(
                        references=[autoscaling.CfnAutoScalingGroup.PerformanceFactorReferenceRequestProperty(
                            instance_family="instanceFamily"
                        )]
                    )
                ),
                burstable_performance="burstablePerformance",
                cpu_manufacturers=["cpuManufacturers"],
                excluded_instance_types=["excludedInstanceTypes"],
                instance_generations=["instanceGenerations"],
                local_storage="localStorage",
                local_storage_types=["localStorageTypes"],
                max_spot_price_as_percentage_of_optimal_on_demand_price=123,
                memory_gi_b_per_v_cpu=autoscaling.CfnAutoScalingGroup.MemoryGiBPerVCpuRequestProperty(
                    max=123,
                    min=123
                ),
                network_bandwidth_gbps=autoscaling.CfnAutoScalingGroup.NetworkBandwidthGbpsRequestProperty(
                    max=123,
                    min=123
                ),
                network_interface_count=autoscaling.CfnAutoScalingGroup.NetworkInterfaceCountRequestProperty(
                    max=123,
                    min=123
                ),
                on_demand_max_price_percentage_over_lowest_price=123,
                require_hibernate_support=False,
                spot_max_price_percentage_over_lowest_price=123,
                total_local_storage_gb=autoscaling.CfnAutoScalingGroup.TotalLocalStorageGBRequestProperty(
                    max=123,
                    min=123
                )
            ),
            instance_type="instanceType",
            launch_template_specification=autoscaling.CfnAutoScalingGroup.LaunchTemplateSpecificationProperty(
                version="version",

                # the properties below are optional
                launch_template_id="launchTemplateId",
                launch_template_name="launchTemplateName"
            ),
            weighted_capacity="weightedCapacity"
        )]
    ),

    # the properties below are optional
    instances_distribution=autoscaling.CfnAutoScalingGroup.InstancesDistributionProperty(
        distribution_segments=[autoscaling.CfnAutoScalingGroup.DistributionSegmentProperty(
            target_capacity_types=["targetCapacityTypes"]
        )],
        on_demand_allocation_strategy="onDemandAllocationStrategy",
        on_demand_base_capacity=123,
        on_demand_percentage_above_base_capacity=123,
        spot_allocation_strategy="spotAllocationStrategy",
        spot_instance_pools=123,
        spot_max_price="spotMaxPrice"
    )
)
java
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import software.amazon.awscdk.services.autoscaling.*;

MixedInstancesPolicyProperty mixedInstancesPolicyProperty = MixedInstancesPolicyProperty.builder()
        .launchTemplate(LaunchTemplateProperty.builder()
                .launchTemplateSpecification(LaunchTemplateSpecificationProperty.builder()
                        .version("version")

                        // the properties below are optional
                        .launchTemplateId("launchTemplateId")
                        .launchTemplateName("launchTemplateName")
                        .build())

                // the properties below are optional
                .overrides(List.of(LaunchTemplateOverridesProperty.builder()
                        .imageId("imageId")
                        .instanceRequirements(InstanceRequirementsProperty.builder()
                                .memoryMiB(MemoryMiBRequestProperty.builder()
                                        .max(123)
                                        .min(123)
                                        .build())
                                .vCpuCount(VCpuCountRequestProperty.builder()
                                        .max(123)
                                        .min(123)
                                        .build())

                                // the properties below are optional
                                .acceleratorCount(AcceleratorCountRequestProperty.builder()
                                        .max(123)
                                        .min(123)
                                        .build())
                                .acceleratorManufacturers(List.of("acceleratorManufacturers"))
                                .acceleratorNames(List.of("acceleratorNames"))
                                .acceleratorTotalMemoryMiB(AcceleratorTotalMemoryMiBRequestProperty.builder()
                                        .max(123)
                                        .min(123)
                                        .build())
                                .acceleratorTypes(List.of("acceleratorTypes"))
                                .allowedInstanceTypes(List.of("allowedInstanceTypes"))
                                .bareMetal("bareMetal")
                                .baselineEbsBandwidthMbps(BaselineEbsBandwidthMbpsRequestProperty.builder()
                                        .max(123)
                                        .min(123)
                                        .build())
                                .baselinePerformanceFactors(BaselinePerformanceFactorsRequestProperty.builder()
                                        .cpu(CpuPerformanceFactorRequestProperty.builder()
                                                .references(List.of(PerformanceFactorReferenceRequestProperty.builder()
                                                        .instanceFamily("instanceFamily")
                                                        .build()))
                                                .build())
                                        .build())
                                .burstablePerformance("burstablePerformance")
                                .cpuManufacturers(List.of("cpuManufacturers"))
                                .excludedInstanceTypes(List.of("excludedInstanceTypes"))
                                .instanceGenerations(List.of("instanceGenerations"))
                                .localStorage("localStorage")
                                .localStorageTypes(List.of("localStorageTypes"))
                                .maxSpotPriceAsPercentageOfOptimalOnDemandPrice(123)
                                .memoryGiBPerVCpu(MemoryGiBPerVCpuRequestProperty.builder()
                                        .max(123)
                                        .min(123)
                                        .build())
                                .networkBandwidthGbps(NetworkBandwidthGbpsRequestProperty.builder()
                                        .max(123)
                                        .min(123)
                                        .build())
                                .networkInterfaceCount(NetworkInterfaceCountRequestProperty.builder()
                                        .max(123)
                                        .min(123)
                                        .build())
                                .onDemandMaxPricePercentageOverLowestPrice(123)
                                .requireHibernateSupport(false)
                                .spotMaxPricePercentageOverLowestPrice(123)
                                .totalLocalStorageGb(TotalLocalStorageGBRequestProperty.builder()
                                        .max(123)
                                        .min(123)
                                        .build())
                                .build())
                        .instanceType("instanceType")
                        .launchTemplateSpecification(LaunchTemplateSpecificationProperty.builder()
                                .version("version")

                                // the properties below are optional
                                .launchTemplateId("launchTemplateId")
                                .launchTemplateName("launchTemplateName")
                                .build())
                        .weightedCapacity("weightedCapacity")
                        .build()))
                .build())

        // the properties below are optional
        .instancesDistribution(InstancesDistributionProperty.builder()
                .distributionSegments(List.of(DistributionSegmentProperty.builder()
                        .targetCapacityTypes(List.of("targetCapacityTypes"))
                        .build()))
                .onDemandAllocationStrategy("onDemandAllocationStrategy")
                .onDemandBaseCapacity(123)
                .onDemandPercentageAboveBaseCapacity(123)
                .spotAllocationStrategy("spotAllocationStrategy")
                .spotInstancePools(123)
                .spotMaxPrice("spotMaxPrice")
                .build())
        .build();
csharp
// Install: dotnet add package Amazon.CDK.Lib
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
using Amazon.CDK.AWS.AutoScaling;

var mixedInstancesPolicyProperty = new MixedInstancesPolicyProperty {
    LaunchTemplate = new LaunchTemplateProperty {
        LaunchTemplateSpecification = new LaunchTemplateSpecificationProperty {
            Version = "version",

            // the properties below are optional
            LaunchTemplateId = "launchTemplateId",
            LaunchTemplateName = "launchTemplateName"
        },

        // the properties below are optional
        Overrides = new [] { new LaunchTemplateOverridesProperty {
            ImageId = "imageId",
            InstanceRequirements = new InstanceRequirementsProperty {
                MemoryMiB = new MemoryMiBRequestProperty {
                    Max = 123,
                    Min = 123
                },
                VCpuCount = new VCpuCountRequestProperty {
                    Max = 123,
                    Min = 123
                },

                // the properties below are optional
                AcceleratorCount = new AcceleratorCountRequestProperty {
                    Max = 123,
                    Min = 123
                },
                AcceleratorManufacturers = new [] { "acceleratorManufacturers" },
                AcceleratorNames = new [] { "acceleratorNames" },
                AcceleratorTotalMemoryMiB = new AcceleratorTotalMemoryMiBRequestProperty {
                    Max = 123,
                    Min = 123
                },
                AcceleratorTypes = new [] { "acceleratorTypes" },
                AllowedInstanceTypes = new [] { "allowedInstanceTypes" },
                BareMetal = "bareMetal",
                BaselineEbsBandwidthMbps = new BaselineEbsBandwidthMbpsRequestProperty {
                    Max = 123,
                    Min = 123
                },
                BaselinePerformanceFactors = new BaselinePerformanceFactorsRequestProperty {
                    Cpu = new CpuPerformanceFactorRequestProperty {
                        References = new [] { new PerformanceFactorReferenceRequestProperty {
                            InstanceFamily = "instanceFamily"
                        } }
                    }
                },
                BurstablePerformance = "burstablePerformance",
                CpuManufacturers = new [] { "cpuManufacturers" },
                ExcludedInstanceTypes = new [] { "excludedInstanceTypes" },
                InstanceGenerations = new [] { "instanceGenerations" },
                LocalStorage = "localStorage",
                LocalStorageTypes = new [] { "localStorageTypes" },
                MaxSpotPriceAsPercentageOfOptimalOnDemandPrice = 123,
                MemoryGiBPerVCpu = new MemoryGiBPerVCpuRequestProperty {
                    Max = 123,
                    Min = 123
                },
                NetworkBandwidthGbps = new NetworkBandwidthGbpsRequestProperty {
                    Max = 123,
                    Min = 123
                },
                NetworkInterfaceCount = new NetworkInterfaceCountRequestProperty {
                    Max = 123,
                    Min = 123
                },
                OnDemandMaxPricePercentageOverLowestPrice = 123,
                RequireHibernateSupport = false,
                SpotMaxPricePercentageOverLowestPrice = 123,
                TotalLocalStorageGb = new TotalLocalStorageGBRequestProperty {
                    Max = 123,
                    Min = 123
                }
            },
            InstanceType = "instanceType",
            LaunchTemplateSpecification = new LaunchTemplateSpecificationProperty {
                Version = "version",

                // the properties below are optional
                LaunchTemplateId = "launchTemplateId",
                LaunchTemplateName = "launchTemplateName"
            },
            WeightedCapacity = "weightedCapacity"
        } }
    },

    // the properties below are optional
    InstancesDistribution = new InstancesDistributionProperty {
        DistributionSegments = new [] { new DistributionSegmentProperty {
            TargetCapacityTypes = new [] { "targetCapacityTypes" }
        } },
        OnDemandAllocationStrategy = "onDemandAllocationStrategy",
        OnDemandBaseCapacity = 123,
        OnDemandPercentageAboveBaseCapacity = 123,
        SpotAllocationStrategy = "spotAllocationStrategy",
        SpotInstancePools = 123,
        SpotMaxPrice = "spotMaxPrice"
    }
};
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import "github.com/aws/aws-cdk-go/awscdk"

mixedInstancesPolicyProperty := &MixedInstancesPolicyProperty{
	LaunchTemplate: &LaunchTemplateProperty{
		LaunchTemplateSpecification: &LaunchTemplateSpecificationProperty{
			Version: jsii.String("version"),

			// the properties below are optional
			LaunchTemplateId: jsii.String("launchTemplateId"),
			LaunchTemplateName: jsii.String("launchTemplateName"),
		},

		// the properties below are optional
		Overrides: []interface{}{
			&LaunchTemplateOverridesProperty{
				ImageId: jsii.String("imageId"),
				InstanceRequirements: &InstanceRequirementsProperty{
					MemoryMiB: &MemoryMiBRequestProperty{
						Max: jsii.Number(123),
						Min: jsii.Number(123),
					},
					VCpuCount: &VCpuCountRequestProperty{
						Max: jsii.Number(123),
						Min: jsii.Number(123),
					},

					// the properties below are optional
					AcceleratorCount: &AcceleratorCountRequestProperty{
						Max: jsii.Number(123),
						Min: jsii.Number(123),
					},
					AcceleratorManufacturers: []*string{
						jsii.String("acceleratorManufacturers"),
					},
					AcceleratorNames: []*string{
						jsii.String("acceleratorNames"),
					},
					AcceleratorTotalMemoryMiB: &AcceleratorTotalMemoryMiBRequestProperty{
						Max: jsii.Number(123),
						Min: jsii.Number(123),
					},
					AcceleratorTypes: []*string{
						jsii.String("acceleratorTypes"),
					},
					AllowedInstanceTypes: []*string{
						jsii.String("allowedInstanceTypes"),
					},
					BareMetal: jsii.String("bareMetal"),
					BaselineEbsBandwidthMbps: &BaselineEbsBandwidthMbpsRequestProperty{
						Max: jsii.Number(123),
						Min: jsii.Number(123),
					},
					BaselinePerformanceFactors: &BaselinePerformanceFactorsRequestProperty{
						Cpu: &CpuPerformanceFactorRequestProperty{
							References: []interface{}{
								&PerformanceFactorReferenceRequestProperty{
									InstanceFamily: jsii.String("instanceFamily"),
								},
							},
						},
					},
					BurstablePerformance: jsii.String("burstablePerformance"),
					CpuManufacturers: []*string{
						jsii.String("cpuManufacturers"),
					},
					ExcludedInstanceTypes: []*string{
						jsii.String("excludedInstanceTypes"),
					},
					InstanceGenerations: []*string{
						jsii.String("instanceGenerations"),
					},
					LocalStorage: jsii.String("localStorage"),
					LocalStorageTypes: []*string{
						jsii.String("localStorageTypes"),
					},
					MaxSpotPriceAsPercentageOfOptimalOnDemandPrice: jsii.Number(123),
					MemoryGiBPerVCpu: &MemoryGiBPerVCpuRequestProperty{
						Max: jsii.Number(123),
						Min: jsii.Number(123),
					},
					NetworkBandwidthGbps: &NetworkBandwidthGbpsRequestProperty{
						Max: jsii.Number(123),
						Min: jsii.Number(123),
					},
					NetworkInterfaceCount: &NetworkInterfaceCountRequestProperty{
						Max: jsii.Number(123),
						Min: jsii.Number(123),
					},
					OnDemandMaxPricePercentageOverLowestPrice: jsii.Number(123),
					RequireHibernateSupport: jsii.Boolean(false),
					SpotMaxPricePercentageOverLowestPrice: jsii.Number(123),
					TotalLocalStorageGb: &TotalLocalStorageGBRequestProperty{
						Max: jsii.Number(123),
						Min: jsii.Number(123),
					},
				},
				InstanceType: jsii.String("instanceType"),
				LaunchTemplateSpecification: &LaunchTemplateSpecificationProperty{
					Version: jsii.String("version"),

					// the properties below are optional
					LaunchTemplateId: jsii.String("launchTemplateId"),
					LaunchTemplateName: jsii.String("launchTemplateName"),
				},
				WeightedCapacity: jsii.String("weightedCapacity"),
			},
		},
	},

	// the properties below are optional
	InstancesDistribution: &InstancesDistributionProperty{
		DistributionSegments: []interface{}{
			&DistributionSegmentProperty{
				TargetCapacityTypes: []*string{
					jsii.String("targetCapacityTypes"),
				},
			},
		},
		OnDemandAllocationStrategy: jsii.String("onDemandAllocationStrategy"),
		OnDemandBaseCapacity: jsii.Number(123),
		OnDemandPercentageAboveBaseCapacity: jsii.Number(123),
		SpotAllocationStrategy: jsii.String("spotAllocationStrategy"),
		SpotInstancePools: jsii.Number(123),
		SpotMaxPrice: jsii.String("spotMaxPrice"),
	},
}

Properties ​

instancesDistributionoptionalIResolvable | CfnAutoScalingGroup.InstancesDistributionPropertyinstances_distributionoptionaltyping.Union[IResolvable, InstancesDistributionProperty]instancesDistributionoptionalIResolvableInstancesDistributionoptionalIResolvableInstancesDistributionoptionalinterface{}#
The instances distribution.
launchTemplateIResolvable | CfnAutoScalingGroup.LaunchTemplatePropertylaunch_templatetyping.Union[IResolvable, LaunchTemplateProperty]launchTemplateIResolvableLaunchTemplateIResolvableLaunchTemplateinterface{}required#
One or more launch templates and the instance types (overrides) that are used to launch EC2 instances to fulfill On-Demand and Spot capacities.