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.

Creates or updates a scaling policy for an Auto Scaling group. Scaling policies are used to scale an Auto Scaling group based on configurable metrics. If no policies are defined, the dynamic scaling and predictive scaling features are not used.

For more information about using dynamic scaling, see Target tracking scaling policies and Step and simple scaling policies in the Amazon EC2 Auto Scaling User Guide.

For more information about using predictive scaling, see Predictive scaling for Amazon EC2 Auto Scaling in the Amazon EC2 Auto Scaling User Guide.

You can view the scaling policies for an Auto Scaling group using the DescribePolicies API call. If you are no longer using a scaling policy, you can delete it by calling the DeletePolicy API.

Note:

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

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

Syntax

C#
public abstract PutScalingPolicyResponse PutScalingPolicy(
         PutScalingPolicyRequest request
)

Parameters

request
Type: Amazon.AutoScaling.Model.PutScalingPolicyRequest

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

Return Value


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

Exceptions

ExceptionCondition
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 adds the specified policy to the specified Auto Scaling group.

To add a scaling policy to an Auto Scaling group


var client = new AmazonAutoScalingClient();
var response = client.PutScalingPolicy(new PutScalingPolicyRequest 
{
    AutoScalingGroupName = "my-auto-scaling-group",
    PolicyName = "alb1000-target-tracking-scaling-policy",
    PolicyType = "TargetTrackingScaling",
    TargetTrackingConfiguration = new TargetTrackingConfiguration {
        PredefinedMetricSpecification = new PredefinedMetricSpecification {
            PredefinedMetricType = "ALBRequestCountPerTarget",
            ResourceLabel = "app/my-alb/778d41231b141a0f/targetgroup/my-alb-target-group/943f017f100becff"
        },
        TargetValue = 1000
    }
});

List<Alarm> alarms = response.Alarms;
string policyARN = response.PolicyARN;

            

Version Information

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

See Also