AWS Amazon EC2 Auto Scaling Configuration
This page shows how to write Terraform and CloudFormation for Amazon EC2 Auto Scaling Configuration and write them securely.
aws_launch_configuration (Terraform)
The Configuration in Amazon EC2 Auto Scaling can be configured in Terraform with the resource name aws_launch_configuration. The following sections describe 1 example of how to use the resource and its parameters.
Example Usage from GitHub
resource "aws_launch_configuration" "ngx_plus" {
name = "ngx-plus"
image_id = data.aws_ami.ngx_plus.id
instance_type = var.machine_type
key_name = var.key_name
security_groups = [
Security Best Practices for aws_launch_configuration
There are 2 settings in aws_launch_configuration that should be taken care of for security reasons. The following section explain an overview and example code.
Check public IPs should be given to Auto Scaling instances
It is better to block public access on the Internet to them. It is better to avoid associating public IP addresses if this is unintentional.
Ensure to enable at rest encryption of Auto Scaling
It is better to enable at rest encryption of Auto Scaling. Device encryption reduces the risk of data leakage.
Parameters
-
arnoptional computed - string -
associate_public_ip_addressoptional - bool -
ebs_optimizedoptional computed - bool -
enable_monitoringoptional - bool -
iam_instance_profileoptional - string -
idoptional computed - string -
image_idrequired - string -
instance_typerequired - string -
key_nameoptional computed - string -
nameoptional computed - string -
name_prefixoptional - string -
placement_tenancyoptional - string -
security_groupsoptional - set of string -
spot_priceoptional - string -
user_dataoptional - string -
user_data_base64optional - string -
vpc_classic_link_idoptional - string -
vpc_classic_link_security_groupsoptional - set of string -
ebs_block_deviceset block-
delete_on_terminationoptional - bool -
device_namerequired - string -
encryptedoptional computed - bool -
iopsoptional computed - number -
no_deviceoptional - bool -
snapshot_idoptional computed - string -
volume_sizeoptional computed - number -
volume_typeoptional computed - string
-
-
ephemeral_block_deviceset block-
device_namerequired - string -
virtual_namerequired - string
-
-
metadata_optionslist block-
http_endpointoptional computed - string -
http_put_response_hop_limitoptional computed - number -
http_tokensoptional computed - string
-
-
root_block_devicelist block-
delete_on_terminationoptional - bool -
encryptedoptional computed - bool -
iopsoptional computed - number -
volume_sizeoptional computed - number -
volume_typeoptional computed - string
-
Explanation in Terraform Registry
Provides a resource to create a new launch configuration, used for autoscaling groups.
AWS::AutoScaling::LaunchConfiguration (CloudFormation)
The LaunchConfiguration in AutoScaling can be configured in CloudFormation with the resource name AWS::AutoScaling::LaunchConfiguration. The following sections describe how to use the resource and its parameters.
Example Usage from GitHub
An example could not be found in GitHub.
Parameters
-
AssociatePublicIpAddressoptional - Boolean -
BlockDeviceMappingsoptional - List of BlockDeviceMapping -
ClassicLinkVPCIdoptional - String -
ClassicLinkVPCSecurityGroupsoptional - List -
EbsOptimizedoptional - Boolean -
IamInstanceProfileoptional - String -
ImageIdrequired - String -
InstanceIdoptional - String -
InstanceMonitoringoptional - Boolean -
InstanceTyperequired - String -
KernelIdoptional - String -
KeyNameoptional - String -
LaunchConfigurationNameoptional - String -
MetadataOptionsoptional - MetadataOptions -
PlacementTenancyoptional - String -
RamDiskIdoptional - String -
SecurityGroupsoptional - List -
SpotPriceoptional - String -
UserDataoptional - String
Explanation in CloudFormation Registry
The
AWS::AutoScaling::LaunchConfigurationresource 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 theAWS::AutoScaling::LaunchConfigurationresource, you can specify an UpdatePolicy attribute for the group. You can find sample update policies for rolling updates in Auto scaling template snippets. For more information, see CreateLaunchConfiguration in the Amazon EC2 Auto Scaling API Reference and Launch configurations in the Amazon EC2 Auto Scaling User Guide.Note To configure Amazon EC2 instances launched as part of the Auto Scaling group, you can specify a launch template or a launch configuration. We recommend that you use a launch template to make sure that you can use the latest features of Amazon EC2, such as Dedicated Hosts and T2 Unlimited instances. For more information, see Creating a launch template for an Auto Scaling group.
Frequently asked questions
What is AWS Amazon EC2 Auto Scaling Configuration?
AWS Amazon EC2 Auto Scaling Configuration is a resource for Amazon EC2 Auto Scaling of Amazon Web Service. Settings can be wrote in Terraform and CloudFormation.
Where can I find the example code for the AWS Amazon EC2 Auto Scaling Configuration?
For Terraform, the jpouyaud-perso/aws-nlb-ha-sni-routing-asg source code example is useful. See the Terraform Example section for further details.