create_auto_scaling_group
¶
create_auto_scaling_group(
*,
config_overrides: Optional[AutoScalingClientConfig] = None,
auto_scaling_group_name: Optional[XmlStringMaxLen255] = None,
launch_configuration_name: Optional[XmlStringMaxLen255] = None,
launch_template: Optional[LaunchTemplateSpecification] = None,
mixed_instances_policy: Optional[MixedInstancesPolicy] = None,
instance_id: Optional[XmlStringMaxLen19] = None,
min_size: Optional[AutoScalingGroupMinSize] = None,
max_size: Optional[AutoScalingGroupMaxSize] = None,
desired_capacity: Optional[AutoScalingGroupDesiredCapacity] = None,
default_cooldown: Optional[Cooldown] = None,
availability_zones: Optional[AvailabilityZones] = None,
availability_zone_ids: Optional[AvailabilityZoneIds] = None,
load_balancer_names: Optional[LoadBalancerNames] = None,
target_group_ar_ns: Optional[TargetGroupARNs] = None,
health_check_type: Optional[XmlStringMaxLen32] = None,
health_check_grace_period: Optional[HealthCheckGracePeriod] = None,
placement_group: Optional[XmlStringMaxLen255] = None,
vpc_zone_identifier: Optional[XmlStringMaxLen5000] = None,
termination_policies: Optional[TerminationPolicies] = None,
new_instances_protected_from_scale_in: Optional[InstanceProtected] = None,
capacity_rebalance: Optional[CapacityRebalanceEnabled] = None,
lifecycle_hook_specification_list: Optional[LifecycleHookSpecifications] = None,
deletion_protection: Optional[DeletionProtection] = None,
tags: Optional[Tags] = None,
service_linked_role_arn: Optional[ResourceName] = None,
max_instance_lifetime: Optional[MaxInstanceLifetime] = None,
context: Optional[Context] = None,
desired_capacity_type: Optional[XmlStringMaxLen255] = None,
default_instance_warmup: Optional[DefaultInstanceWarmup] = None,
traffic_sources: Optional[TrafficSources] = None,
instance_maintenance_policy: Optional[InstanceMaintenancePolicy] = None,
availability_zone_distribution: Optional[AvailabilityZoneDistribution] = None,
availability_zone_impairment_policy: Optional[
AvailabilityZoneImpairmentPolicy
] = None,
skip_zonal_shift_validation: Optional[SkipZonalShiftValidation] = None,
capacity_reservation_specification: Optional[
CapacityReservationSpecification
] = None,
instance_lifecycle_policy: Optional[InstanceLifecyclePolicy] = None,
operator: Optional[Operator] = None,
) -> None
We strongly recommend using a launch template when calling this operation to ensure full functionality for Amazon EC2 Auto Scaling and Amazon EC2.
Creates an Auto Scaling group with the specified name and attributes.
If you exceed your maximum limit of Auto Scaling groups, the call fails. To query this limit, call the DescribeAccountLimits API. For information about updating this limit, see Quotas for Amazon EC2 Auto Scaling in the Amazon EC2 Auto Scaling User Guide.
If you're new to Amazon EC2 Auto Scaling, see the introductory tutorials in Get started with Amazon EC2 Auto Scaling in the Amazon EC2 Auto Scaling User Guide.
Every Auto Scaling group has three size properties (DesiredCapacity, MaxSize, and MinSize). Usually, you set these sizes based on a specific number of instances. However, if you configure a mixed instances policy that defines weights for the instance types, you must specify these sizes with the same units that you use for weighting instances.
Parameters:
-
auto_scaling_group_name(Optional[XmlStringMaxLen255], default:None) –The name of the Auto Scaling group. This name must be unique per Region per account.
The name can contain any ASCII character 33 to 126 including most punctuation characters, digits, and upper and lowercased letters.
You cannot use a colon (:) in the name.
-
launch_configuration_name(Optional[XmlStringMaxLen255], default:None) –The name of the launch configuration to use to launch instances.
Conditional: You must specify either a launch template (
LaunchTemplateorMixedInstancesPolicy) or a launch configuration (LaunchConfigurationNameorInstanceId). -
launch_template(Optional[LaunchTemplateSpecification], default:None) –Information used to specify the launch template and version to use to launch instances.
Conditional: You must specify either a launch template (
LaunchTemplateorMixedInstancesPolicy) or a launch configuration (LaunchConfigurationNameorInstanceId).The launch template that is specified must be configured for use with an Auto Scaling group. For more information, see Create a launch template for an Auto Scaling group in the Amazon EC2 Auto Scaling User Guide.
-
mixed_instances_policy(Optional[MixedInstancesPolicy], default:None) –The mixed instances policy. For more information, see Auto Scaling groups with multiple instance types and purchase options in the Amazon EC2 Auto Scaling User Guide. To learn how to prioritize multiple capacity types, see Use Distribution Segments to target multiple capacity types in the Amazon EC2 Auto Scaling User Guide.
-
instance_id(Optional[XmlStringMaxLen19], default:None) –The ID of the instance used to base the launch configuration on. If specified, Amazon EC2 Auto Scaling uses the configuration values from the specified instance to create a new launch configuration. To get the instance ID, use the Amazon EC2 DescribeInstances API operation. For more information, see Create an Auto Scaling group using parameters from an existing instance in the Amazon EC2 Auto Scaling User Guide.
-
min_size(Optional[AutoScalingGroupMinSize], default:None) –The minimum size of the group.
-
max_size(Optional[AutoScalingGroupMaxSize], default:None) –The maximum size of the group.
With a mixed instances policy that uses instance weighting, Amazon EC2 Auto Scaling may need to go above
MaxSizeto meet your capacity requirements. In this event, Amazon EC2 Auto Scaling will never go aboveMaxSizeby more than your largest instance weight (weights that define how many units each instance contributes to the desired capacity of the group). -
desired_capacity(Optional[AutoScalingGroupDesiredCapacity], default:None) –The desired capacity is the initial capacity of the Auto Scaling group at the time of its creation and the capacity it attempts to maintain. It can scale beyond this capacity if you configure auto scaling. This number must be greater than or equal to the minimum size of the group and less than or equal to the maximum size of the group. If you do not specify a desired capacity, the default is the minimum size of the group.
-
default_cooldown(Optional[Cooldown], default:None) –Only needed if you use simple scaling policies.
The amount of time, in seconds, between one scaling activity ending and another one starting due to simple scaling policies. For more information, see Scaling cooldowns for Amazon EC2 Auto Scaling in the Amazon EC2 Auto Scaling User Guide.
Default:
300seconds -
availability_zones(Optional[AvailabilityZones], default:None) –A list of Availability Zones where instances in the Auto Scaling group can be created. Used for launching into the default VPC subnet in each Availability Zone when not using the
VPCZoneIdentifierproperty, or for attaching a network interface when an existing network interface ID is specified in a launch template. -
availability_zone_ids(Optional[AvailabilityZoneIds], default:None) –A list of Availability Zone IDs where the Auto Scaling group can launch instances. You cannot specify both AvailabilityZones and AvailabilityZoneIds in the same request.
-
load_balancer_names(Optional[LoadBalancerNames], default:None) –A list of Classic Load Balancers associated with this Auto Scaling group. For Application Load Balancers, Network Load Balancers, and Gateway Load Balancers, specify the
TargetGroupARNsproperty instead. -
target_group_ar_ns(Optional[TargetGroupARNs], default:None) –The Amazon Resource Names (ARN) of the Elastic Load Balancing target groups to associate with the Auto Scaling group. Instances are registered as targets with the target groups. The target groups receive incoming traffic and route requests to one or more registered targets. For more information, see Use Elastic Load Balancing to distribute traffic across the instances in your Auto Scaling group in the Amazon EC2 Auto Scaling User Guide.
-
health_check_type(Optional[XmlStringMaxLen32], default:None) –A comma-separated value string of one or more health check types.
The valid values are
EC2,EBS,ELB, andVPC_LATTICE.EC2is the default health check and cannot be disabled. For more information, see Health checks for instances in an Auto Scaling group in the Amazon EC2 Auto Scaling User Guide.Only specify
EC2if you must clear a value that was previously set. -
health_check_grace_period(Optional[HealthCheckGracePeriod], default:None) –The amount of time, in seconds, that Amazon EC2 Auto Scaling waits before checking the health status of an EC2 instance that has come into service and marking it unhealthy due to a failed health check. This is useful if your instances do not immediately pass their health checks after they enter the
InServicestate. For more information, see Set the health check grace period for an Auto Scaling group in the Amazon EC2 Auto Scaling User Guide.Default:
0seconds -
placement_group(Optional[XmlStringMaxLen255], default:None) –The name of the placement group into which to launch your instances. For more information, see Placement groups in the Amazon EC2 User Guide.
A cluster placement group is a logical grouping of instances within a single Availability Zone. You cannot specify multiple Availability Zones and a cluster placement group.
-
vpc_zone_identifier(Optional[XmlStringMaxLen5000], default:None) –A comma-separated list of subnet IDs for a virtual private cloud (VPC) where instances in the Auto Scaling group can be created. If you specify
VPCZoneIdentifierwithAvailabilityZones, the subnets that you specify must reside in those Availability Zones. -
termination_policies(Optional[TerminationPolicies], default:None) –A policy or a list of policies that are used to select the instance to terminate. These policies are executed in the order that you list them. For more information, see Configure termination policies for Amazon EC2 Auto Scaling in the Amazon EC2 Auto Scaling User Guide.
Valid values:
Default|AllocationStrategy|ClosestToNextInstanceHour|NewestInstance|OldestInstance|OldestLaunchConfiguration|OldestLaunchTemplate|arn:aws:lambda:region:account-id:function:my-function:my-alias -
new_instances_protected_from_scale_in(Optional[InstanceProtected], default:None) –Indicates whether newly launched instances are protected from termination by Amazon EC2 Auto Scaling when scaling in. For more information about preventing instances from terminating on scale in, see Use instance scale-in protection in the Amazon EC2 Auto Scaling User Guide.
-
capacity_rebalance(Optional[CapacityRebalanceEnabled], default:None) –Indicates whether Capacity Rebalancing is enabled. Otherwise, Capacity Rebalancing is disabled. When you turn on Capacity Rebalancing, Amazon EC2 Auto Scaling attempts to launch a Spot Instance whenever Amazon EC2 notifies that a Spot Instance is at an elevated risk of interruption. After launching a new instance, it then terminates an old instance. For more information, see Use Capacity Rebalancing to handle Amazon EC2 Spot Interruptions in the in the Amazon EC2 Auto Scaling User Guide.
-
lifecycle_hook_specification_list(Optional[LifecycleHookSpecifications], default:None) –One or more lifecycle hooks to add to the Auto Scaling group before instances are launched.
-
deletion_protection(Optional[DeletionProtection], default:None) –The deletion protection setting for the Auto Scaling group. This setting helps safeguard your Auto Scaling group and its instances by controlling whether the
DeleteAutoScalingGroupoperation is allowed. When deletion protection is enabled, users cannot delete the Auto Scaling group according to the specified protection level until the setting is changed back to a less restrictive level.The valid values are
none,prevent-force-deletion, andprevent-all-deletion.Default:
noneFor more information, see Configure deletion protection for your Amazon EC2 Auto Scaling resources in the Amazon EC2 Auto Scaling User Guide.
-
tags(Optional[Tags], default:None) –One or more tags. You can tag your Auto Scaling group and propagate the tags to the Amazon EC2 instances it launches. Tags are not propagated to Amazon EBS volumes. To add tags to Amazon EBS volumes, specify the tags in a launch template but use caution. If the launch template specifies an instance tag with a key that is also specified for the Auto Scaling group, Amazon EC2 Auto Scaling overrides the value of that instance tag with the value specified by the Auto Scaling group. For more information, see Tag Auto Scaling groups and instances in the Amazon EC2 Auto Scaling User Guide.
-
service_linked_role_arn(Optional[ResourceName], default:None) –The Amazon Resource Name (ARN) of the service-linked role that the Auto Scaling group uses to call other Amazon Web Services service on your behalf. By default, Amazon EC2 Auto Scaling uses a service-linked role named
AWSServiceRoleForAutoScaling, which it creates if it does not exist. For more information, see Service-linked roles in the Amazon EC2 Auto Scaling User Guide. -
max_instance_lifetime(Optional[MaxInstanceLifetime], default:None) –The maximum amount of time, in seconds, that an instance can be in service. The default is null. If specified, the value must be either 0 or a number equal to or greater than 86,400 seconds (1 day). For more information, see Replace Auto Scaling instances based on maximum instance lifetime in the Amazon EC2 Auto Scaling User Guide.
-
context(Optional[Context], default:None) –Reserved.
-
desired_capacity_type(Optional[XmlStringMaxLen255], default:None) –The unit of measurement for the value specified for desired capacity. Amazon EC2 Auto Scaling supports
DesiredCapacityTypefor attribute-based instance type selection only. For more information, see Create a mixed instances group using attribute-based instance type selection in the Amazon EC2 Auto Scaling User Guide.By default, Amazon EC2 Auto Scaling specifies
units, which translates into number of instances.Valid values:
units|vcpu|memory-mib -
default_instance_warmup(Optional[DefaultInstanceWarmup], default:None) –The amount of time, in seconds, until a new instance is considered to have finished initializing and resource consumption to become stable after it enters the
InServicestate.During an instance refresh, Amazon EC2 Auto Scaling waits for the warm-up period after it replaces an instance before it moves on to replacing the next instance. Amazon EC2 Auto Scaling also waits for the warm-up period before aggregating the metrics for new instances with existing instances in the Amazon CloudWatch metrics that are used for scaling, resulting in more reliable usage data. For more information, see Set the default instance warmup for an Auto Scaling group in the Amazon EC2 Auto Scaling User Guide.
To manage various warm-up settings at the group level, we recommend that you set the default instance warmup, even if it is set to 0 seconds. To remove a value that you previously set, include the property but specify
-1for the value. However, we strongly recommend keeping the default instance warmup enabled by specifying a value of0or other nominal value.Default: None
-
traffic_sources(Optional[TrafficSources], default:None) –The list of traffic sources to attach to this Auto Scaling group. You can use any of the following as traffic sources for an Auto Scaling group: Classic Load Balancer, Application Load Balancer, Gateway Load Balancer, Network Load Balancer, and VPC Lattice.
-
instance_maintenance_policy(Optional[InstanceMaintenancePolicy], default:None) –An instance maintenance policy. For more information, see Set instance maintenance policy in the Amazon EC2 Auto Scaling User Guide.
-
availability_zone_distribution(Optional[AvailabilityZoneDistribution], default:None) –The instance capacity distribution across Availability Zones.
-
availability_zone_impairment_policy(Optional[AvailabilityZoneImpairmentPolicy], default:None) –The policy for Availability Zone impairment.
-
skip_zonal_shift_validation(Optional[SkipZonalShiftValidation], default:None) –If you enable zonal shift with cross-zone disabled load balancers, capacity could become imbalanced across Availability Zones. To skip the validation, specify
true. For more information, see Auto Scaling group zonal shift in the Amazon EC2 Auto Scaling User Guide. -
capacity_reservation_specification(Optional[CapacityReservationSpecification], default:None) –The capacity reservation specification for the Auto Scaling group.
-
instance_lifecycle_policy(Optional[InstanceLifecyclePolicy], default:None) –The instance lifecycle policy for the Auto Scaling group. This policy controls instance behavior when an instance transitions through its lifecycle states. Configure retention triggers to specify when instances should move to a
Retainedstate instead of automatic termination.For more information, see Control instance retention with instance lifecycle policies in the Amazon EC2 Auto Scaling User Guide.
Instances in a Retained state will continue to incur standard EC2 charges until terminated.
-
operator(Optional[Operator], default:None) –The entity that manages the Auto Scaling group. If you specify this parameter, Amazon EC2 Auto Scaling passes the operator identity to EC2 for instance launches and only allows the designated operator to make changes to the Auto Scaling group. All mutating API calls from non-operator callers are rejected with an
AccessDeniedexception.
Raises:
-
AlreadyExistsFault–You already have an Auto Scaling group or launch configuration with this name.
-
LimitExceededFault–You have already reached a limit for your Amazon EC2 Auto Scaling resources (for example, Auto Scaling groups, launch configurations, or lifecycle hooks). For more information, see DescribeAccountLimits in the Amazon EC2 Auto Scaling API Reference.
-
ResourceContentionFault–You already have a pending update to an Amazon EC2 Auto Scaling resource (for example, an Auto Scaling group, instance, or load balancer).
-
ServiceLinkedRoleFailure–The service-linked role is not yet ready for use.
-
UnknownServiceError–The service returned an error code this client does not model.
Examples:
To create an Auto Scaling group with an attached target group This example creates an Auto Scaling group and attaches the specified target group.
>>> client.create_auto_scaling_group(auto_scaling_group_name='my-auto-scaling-group', launch_template={'LaunchTemplateName': 'my-template-for-auto-scaling', 'Version': '$Default'}, min_size=1, max_size=3, target_group_ar_ns=['arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/my-targets/73e2d6bc24d8a067'], health_check_type='ELB', health_check_grace_period=300, vpc_zone_identifier='subnet-057fa0918fEXAMPLE, subnet-610acd08EXAMPLE')
To create an Auto Scaling group with a mixed instances policy
This example creates an Auto Scaling group with a mixed instances policy. It specifies the c5.large, c5a.large, and c6g.large instance types and defines a different launch template for the c6g.large instance type.
>>> client.create_auto_scaling_group(auto_scaling_group_name='my-asg', mixed_instances_policy={'LaunchTemplate': {'LaunchTemplateSpecification': {'LaunchTemplateName': 'my-launch-template-for-x86', 'Version': '$Default'}, 'Overrides': [{'InstanceType': 'c6g.large', 'LaunchTemplateSpecification': {'LaunchTemplateName': 'my-launch-template-for-arm', 'Version': '$Default'}}, {'InstanceType': 'c5.large'}, {'InstanceType': 'c5a.large'}]}, 'InstancesDistribution': {'OnDemandBaseCapacity': 1, 'OnDemandPercentageAboveBaseCapacity': 50, 'SpotAllocationStrategy': 'price-capacity-optimized'}}, min_size=1, max_size=5, desired_capacity=3, vpc_zone_identifier='subnet-057fa0918fEXAMPLE, subnet-610acd08EXAMPLE')
To create an Auto Scaling group using attribute-based instance type selection
This example creates an Auto Scaling group using attribute-based instance type selection. It requires the instance types to have a minimum of four vCPUs and a maximum of eight vCPUs, a minimum of 16,384 MiB of memory, and an Intel manufactured CPU.
>>> client.create_auto_scaling_group(auto_scaling_group_name='my-asg', mixed_instances_policy={'LaunchTemplate': {'LaunchTemplateSpecification': {'LaunchTemplateName': 'my-template-for-auto-scaling', 'Version': '$Default'}, 'Overrides': [{'InstanceRequirements': {'VCpuCount': {'Min': 4, 'Max': 8}, 'MemoryMiB': {'Min': 16384}, 'CpuManufacturers': ['intel']}}]}, 'InstancesDistribution': {'OnDemandPercentageAboveBaseCapacity': 50, 'SpotAllocationStrategy': 'price-capacity-optimized'}}, min_size=0, max_size=100, desired_capacity=4, desired_capacity_type='units', vpc_zone_identifier='subnet-057fa0918fEXAMPLE, subnet-610acd08EXAMPLE')
To create an Auto Scaling group using Distribution Segments
This example creates an Auto Scaling group that uses Distribution Segments to prioritize On-Demand Capacity Reservations, Capacity Blocks, interruptible Capacity Reservations, and then On-Demand capacity.
>>> client.create_auto_scaling_group(auto_scaling_group_name='my-asg', mixed_instances_policy={'LaunchTemplate': {'LaunchTemplateSpecification': {'LaunchTemplateName': 'my-template-for-auto-scaling', 'Version': '$Default'}, 'Overrides': [{'InstanceType': 'm5.24xlarge'}, {'InstanceType': 'p5.48xlarge'}]}, 'InstancesDistribution': {'OnDemandAllocationStrategy': 'prioritized', 'DistributionSegments': [{'TargetCapacityTypes': ['on-demand-capacity-reservation', 'capacity-block', 'interruptible-capacity-reservation', 'on-demand']}]}}, capacity_reservation_specification={'CapacityReservationTarget': {'CapacityReservationResourceGroupArns': ['arn:aws:resource-groups:us-east-1:123456789012:group/my-capacity-reservation-group']}}, min_size=0, max_size=10, desired_capacity=5, vpc_zone_identifier='subnet-057fa0918fEXAMPLE')
To create an Auto Scaling group
This example creates an Auto Scaling group.
>>> client.create_auto_scaling_group(auto_scaling_group_name='my-auto-scaling-group', launch_template={'LaunchTemplateName': 'my-template-for-auto-scaling', 'Version': '$Default'}, min_size=1, max_size=3, max_instance_lifetime=2592000, default_instance_warmup=120, vpc_zone_identifier='subnet-057fa0918fEXAMPLE')
Source code in docs_src/capo_auto_scaling/_services/auto_scaling.py
854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 | |