AWS SDK Version 3 for .NET
API Reference

AWS services or capabilities described in AWS Documentation may vary by region/location. Click Getting Started with Amazon AWS to see specific differences applicable to the China (Beijing) Region.

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.

Note:

For .NET Core this operation is only available in asynchronous form. Please refer to CreateAutoScalingGroupAsync.

Namespace: Amazon.AutoScaling
Assembly: AWSSDK.AutoScaling.dll
Version: 3.x.y.z

Syntax

C#
public abstract CreateAutoScalingGroupResponse CreateAutoScalingGroup(
         CreateAutoScalingGroupRequest request
)

Parameters

request
Type: Amazon.AutoScaling.Model.CreateAutoScalingGroupRequest

Container for the necessary parameters to execute the CreateAutoScalingGroup service method.

Return Value


The response from the CreateAutoScalingGroup service method, as returned by AutoScaling.

Exceptions

ExceptionCondition
AlreadyExistsException You already have an Auto Scaling group or launch configuration with this name.
LimitExceededException 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.
ResourceContentionException You already have a pending update to an Amazon EC2 Auto Scaling resource (for example, an Auto Scaling group, instance, or load balancer).
ServiceLinkedRoleFailureException The service-linked role is not yet ready for use.

Examples

This example creates an Auto Scaling group.

To create an Auto Scaling group


var client = new AmazonAutoScalingClient();
var response = client.CreateAutoScalingGroup(new CreateAutoScalingGroupRequest 
{
    AutoScalingGroupName = "my-auto-scaling-group",
    DefaultInstanceWarmup = 120,
    LaunchTemplate = new LaunchTemplateSpecification {
        LaunchTemplateName = "my-template-for-auto-scaling",
        Version = "$Default"
    },
    MaxInstanceLifetime = 2592000,
    MaxSize = 3,
    MinSize = 1,
    VPCZoneIdentifier = "subnet-057fa0918fEXAMPLE"
});


            

This example creates an Auto Scaling group and attaches the specified target group.

To create an Auto Scaling group with an attached target group


var client = new AmazonAutoScalingClient();
var response = client.CreateAutoScalingGroup(new CreateAutoScalingGroupRequest 
{
    AutoScalingGroupName = "my-auto-scaling-group",
    HealthCheckGracePeriod = 300,
    HealthCheckType = "ELB",
    LaunchTemplate = new LaunchTemplateSpecification {
        LaunchTemplateName = "my-template-for-auto-scaling",
        Version = "$Default"
    },
    MaxSize = 3,
    MinSize = 1,
    TargetGroupARNs = new List<string> {
        "arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/my-targets/73e2d6bc24d8a067"
    },
    VPCZoneIdentifier = "subnet-057fa0918fEXAMPLE, subnet-610acd08EXAMPLE"
});


            

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.

To create an Auto Scaling group with a mixed instances policy


var client = new AmazonAutoScalingClient();
var response = client.CreateAutoScalingGroup(new CreateAutoScalingGroupRequest 
{
    AutoScalingGroupName = "my-asg",
    DesiredCapacity = 3,
    MaxSize = 5,
    MinSize = 1,
    MixedInstancesPolicy = new MixedInstancesPolicy {
        InstancesDistribution = new InstancesDistribution {
            OnDemandBaseCapacity = 1,
            OnDemandPercentageAboveBaseCapacity = 50,
            SpotAllocationStrategy = "price-capacity-optimized"
        },
        LaunchTemplate = new LaunchTemplate {
            LaunchTemplateSpecification = new LaunchTemplateSpecification {
                LaunchTemplateName = "my-launch-template-for-x86",
                Version = "$Default"
            },
            Overrides = new List<LaunchTemplateOverrides> {
                new LaunchTemplateOverrides {
                    InstanceType = "c6g.large",
                    LaunchTemplateSpecification = new LaunchTemplateSpecification {
                        LaunchTemplateName = "my-launch-template-for-arm",
                        Version = "$Default"
                    }
                },
                new LaunchTemplateOverrides { InstanceType = "c5.large" },
                new LaunchTemplateOverrides { InstanceType = "c5a.large" }
            }
        }
    },
    VPCZoneIdentifier = "subnet-057fa0918fEXAMPLE, subnet-610acd08EXAMPLE"
});


            

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.

To create an Auto Scaling group using attribute-based instance type selection


var client = new AmazonAutoScalingClient();
var response = client.CreateAutoScalingGroup(new CreateAutoScalingGroupRequest 
{
    AutoScalingGroupName = "my-asg",
    DesiredCapacity = 4,
    DesiredCapacityType = "units",
    MaxSize = 100,
    MinSize = 0,
    MixedInstancesPolicy = new MixedInstancesPolicy {
        InstancesDistribution = new InstancesDistribution {
            OnDemandPercentageAboveBaseCapacity = 50,
            SpotAllocationStrategy = "price-capacity-optimized"
        },
        LaunchTemplate = new LaunchTemplate {
            LaunchTemplateSpecification = new LaunchTemplateSpecification {
                LaunchTemplateName = "my-template-for-auto-scaling",
                Version = "$Default"
            },
            Overrides = new List<LaunchTemplateOverrides> {
                new LaunchTemplateOverrides { InstanceRequirements = new InstanceRequirements {
                    CpuManufacturers = new List<string> {
                        "intel"
                    },
                    MemoryMiB = new MemoryMiBRequest { Min = 16384 },
                    VCpuCount = new VCpuCountRequest {
                        Max = 8,
                        Min = 4
                    }
                } }
            }
        }
    },
    VPCZoneIdentifier = "subnet-057fa0918fEXAMPLE, subnet-610acd08EXAMPLE"
});


            

Version Information

.NET Framework:
Supported in: 4.5, 4.0, 3.5

See Also