AWS::AutoScaling::LaunchConfiguration
The AWS::AutoScaling::LaunchConfiguration
resource specifies the launch
configuration that can be used by an Auto Scaling group to configure Amazon EC2 instances.
When you update the launch configuration for an Auto Scaling group, CloudFormation deletes
that resource and creates a new launch configuration with the updated properties and a new
name. Existing instances are not affected. To update existing instances when you update the
AWS::AutoScaling::LaunchConfiguration
resource, you can specify an UpdatePolicy
attribute for the group. You can find sample update policies for rolling updates in
Configure Amazon EC2
Auto Scaling resources.
Note
Amazon EC2 Auto Scaling configures instances launched as part of an Auto Scaling group using either a launch template or a launch configuration. We strongly recommend that you do not use launch configurations. For more information, see Launch configurations in the Amazon EC2 Auto Scaling User Guide.
For help migrating from launch configurations to launch templates, see Migrate AWS CloudFormation stacks from launch configurations to launch templates in the Amazon EC2 Auto Scaling User Guide.
Syntax
To declare this entity in your AWS CloudFormation template, use the following syntax:
JSON
{ "Type" : "AWS::AutoScaling::LaunchConfiguration", "Properties" : { "AssociatePublicIpAddress" :
Boolean
, "BlockDeviceMappings" :[ BlockDeviceMapping, ... ]
, "ClassicLinkVPCId" :String
, "ClassicLinkVPCSecurityGroups" :[ String, ... ]
, "EbsOptimized" :Boolean
, "IamInstanceProfile" :String
, "ImageId" :String
, "InstanceId" :String
, "InstanceMonitoring" :Boolean
, "InstanceType" :String
, "KernelId" :String
, "KeyName" :String
, "LaunchConfigurationName" :String
, "MetadataOptions" :MetadataOptions
, "PlacementTenancy" :String
, "RamDiskId" :String
, "SecurityGroups" :[ String, ... ]
, "SpotPrice" :String
, "UserData" :String
} }
YAML
Type: AWS::AutoScaling::LaunchConfiguration Properties: AssociatePublicIpAddress:
Boolean
BlockDeviceMappings:- BlockDeviceMapping
ClassicLinkVPCId:String
ClassicLinkVPCSecurityGroups:- String
EbsOptimized:Boolean
IamInstanceProfile:String
ImageId:String
InstanceId:String
InstanceMonitoring:Boolean
InstanceType:String
KernelId:String
KeyName:String
LaunchConfigurationName:String
MetadataOptions:MetadataOptions
PlacementTenancy:String
RamDiskId:String
SecurityGroups:- String
SpotPrice:String
UserData:String
Properties
AssociatePublicIpAddress
-
Specifies whether to assign a public IPv4 address to the group's instances. If the instance is launched into a default subnet, the default is to assign a public IPv4 address, unless you disabled the option to assign a public IPv4 address on the subnet. If the instance is launched into a nondefault subnet, the default is not to assign a public IPv4 address, unless you enabled the option to assign a public IPv4 address on the subnet.
If you specify
true
, each instance in the Auto Scaling group receives a unique public IPv4 address. For more information, see Provide network connectivity for your Auto Scaling instances using Amazon VPC in the Amazon EC2 Auto Scaling User Guide.If you specify this property, you must specify at least one subnet for
VPCZoneIdentifier
when you create your group.Required: No
Type: Boolean
Update requires: Replacement
BlockDeviceMappings
-
The block device mapping entries that define the block devices to attach to the instances at launch. By default, the block devices specified in the block device mapping for the AMI are used. For more information, see Block device mappings in the Amazon EC2 User Guide for Linux Instances.
Required: No
Type: Array of BlockDeviceMapping
Update requires: Replacement
ClassicLinkVPCId
-
Available for backward compatibility.
Required: No
Type: String
Update requires: Replacement
ClassicLinkVPCSecurityGroups
-
Available for backward compatibility.
Required: Conditional
Type: Array of String
Update requires: Replacement
EbsOptimized
-
Specifies whether the launch configuration is optimized for EBS I/O (
true
) or not (false
). The optimization provides dedicated throughput to Amazon EBS and an optimized configuration stack to provide optimal I/O performance. This optimization is not available with all instance types. Additional fees are incurred when you enable EBS optimization for an instance type that is not EBS-optimized by default. For more information, see Amazon EBS-optimized instances in the Amazon EC2 User Guide for Linux Instances.The default value is
false
.Required: No
Type: Boolean
Update requires: Replacement
IamInstanceProfile
-
The name or the Amazon Resource Name (ARN) of the instance profile associated with the IAM role for the instance. The instance profile contains the IAM role. For more information, see IAM role for applications that run on Amazon EC2 instances in the Amazon EC2 Auto Scaling User Guide.
Required: No
Type: String
Update requires: Replacement
ImageId
-
The ID of the Amazon Machine Image (AMI) that was assigned during registration. For more information, see Find a Linux AMI in the Amazon EC2 User Guide for Linux Instances.
If you specify
InstanceId
, anImageId
is not required.Required: Conditional
Type: String
Update requires: Replacement
InstanceId
-
The ID of the Amazon EC2 instance to use to create the launch configuration. When you use an instance to create a launch configuration, all properties are derived from the instance with the exception of
BlockDeviceMapping
andAssociatePublicIpAddress
. You can override any properties from the instance by specifying them in the launch configuration.Required: No
Type: String
Update requires: Replacement
InstanceMonitoring
-
Controls whether instances in this group are launched with detailed (
true
) or basic (false
) monitoring.The default value is
true
(enabled).Important
When detailed monitoring is enabled, Amazon CloudWatch generates metrics every minute and your account is charged a fee. When you disable detailed monitoring, CloudWatch generates metrics every 5 minutes. For more information, see Configure monitoring for Auto Scaling instances in the Amazon EC2 Auto Scaling User Guide.
Required: No
Type: Boolean
Update requires: Replacement
InstanceType
-
Specifies the instance type of the EC2 instance. For information about available instance types, see Available instance types in the Amazon EC2 User Guide for Linux Instances.
If you specify
InstanceId
, anInstanceType
is not required.Required: Conditional
Type: String
Update requires: Replacement
KernelId
-
The ID of the kernel associated with the AMI.
Note
We recommend that you use PV-GRUB instead of kernels and RAM disks. For more information, see User provided kernels in the Amazon EC2 User Guide for Linux Instances.
Required: No
Type: String
Update requires: Replacement
KeyName
-
The name of the key pair. For more information, see Amazon EC2 key pairs and Amazon EC2 instances in the Amazon EC2 User Guide for Linux Instances.
Required: No
Type: String
Update requires: Replacement
LaunchConfigurationName
-
The name of the launch configuration. This name must be unique per Region per account.
Required: No
Type: String
Minimum:
1
Maximum:
255
Update requires: Replacement
MetadataOptions
-
The metadata options for the instances. For more information, see Configure the instance metadata options in the Amazon EC2 Auto Scaling User Guide.
Required: No
Type: MetadataOptions
Update requires: Replacement
PlacementTenancy
-
The tenancy of the instance, either
default
ordedicated
. An instance withdedicated
tenancy runs on isolated, single-tenant hardware and can only be launched into a VPC. To launch dedicated instances into a shared tenancy VPC (a VPC with the instance placement tenancy attribute set todefault
), you must set the value of this property todedicated
.If you specify
PlacementTenancy
, you must specify at least one subnet forVPCZoneIdentifier
when you create your group.Valid values:
default
|dedicated
Required: No
Type: String
Update requires: Replacement
RamDiskId
-
The ID of the RAM disk to select.
Note
We recommend that you use PV-GRUB instead of kernels and RAM disks. For more information, see User provided kernels in the Amazon EC2 User Guide for Linux Instances.
Required: No
Type: String
Update requires: Replacement
SecurityGroups
-
A list that contains the security groups to assign to the instances in the Auto Scaling group. The list can contain both the IDs of existing security groups and references to SecurityGroup resources created in the template.
For more information, see Control traffic to resources using security groups in the Amazon Virtual Private Cloud User Guide.
Required: No
Type: Array of String
Update requires: Replacement
SpotPrice
-
The maximum hourly price to be paid for any Spot Instance launched to fulfill the request. Spot Instances are launched when the price you specify exceeds the current Spot price. For more information, see Request Spot Instances for fault-tolerant and flexible applications in the Amazon EC2 Auto Scaling User Guide.
Valid Range: Minimum value of 0.001
Note
When you change your maximum price by creating a new launch configuration, running instances will continue to run as long as the maximum price for those running instances is higher than the current Spot price.
Required: No
Type: String
Update requires: Replacement
UserData
-
The Base64-encoded user data to make available to the launched EC2 instances. For more information, see Instance metadata and user data in the Amazon EC2 User Guide for Linux Instances.
Required: No
Type: String
Maximum:
21847
Update requires: Replacement
Return values
Ref
When you pass the logical ID of this resource to the intrinsic Ref
function, Ref
returns the resource name. For example:
mystack-mylaunchconfig-1DDYF1E3B3I
.
For more information about using the Ref
function, see Ref
.
Remarks
CloudFormation marks the Auto Scaling group as successful (by setting its status to
CREATE_COMPLETE) when its desired capacity is reached. However, if SpotPrice
is
set in the launch configuration, then desired capacity is not used as a criteria for
success. Whether your request is fulfilled depends on Spot Instance capacity and your
maximum price. If the current Spot price is less than your specified maximum price, Amazon
EC2 Auto Scaling uses the desired capacity as the target capacity for the group. If the
request for Spot Instances is unsuccessful, it keeps trying.
If your Auto Scaling instances receive a public IPv4 address and are launched in a VPC that is defined in the same stack template, you must use the DependsOn attribute to declare a dependency on the VPC-gateway attachment.
Examples
The following examples create launch configurations that can be used by an Auto Scaling group to configure Amazon EC2 instances.
Amazon EBS-backed AMI and defined block device mappings
This example shows a launch configuration with a BlockDeviceMappings
property that lists two devices: a 30 gigabyte EBS root volume mapped to /dev/sda1 and a
100 gigabyte EBS volume mapped to /dev/sdm. The /dev/sdm volume uses the default EBS
volume type based on the region and is not deleted when terminating the instance it is
attached to.
CloudFormation supports parameters from the AWS Systems Manager
Parameter Store. In this example, the ImageId
property references the latest
Amazon Linux 2 AMI (EBS-backed image) from the Parameter Store. For more information, see
AWS Systems Manager Parameter Store in the
AWS Systems Manager User Guide and the blog post Query for the latest Amazon Linux AMI IDs using AWS Systems Manager
Parameter Store
JSON
{ "AWSTemplateFormatVersion": "2010-09-09", "Parameters": { "LatestAmiId": { "Description": "Region specific image from the Parameter Store", "Type": "AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>", "Default": "/aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2" }, "InstanceType": { "Description": "Amazon EC2 instance type for the instances", "Type": "String", "AllowedValues": [ "t3.micro", "t3.small", "t3.medium" ], "Default": "t3.micro" } }, "Resources":{ "myLaunchConfig":{ "Type":"AWS::AutoScaling::LaunchConfiguration", "Properties":{ "ImageId":{ "Ref":"LatestAmiId" }, "SecurityGroups":[ { "Ref":"myEC2SecurityGroup" } ], "InstanceType":{ "Ref":"InstanceType" }, "BlockDeviceMappings":[ { "DeviceName":"/dev/sda1", "Ebs":{ "VolumeSize":"30", "VolumeType":"gp3" } }, { "DeviceName":"/dev/sdm", "Ebs":{ "VolumeSize":"100", "DeleteOnTermination":"false" } } ] } } } }
YAML
--- AWSTemplateFormatVersion: 2010-09-09 Parameters: LatestAmiId: Description: Region specific image from the Parameter Store Type: 'AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>' Default: '/aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2' InstanceType: Description: Amazon EC2 instance type for the instances Type: String AllowedValues: - t3.micro - t3.small - t3.medium Default: t3.micro Resources: myLaunchConfig: Type: AWS::AutoScaling::LaunchConfiguration Properties: ImageId: !Ref LatestAmiId SecurityGroups: - !Ref myEC2SecurityGroup InstanceType: !Ref InstanceType BlockDeviceMappings: - DeviceName: /dev/sda1 Ebs: VolumeSize: '30' VolumeType: gp3 - DeviceName: /dev/sdm Ebs: VolumeSize: '100' DeleteOnTermination: false
Instance store-backed AMI with Spot price and IAM role
This example shows a launch configuration that launches Spot Instances in the Auto
Scaling group. This launch configuration will only be active if the current Spot price is
less than the price in the template specification (0.045). It also demonstrates a launch
configuration that uses the IamInstanceProfile
property. For an example of a
full template, including the definition of, and further references from the InstanceProfile object referenced here as RootInstanceProfile
, see
auto_scaling_with_instance_profile.template
In this example, the ImageId
property references the latest Amazon Linux
AMI (instance store/S3-backed image) from the Parameter Store. The BlockDeviceMappings
property lists a virtual device ephemeral0
mapped to /dev/sdc.
JSON
{ "AWSTemplateFormatVersion": "2010-09-09", "Parameters": { "LatestAmiId": { "Description": "Region specific image from the Parameter Store", "Type": "AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>", "Default": "/aws/service/ami-amazon-linux-latest/amzn-ami-hvm-x86_64-s3" } }, "Resources":{ "myLaunchConfig":{ "Type":"AWS::AutoScaling::LaunchConfiguration", "Properties":{ "ImageId":{ "Ref":"LatestAmiId" }, "SecurityGroups":[ { "Ref":"myEC2SecurityGroup" } ], "InstanceType":"m3.medium", "SpotPrice":"0.045", "IamInstanceProfile":{ "Ref":"RootInstanceProfile" }, "BlockDeviceMappings": [ { "DeviceName": "/dev/sdc", "VirtualName": "ephemeral0" } ] } } } }
YAML
--- AWSTemplateFormatVersion: 2010-09-09 Parameters: LatestAmiId: Description: Region specific image from the Parameter Store Type: 'AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>' Default: '/aws/service/ami-amazon-linux-latest/amzn-ami-hvm-x86_64-s3' Resources: myLaunchConfig: Type: AWS::AutoScaling::LaunchConfiguration Properties: ImageId: !Ref LatestAmiId SecurityGroups: - !Ref myEC2SecurityGroup InstanceType: m3.medium SpotPrice: '0.045' IamInstanceProfile: !Ref RootInstanceProfile BlockDeviceMappings: - DeviceName: /dev/sdc VirtualName: ephemeral0
Provisioned IOPS EBS-optimized volume with key-pair name and user data
This example demonstrates a launch configuration that configures the
EbsOptmized
property to launch instances with a provisioned IOPS
EBS-optimized volume. This can increase the performance of your EBS-backed
instances.
Note
For instances that are not EBS–optimized by default, you must enable EBS optimization to achieve the level of performance described in the Amazon EBS-optimized instances documentation in the Amazon Elastic Compute Cloud User Guide. For current generation instance types, EBS-optimization is enabled by default at no additional cost. Enabling EBS optimization for a previous generation instance type that is not EBS-optimized by default incurs additional fees.
When you use a launch configuration such as this one, your m1.large
instances will contain optimized EBS root volumes with the provisioned IOPS settings that
you specified in the AMI. Because you cannot specify the IOPS settings in a launch
configuration, the AMI must be configured with a block device mapping that specifies the
desired number of IOPS. The following are key attributes of this EBS-optimized instance
configuration:
-
An instance type of
m1.large
or greater. This is required for EBS optimization. This optimization is only available for certain instance types and sizes. -
An EBS-backed AMI with a volume type of
io1
and the number of IOPS you want to provision for the volume. -
The size of the EBS volume must accommodate the IOPS you need. There is a 50:1 ratio between IOPS and Gibibytes (GiB) of storage.
For more information about IOPS performance with provisioned IOPS volumes, see Provisioned IOPS
SSD (io1
and io2
) volumes in the Amazon
Elastic Compute Cloud User Guide.
For more performance tips, see Amazon EBS volume performance on Linux instances in the Amazon Elastic Compute Cloud User Guide.
JSON
{ "Resources":{ "myLaunchConfig":{ "Type":"AWS::AutoScaling::LaunchConfiguration", "Properties":{ "ImageId":"ami-02354e95b3example", "SecurityGroups":[ { "Ref":"myEC2SecurityGroup" }, "myExistingEC2SecurityGroup" ], "InstanceType":"m1.large", "UserData": {"Fn::Base64": {"Fn::Join": ["", [ "#!/bin/bash -x\n", "/opt/aws/bin/cfn-signal -e $? --stack ", {"Ref": "AWS::StackName"}, " --resource myASG ", " --region ", {"Ref": "AWS::Region"}, "\n" ]]}}, "EbsOptimized":"true" } } } }
YAML
--- Resources: myLaunchConfig: Type: AWS::AutoScaling::LaunchConfiguration Properties: ImageId: ami-02354e95b3example SecurityGroups: - !Ref myEC2SecurityGroup - myExistingEC2SecurityGroup InstanceType: m1.large UserData: !Base64 | #!/bin/bash -x yum install -y aws-cfn-bootstrap /opt/aws/bin/cfn-signal -e $? --stack !Ref 'AWS::StackName' --resource myASG --region !Ref 'AWS::Region' EbsOptimized: true
See also
-
You can find additional useful snippets in the following sections of the AWS CloudFormation User Guide:
-
For examples of Auto Scaling groups, see Configure Amazon EC2 Auto Scaling resources.
-
For examples of launch templates, see Create launch templates.
-
-
Migrate AWS CloudFormation stacks from launch configurations to launch templates in the Amazon EC2 Auto Scaling User Guide
-
CreateLaunchConfiguration in the Amazon EC2 Auto Scaling API Reference