AWS EC2 Launch Templates

AWS EC2 Launch Template Features, Use Cases and Sample API Requests

Launch Template Support must be enabled in order to use the features described in this page. Follow guidelines here to enable the feature set.

Note: The features supported in the UI (Deck) come with tool tips that can help you learn the new features. Consider trying them out in Deck, especially if they are new to you.

Feature Configuration

Once launch templates support is enabled in Clouddriver, a new set of features are unlocked. Some of them are tied to the EC2 launch template directly like IMDSV2 and others require a launch template to be used in order to support features like SpotAllocationStrategy ( MixedInstancesPolicy features).

Review the sections below for details about the features and sample use cases along with Spinnaker API requests.

Launch Template Only Parameters

Review the sections below to determine which features you want to enable in the Spinnaker UI / Deck. Users will see enabled features as options when configuring a Server Group.

FeatureDescriptionDeck SettingClouddriver API Request ParameterRelease VersionDefault value in Spinnaker
IPv6ASGs associate an IPv6 address to their instances.enableIPv6associateIPv6Addressv1.21no default
IMDSv2Helps mitigate AWS credential theft from the exploitation of SSRF vulnerabilities in web applications. This is only supported by modern SDKs. Learn more from AWS.enableIMDSv2requireIMDSv2v1.21false
CreditSpecificationThe credit option for CPU usage of the instance. Valid for burstable performance EC2 instances only. Learn more from AWS.enableCpuCreditsunlimitedCpuCreditsv1.24default false used only when all instance types in request support bursting.

Additional Features

Enabling launch template support also unlocks additional features offered by Amazon EC2 Auto Scaling that facilitate diversified server groups:

  • Multiple instance types
  • Multiple purchase options (On-Demand / Spot) with proportion control
  • Allocation strategies
  • Capacity rebalancing

Follow AWS recommended best practices for EC2 Spot to improve your experience with EC2 Spot.

Motivation to diversify instances in your Server Group:

  • Reduce costs by diversifying instances across purchase options and Spot allocation strategies. See AWS docs to learn more about how to use Spot .
  • Reduce costs and optimize resources with instance weighting.
  • Enhance availability by deploying your application across multiple instance types running in multiple Availability Zones.
  • Enhance availability by proactively augmenting your fleet with a new Spot instance from an optimal pool, before a running instance is interrupted by EC2, by enabling capacity rebalance .
  • Reduce probability of InsufficientInstanceCapacity exceptions with flexible instance configuration.

Using one or more parameters in the table below will automatically create Server Groups with the instance diversification configuration specified, and will use AWS defaults for the parameters not specified. Note that a number of these parameters complement each other. So, combining them can greatly enhance your AWS experience.

CategoryFeature / Clouddriver API Request ParameterDescriptionAWS DefaultClouddriver Release VersionDeck SettingDeck Release Version
Multiple instance types with instance weighting and priority, with launch template overrides.

Properties overridden will replace the same properties in launch template.

AWS docs:
Instance Weighting
launchTemplateOverridesForInstanceType.instanceTypeInstance Type to overrideno defaultv1.26WIPWIP
launchTemplateOverridesForInstanceType.weightedCapacityThe number of capacity units for the specified instance type in terms of virtual CPUs, memory, storage, throughput, or other relative performance characteristic. The capacity units count toward the desired capacity.1
i.e. if no weighted capacity is specified, all instance types (large or small) are treated as the same weight.
launchTemplateOverridesForInstanceType.priorityOptional priority for instance type. Lower the number, higher the priority. If unset, the launch template override has the lowest priority.
The order of instance types in the list of launch template overrides sent to AWS is set from highest to lowest priority.

Valid values: integer > 0.
first to last in listv1.27WIPWIP
On-Demand

AWS docs:
Instance Diversification
onDemandAllocationStrategyIndicates how to allocate instance types to fulfill On-Demand capacity. The only valid value is prioritized.

This strategy uses the order of instance types in the launch template overrides to define the launch priority of each instance type. The first instance type in the list is prioritized higher than the last.
prioritizedv1.26
onDemandBaseCapacityThe minimum amount of the Server Group’s capacity that must be fulfilled by On-Demand Instances.

NOTE: If weights are specified for the instance types in the overrides, set the value of OnDemandBaseCapacity in terms of the number of capacity units, and not number of instances.
0
onDemandPercentageAboveBaseCapacityThe percentages of On-Demand Instances and Spot Instances for additional capacity beyond OnDemandBaseCapacity.100
i.e. only On-Demand instances
Spot

AWS docs:
Instance Diversification
ASG Capacity Rebalance
* EC2 Instance Rebalance Recommendations
spotAllocationStrategyIndicates how to allocate instances across Spot Instance pools. 2 strategies:
1) capacity-optimized (recommended): instances launched using Spot pools that are optimally chosen based on the available Spot capacity.
2) lowest-price: instances launched using Spot pools with the lowest price, and evenly allocated across the number of Spot pools specified in spotInstancePools.
lowest-price
spotInstancePoolsThe number of Spot Instance pools across which to allocate Spot Instances. The Spot pools are determined from the different instance types in the overrides. Only applicable with ‘lowest-price’ spotAllocationStrategy.2
spotPriceThe maximum price per unit hour that the user is willing to pay for a Spot Instance.On-Demand price for the configuration
capacityRebalanceEnable to allow Amazon EC2 Auto Scaling to attempt proactive replacement of Spot Instances in the server group that have received a rebalance recommendation (i.e. at elevated risk of interruption), before they are interrupted by AWS EC2. Note: Enabling this feature could exceed the server group’s max capacity for a brief period of time, leading to higher costs. Learn more in AWS docs.false
i.e. disabled
v1.27Advanced Settings > capcity rebalancev1.27

Use Cases & Sample API Requests

Create a Server Group with launch template

After enabling the launch template feature set is Clouddriver and/or Deck, set setLaunchTemplate to true in order to indicate Spinnaker to create your Server Group with an EC2 launch template.

  1. curl -H 'Content-Type: application/json' -d '{ "job": [
  2. {
  3. "type": "createServerGroup",
  4. "cloudProvider": "aws",
  5. "account": "my_aws_account",
  6. "application": "myAwsApp",
  7. "stack": "myStack",
  8. "credentials": "my_aws_account",
  9. "subnetType": "public-subnet",
  10. "availabilityZones": {"us-west-1": ["us-west-1a","us-west-1b","us-west-1c"]},
  11. "amiName": "ami-12345",
  12. "capacity": {"desired": 5,"max": 7,"min": 5},
  13. "iamRole":"BaseInstanceProfile",
  14. "instanceType":"t3.large",
  15. "setLaunchTemplate": true,
  16. "requireIMDSv2": true,
  17. "unlimitedCpuCredits": true
  18. }], "application": "myAwsApp", "description": "Create New Server Group in cluster myAwsApp"}' -X POST http://localhost:8084/tasks

Let’s say, the Server Group created was named myAwsApp-myStack-v005. It is backed by EC2 launch template with IMDSv2 enabled and unlimited CPU credits.

Convert a Server Group with launch template to use mixed instances policy, with multiple instance types and capacity weighting

The Spinnaker operation, modifyServerGroupLaunchTemplate/ updateLaunchTemplate also supports updating a Server Group backed by launch template to use mixed instances policy when one or more mixed instances policy parameters listed above is specified.

  1. curl -H 'Content-Type: application/json' -d '{ "job": [
  2. {
  3. "type": "updateLaunchTemplate",
  4. "cloudProvider": "aws",
  5. "account": "my_aws_account",
  6. "application": "myAwsApp",
  7. "stack": "myStack",
  8. "credentials": "my_aws_account",
  9. "region": "eu-central-1",
  10. "asgName": "myAwsApp-myStack-v005",
  11. "launchTemplateOverridesForInstanceType": [
  12. {"instanceType":"t2.large","weightedCapacity":"1"},
  13. {"instanceType":"t3.large","weightedCapacity":"1"},
  14. {"instanceType":"t2.xlarge","weightedCapacity":"2"},
  15. {"instanceType":"t3.xlarge","weightedCapacity":"2"}]
  16. }], "application": "myAwsApp", "description": "Modify Server Group in cluster myAwsApp"}' -X POST http://localhost:8084/tasks

Note: instance weighting is requested by vCPUs.

AWS docs:

Diversify instances in a Server Group across purchase options (On-Demand and Spot), multiple instance types with priority assignment:

  1. curl -H 'Content-Type: application/json' -d '{ "job": [
  2. {
  3. "type": "createServerGroup",
  4. "cloudProvider": "aws",
  5. "account": "my_aws_account",
  6. "application": "myAwsApp",
  7. "stack": "myStack",
  8. "credentials": "my_aws_account",
  9. "availabilityZones": {"us-west-1": ["us-west-1a","us-west-1b","us-west-1c"]},
  10. "amiName": "ami-12345",
  11. "capacity": {"desired": 5,"max": 7,"min": 5},
  12. "iamRole":"BaseInstanceProfile",
  13. "instanceType":"m4.large",
  14. "setLaunchTemplate": true,
  15. "onDemandBaseCapacity":1,
  16. "onDemandPercentageAboveBaseCapacity":50,
  17. "spotAllocationStrategy":"lowest-price",
  18. "spotInstancePools": 2,
  19. "launchTemplateOverridesForInstanceType": [
  20. {"instanceType":"m5.large","weightedCapacity":"1","priority": 2},
  21. {"instanceType":"m5.xlarge","weightedCapacity":"2","priority": 1}]
  22. }], "application": "myAwsApp", "description": "Create New Server Group in cluster myAwsApp"}' -X POST http://localhost:8084/tasks

See capacity type for instances in Deck:

Capacity Type On-Demand Capacity Type Spot

AWS docs:

The best practices followed in the example:

  • use multiple instance types
  • use capacity-optimized Spot allocation strategy to indicate AWS to provision instances from the most-available Spot capacity pools
  • use default maximum price for Spot i.e. On-Demand price
  • mix in previous generation instance types
  • use proactive capacity rebalancing (works best with capacity-optimized spotAllocationStrategy)
  1. curl -H 'Content-Type: application/json' -d '{ "job": [
  2. {
  3. "type": "createServerGroup",
  4. "cloudProvider": "aws",
  5. "account": "my_aws_account",
  6. "application": "myAwsApp",
  7. "stack": "myStack",
  8. "credentials": "my_aws_account",
  9. "subnetType": "public-subnet",
  10. "availabilityZones": {"us-west-1": ["us-west-1a","us-west-1b","us-west-1c"]},
  11. "amiName": "ami-12345",
  12. "capacity": {"desired": 5,"max": 7,"min": 5},
  13. "iamRole":"BaseInstanceProfile",
  14. "instanceType":"m4.large",
  15. "setLaunchTemplate": true,
  16. "onDemandPercentageAboveBaseCapacity":50,
  17. "onDemandBaseCapacity":1,
  18. "spotAllocationStrategy":"capacity-optimized",
  19. "capacityRebalance": true,
  20. "launchTemplateOverridesForInstanceType": [
  21. {"instanceType":"m4.large","weightedCapacity":"1"},
  22. {"instanceType":"m5.large","weightedCapacity":"1"},
  23. {"instanceType":"m4.xlarge","weightedCapacity":"2"},
  24. {"instanceType":"m5.xlarge","weightedCapacity":"2"}]
  25. }], "application": "myAwsApp", "description": "Create New Server Group in cluster myAwsApp"}' -X POST http://localhost:8084/tasks

Note: instance weighting requested by vCPUs

AWS docs:

Last modified December 22, 2021: Update launch-templates.md (#163) (cf2dd67)