/*******************************************************************************
* Copyright 2012-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use
* this file except in compliance with the License. A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file.
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
* *****************************************************************************
*
* AWS Tools for Windows (TM) PowerShell (TM)
*
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Management.Automation;
using System.Text;
using Amazon.PowerShell.Common;
using Amazon.Runtime;
using Amazon.AutoScaling;
using Amazon.AutoScaling.Model;
namespace Amazon.PowerShell.Cmdlets.AS
{
///
/// 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.
///
///
[Cmdlet("Write", "ASScalingPolicy", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.Medium)]
[OutputType("Amazon.AutoScaling.Model.PutScalingPolicyResponse")]
[AWSCmdlet("Calls the AWS Auto Scaling PutScalingPolicy API operation.", Operation = new[] {"PutScalingPolicy"}, SelectReturnType = typeof(Amazon.AutoScaling.Model.PutScalingPolicyResponse))]
[AWSCmdletOutput("Amazon.AutoScaling.Model.PutScalingPolicyResponse",
"This cmdlet returns an Amazon.AutoScaling.Model.PutScalingPolicyResponse object containing multiple properties. The object can also be referenced from properties attached to the cmdlet entry in the $AWSHistory stack."
)]
public partial class WriteASScalingPolicyCmdlet : AmazonAutoScalingClientCmdlet, IExecutor
{
#region Parameter AdjustmentType
///
///
/// Specifies how the scaling adjustment is interpreted (for example, an absolute number
/// or a percentage). The valid values are ChangeInCapacity
, ExactCapacity
,
/// and PercentChangeInCapacity
.Required if the policy type is StepScaling
or SimpleScaling
.
/// For more information, see Scaling
/// adjustment types in the Amazon EC2 Auto Scaling User Guide.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String AdjustmentType { get; set; }
#endregion
#region Parameter AutoScalingGroupName
///
///
/// The name of the Auto Scaling group.
///
///
#if !MODULAR
[System.Management.Automation.Parameter(Position = 0, ValueFromPipelineByPropertyName = true, ValueFromPipeline = true)]
#else
[System.Management.Automation.Parameter(Position = 0, ValueFromPipelineByPropertyName = true, ValueFromPipeline = true, Mandatory = true)]
[System.Management.Automation.AllowEmptyString]
[System.Management.Automation.AllowNull]
#endif
[Amazon.PowerShell.Common.AWSRequiredParameter]
public System.String AutoScalingGroupName { get; set; }
#endregion
#region Parameter Cooldown
///
///
/// A cooldown period, in seconds, that applies to a specific simple scaling policy. When
/// a cooldown period is specified here, it overrides the default cooldown.Valid only if the policy type is SimpleScaling
. For more information,
/// see Scaling
/// cooldowns for Amazon EC2 Auto Scaling in the Amazon EC2 Auto Scaling User Guide.Default: None
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.Int32? Cooldown { get; set; }
#endregion
#region Parameter CustomizedMetricSpecification_Dimension
///
///
/// The dimensions of the metric.Conditional: If you published your metric with dimensions, you must specify the same
/// dimensions in your scaling policy.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("TargetTrackingConfiguration_CustomizedMetricSpecification_Dimensions")]
public Amazon.AutoScaling.Model.MetricDimension[] CustomizedMetricSpecification_Dimension { get; set; }
#endregion
#region Parameter TargetTrackingConfiguration_DisableScaleIn
///
///
/// Indicates whether scaling in by the target tracking scaling policy is disabled. If
/// scaling in is disabled, the target tracking scaling policy doesn't remove instances
/// from the Auto Scaling group. Otherwise, the target tracking scaling policy can remove
/// instances from the Auto Scaling group. The default is false
.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.Boolean? TargetTrackingConfiguration_DisableScaleIn { get; set; }
#endregion
#region Parameter Enabled
///
///
/// Indicates whether the scaling policy is enabled or disabled. The default is enabled.
/// For more information, see Disabling
/// a scaling policy for an Auto Scaling group in the Amazon EC2 Auto Scaling User
/// Guide.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.Boolean? Enabled { get; set; }
#endregion
#region Parameter EstimatedInstanceWarmup
///
///
/// Not needed if the default instance warmup is defined for the group.The estimated time, in seconds, until a newly launched instance can contribute to
/// the CloudWatch metrics. This warm-up period applies to instances launched due to a
/// specific target tracking or step scaling policy. When a warm-up period is specified
/// here, it overrides the default instance warmup.Valid only if the policy type is TargetTrackingScaling
or StepScaling
.The default is to use the value for the default instance warmup defined for the group.
/// If default instance warmup is null, then EstimatedInstanceWarmup
falls
/// back to the value of default cooldown.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.Int32? EstimatedInstanceWarmup { get; set; }
#endregion
#region Parameter PredictiveScalingConfiguration_MaxCapacityBreachBehavior
///
///
/// Defines the behavior that should be applied if the forecast capacity approaches or
/// exceeds the maximum capacity of the Auto Scaling group. Defaults to HonorMaxCapacity
/// if not specified.The following are possible values:HonorMaxCapacity
- Amazon EC2 Auto Scaling cannot scale out capacity
/// higher than the maximum capacity. The maximum capacity is enforced as a hard limit.
/// IncreaseMaxCapacity
- Amazon EC2 Auto Scaling can scale out capacity
/// higher than the maximum capacity when the forecast capacity is close to or exceeds
/// the maximum capacity. The upper limit is determined by the forecasted capacity and
/// the value for MaxCapacityBuffer
.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[AWSConstantClassSource("Amazon.AutoScaling.PredictiveScalingMaxCapacityBreachBehavior")]
public Amazon.AutoScaling.PredictiveScalingMaxCapacityBreachBehavior PredictiveScalingConfiguration_MaxCapacityBreachBehavior { get; set; }
#endregion
#region Parameter PredictiveScalingConfiguration_MaxCapacityBuffer
///
///
/// The size of the capacity buffer to use when the forecast capacity is close to or exceeds
/// the maximum capacity. The value is specified as a percentage relative to the forecast
/// capacity. For example, if the buffer is 10, this means a 10 percent buffer, such that
/// if the forecast capacity is 50, and the maximum capacity is 40, then the effective
/// maximum capacity is 55.If set to 0, Amazon EC2 Auto Scaling may scale capacity higher than the maximum capacity
/// to equal but not exceed forecast capacity. Required if the MaxCapacityBreachBehavior
property is set to IncreaseMaxCapacity
,
/// and cannot be used otherwise.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.Int32? PredictiveScalingConfiguration_MaxCapacityBuffer { get; set; }
#endregion
#region Parameter MetricAggregationType
///
///
/// The aggregation type for the CloudWatch metrics. The valid values are Minimum
,
/// Maximum
, and Average
. If the aggregation type is null, the
/// value is treated as Average
.Valid only if the policy type is StepScaling
.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String MetricAggregationType { get; set; }
#endregion
#region Parameter CustomizedMetricSpecification_MetricName
///
///
/// The name of the metric. To get the exact metric name, namespace, and dimensions, inspect
/// the Metric
/// object that is returned by a call to ListMetrics.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("TargetTrackingConfiguration_CustomizedMetricSpecification_MetricName")]
public System.String CustomizedMetricSpecification_MetricName { get; set; }
#endregion
#region Parameter CustomizedMetricSpecification_Metric
///
///
/// The metrics to include in the target tracking scaling policy, as a metric data query.
/// This can include both raw metric and metric math expressions.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("TargetTrackingConfiguration_CustomizedMetricSpecification_Metrics")]
public Amazon.AutoScaling.Model.TargetTrackingMetricDataQuery[] CustomizedMetricSpecification_Metric { get; set; }
#endregion
#region Parameter PredictiveScalingConfiguration_MetricSpecification
///
///
/// This structure includes the metrics and target utilization to use for predictive scaling.
/// This is an array, but we currently only support a single metric specification. That
/// is, you can specify a target value and a single metric pair, or a target value and
/// one scaling metric and one load metric.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("PredictiveScalingConfiguration_MetricSpecifications")]
public Amazon.AutoScaling.Model.PredictiveScalingMetricSpecification[] PredictiveScalingConfiguration_MetricSpecification { get; set; }
#endregion
#region Parameter MinAdjustmentMagnitude
///
///
/// The minimum value to scale by when the adjustment type is PercentChangeInCapacity
.
/// For example, suppose that you create a step scaling policy to scale out an Auto Scaling
/// group by 25 percent and you specify a MinAdjustmentMagnitude
of 2. If
/// the group has 4 instances and the scaling policy is performed, 25 percent of 4 is
/// 1. However, because you specified a MinAdjustmentMagnitude
of 2, Amazon
/// EC2 Auto Scaling scales out the group by 2 instances.Valid only if the policy type is StepScaling
or SimpleScaling
.
/// For more information, see Scaling
/// adjustment types in the Amazon EC2 Auto Scaling User Guide.Some Auto Scaling groups use instance weights. In this case, set the MinAdjustmentMagnitude
/// to a value that is at least as large as your largest instance weight.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.Int32? MinAdjustmentMagnitude { get; set; }
#endregion
#region Parameter MinAdjustmentStep
///
///
/// Available for backward compatibility. Use MinAdjustmentMagnitude
instead.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.Int32? MinAdjustmentStep { get; set; }
#endregion
#region Parameter PredictiveScalingConfiguration_Mode
///
///
/// The predictive scaling mode. Defaults to ForecastOnly
if not specified.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[AWSConstantClassSource("Amazon.AutoScaling.PredictiveScalingMode")]
public Amazon.AutoScaling.PredictiveScalingMode PredictiveScalingConfiguration_Mode { get; set; }
#endregion
#region Parameter CustomizedMetricSpecification_Namespace
///
///
/// The namespace of the metric.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("TargetTrackingConfiguration_CustomizedMetricSpecification_Namespace")]
public System.String CustomizedMetricSpecification_Namespace { get; set; }
#endregion
#region Parameter PolicyName
///
///
/// The name of the policy.
///
///
#if !MODULAR
[System.Management.Automation.Parameter(Position = 1, ValueFromPipelineByPropertyName = true)]
#else
[System.Management.Automation.Parameter(Position = 1, ValueFromPipelineByPropertyName = true, Mandatory = true)]
[System.Management.Automation.AllowEmptyString]
[System.Management.Automation.AllowNull]
#endif
[Amazon.PowerShell.Common.AWSRequiredParameter]
public System.String PolicyName { get; set; }
#endregion
#region Parameter PolicyType
///
///
/// One of the following policy types: TargetTrackingScaling
StepScaling
SimpleScaling
(default)PredictiveScaling
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String PolicyType { get; set; }
#endregion
#region Parameter PredefinedMetricSpecification_PredefinedMetricType
///
///
/// The metric type. The following predefined metrics are available:ASGAverageCPUUtilization
- Average CPU utilization of the Auto Scaling
/// group.ASGAverageNetworkIn
- Average number of bytes received on all network
/// interfaces by the Auto Scaling group.ASGAverageNetworkOut
- Average number of bytes sent out on all network
/// interfaces by the Auto Scaling group.ALBRequestCountPerTarget
- Average Application Load Balancer request
/// count per target for your Auto Scaling group.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("TargetTrackingConfiguration_PredefinedMetricSpecification_PredefinedMetricType")]
[AWSConstantClassSource("Amazon.AutoScaling.MetricType")]
public Amazon.AutoScaling.MetricType PredefinedMetricSpecification_PredefinedMetricType { get; set; }
#endregion
#region Parameter PredefinedMetricSpecification_ResourceLabel
///
///
/// A label that uniquely identifies a specific Application Load Balancer target group
/// from which to determine the average request count served by your Auto Scaling group.
/// You can't specify a resource label unless the target group is attached to the Auto
/// Scaling group.You create the resource label by appending the final portion of the load balancer
/// ARN and the final portion of the target group ARN into a single value, separated by
/// a forward slash (/). The format of the resource label is:app/my-alb/778d41231b141a0f/targetgroup/my-alb-target-group/943f017f100becff
.Where:- app/<load-balancer-name>/<load-balancer-id> is the final portion of the
/// load balancer ARN
- targetgroup/<target-group-name>/<target-group-id> is the final portion
/// of the target group ARN.
To find the ARN for an Application Load Balancer, use the DescribeLoadBalancers
/// API operation. To find the ARN for the target group, use the DescribeTargetGroups
/// API operation.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("TargetTrackingConfiguration_PredefinedMetricSpecification_ResourceLabel")]
public System.String PredefinedMetricSpecification_ResourceLabel { get; set; }
#endregion
#region Parameter ScalingAdjustment
///
///
/// The amount by which to scale, based on the specified adjustment type. A positive value
/// adds to the current capacity while a negative number removes from the current capacity.
/// For exact capacity, you must specify a non-negative value.Required if the policy type is SimpleScaling
. (Not used with any other
/// policy type.)
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.Int32? ScalingAdjustment { get; set; }
#endregion
#region Parameter PredictiveScalingConfiguration_SchedulingBufferTime
///
///
/// The amount of time, in seconds, by which the instance launch time can be advanced.
/// For example, the forecast says to add capacity at 10:00 AM, and you choose to pre-launch
/// instances by 5 minutes. In that case, the instances will be launched at 9:55 AM. The
/// intention is to give resources time to be provisioned. It can take a few minutes to
/// launch an EC2 instance. The actual amount of time required depends on several factors,
/// such as the size of the instance and whether there are startup scripts to complete.
/// The value must be less than the forecast interval duration of 3600 seconds (60 minutes).
/// Defaults to 300 seconds if not specified.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.Int32? PredictiveScalingConfiguration_SchedulingBufferTime { get; set; }
#endregion
#region Parameter CustomizedMetricSpecification_Statistic
///
///
/// The statistic of the metric.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("TargetTrackingConfiguration_CustomizedMetricSpecification_Statistic")]
[AWSConstantClassSource("Amazon.AutoScaling.MetricStatistic")]
public Amazon.AutoScaling.MetricStatistic CustomizedMetricSpecification_Statistic { get; set; }
#endregion
#region Parameter StepAdjustment
///
///
/// A set of adjustments that enable you to scale based on the size of the alarm breach.Required if the policy type is StepScaling
. (Not used with any other
/// policy type.)
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("StepAdjustments")]
public Amazon.AutoScaling.Model.StepAdjustment[] StepAdjustment { get; set; }
#endregion
#region Parameter TargetTrackingConfiguration_TargetValue
///
///
/// The target value for the metric.Some metrics are based on a count instead of a percentage, such as the request count
/// for an Application Load Balancer or the number of messages in an SQS queue. If the
/// scaling policy specifies one of these metrics, specify the target utilization as the
/// optimal average request or message count per instance during any one-minute interval.
///
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.Double? TargetTrackingConfiguration_TargetValue { get; set; }
#endregion
#region Parameter CustomizedMetricSpecification_Unit
///
///
/// The unit of the metric. For a complete list of the units that CloudWatch supports,
/// see the MetricDatum
/// data type in the Amazon CloudWatch API Reference.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("TargetTrackingConfiguration_CustomizedMetricSpecification_Unit")]
public System.String CustomizedMetricSpecification_Unit { get; set; }
#endregion
#region Parameter Select
///
/// Use the -Select parameter to control the cmdlet output. The default value is '*'.
/// Specifying -Select '*' will result in the cmdlet returning the whole service response (Amazon.AutoScaling.Model.PutScalingPolicyResponse).
/// Specifying the name of a property of type Amazon.AutoScaling.Model.PutScalingPolicyResponse will result in that property being returned.
/// Specifying -Select '^ParameterName' will result in the cmdlet returning the selected cmdlet parameter value.
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public string Select { get; set; } = "*";
#endregion
#region Parameter PassThru
///
/// Changes the cmdlet behavior to return the value passed to the AutoScalingGroupName parameter.
/// The -PassThru parameter is deprecated, use -Select '^AutoScalingGroupName' instead. This parameter will be removed in a future version.
///
[System.Obsolete("The -PassThru parameter is deprecated, use -Select '^AutoScalingGroupName' instead. This parameter will be removed in a future version.")]
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public SwitchParameter PassThru { get; set; }
#endregion
#region Parameter Force
///
/// This parameter overrides confirmation prompts to force
/// the cmdlet to continue its operation. This parameter should always
/// be used with caution.
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public SwitchParameter Force { get; set; }
#endregion
protected override void ProcessRecord()
{
this._AWSSignerType = "v4";
base.ProcessRecord();
var resourceIdentifiersText = FormatParameterValuesForConfirmationMsg(nameof(this.AutoScalingGroupName), MyInvocation.BoundParameters);
if (!ConfirmShouldProceed(this.Force.IsPresent, resourceIdentifiersText, "Write-ASScalingPolicy (PutScalingPolicy)"))
{
return;
}
var context = new CmdletContext();
// allow for manipulation of parameters prior to loading into context
PreExecutionContextLoad(context);
#pragma warning disable CS0618, CS0612 //A class member was marked with the Obsolete attribute
if (ParameterWasBound(nameof(this.Select)))
{
context.Select = CreateSelectDelegate(Select) ??
throw new System.ArgumentException("Invalid value for -Select parameter.", nameof(this.Select));
if (this.PassThru.IsPresent)
{
throw new System.ArgumentException("-PassThru cannot be used when -Select is specified.", nameof(this.Select));
}
}
else if (this.PassThru.IsPresent)
{
context.Select = (response, cmdlet) => this.AutoScalingGroupName;
}
#pragma warning restore CS0618, CS0612 //A class member was marked with the Obsolete attribute
context.AdjustmentType = this.AdjustmentType;
context.AutoScalingGroupName = this.AutoScalingGroupName;
#if MODULAR
if (this.AutoScalingGroupName == null && ParameterWasBound(nameof(this.AutoScalingGroupName)))
{
WriteWarning("You are passing $null as a value for parameter AutoScalingGroupName which is marked as required. In case you believe this parameter was incorrectly marked as required, report this by opening an issue at https://github.com/aws/aws-tools-for-powershell/issues.");
}
#endif
context.Cooldown = this.Cooldown;
context.Enabled = this.Enabled;
context.EstimatedInstanceWarmup = this.EstimatedInstanceWarmup;
context.MetricAggregationType = this.MetricAggregationType;
context.MinAdjustmentMagnitude = this.MinAdjustmentMagnitude;
context.MinAdjustmentStep = this.MinAdjustmentStep;
context.PolicyName = this.PolicyName;
#if MODULAR
if (this.PolicyName == null && ParameterWasBound(nameof(this.PolicyName)))
{
WriteWarning("You are passing $null as a value for parameter PolicyName which is marked as required. In case you believe this parameter was incorrectly marked as required, report this by opening an issue at https://github.com/aws/aws-tools-for-powershell/issues.");
}
#endif
context.PolicyType = this.PolicyType;
context.PredictiveScalingConfiguration_MaxCapacityBreachBehavior = this.PredictiveScalingConfiguration_MaxCapacityBreachBehavior;
context.PredictiveScalingConfiguration_MaxCapacityBuffer = this.PredictiveScalingConfiguration_MaxCapacityBuffer;
if (this.PredictiveScalingConfiguration_MetricSpecification != null)
{
context.PredictiveScalingConfiguration_MetricSpecification = new List(this.PredictiveScalingConfiguration_MetricSpecification);
}
context.PredictiveScalingConfiguration_Mode = this.PredictiveScalingConfiguration_Mode;
context.PredictiveScalingConfiguration_SchedulingBufferTime = this.PredictiveScalingConfiguration_SchedulingBufferTime;
context.ScalingAdjustment = this.ScalingAdjustment;
if (this.StepAdjustment != null)
{
context.StepAdjustment = new List(this.StepAdjustment);
}
if (this.CustomizedMetricSpecification_Dimension != null)
{
context.CustomizedMetricSpecification_Dimension = new List(this.CustomizedMetricSpecification_Dimension);
}
context.CustomizedMetricSpecification_MetricName = this.CustomizedMetricSpecification_MetricName;
if (this.CustomizedMetricSpecification_Metric != null)
{
context.CustomizedMetricSpecification_Metric = new List(this.CustomizedMetricSpecification_Metric);
}
context.CustomizedMetricSpecification_Namespace = this.CustomizedMetricSpecification_Namespace;
context.CustomizedMetricSpecification_Statistic = this.CustomizedMetricSpecification_Statistic;
context.CustomizedMetricSpecification_Unit = this.CustomizedMetricSpecification_Unit;
context.TargetTrackingConfiguration_DisableScaleIn = this.TargetTrackingConfiguration_DisableScaleIn;
context.PredefinedMetricSpecification_PredefinedMetricType = this.PredefinedMetricSpecification_PredefinedMetricType;
context.PredefinedMetricSpecification_ResourceLabel = this.PredefinedMetricSpecification_ResourceLabel;
context.TargetTrackingConfiguration_TargetValue = this.TargetTrackingConfiguration_TargetValue;
// allow further manipulation of loaded context prior to processing
PostExecutionContextLoad(context);
var output = Execute(context) as CmdletOutput;
ProcessOutput(output);
}
#region IExecutor Members
public object Execute(ExecutorContext context)
{
var cmdletContext = context as CmdletContext;
// create request
var request = new Amazon.AutoScaling.Model.PutScalingPolicyRequest();
if (cmdletContext.AdjustmentType != null)
{
request.AdjustmentType = cmdletContext.AdjustmentType;
}
if (cmdletContext.AutoScalingGroupName != null)
{
request.AutoScalingGroupName = cmdletContext.AutoScalingGroupName;
}
if (cmdletContext.Cooldown != null)
{
request.Cooldown = cmdletContext.Cooldown.Value;
}
if (cmdletContext.Enabled != null)
{
request.Enabled = cmdletContext.Enabled.Value;
}
if (cmdletContext.EstimatedInstanceWarmup != null)
{
request.EstimatedInstanceWarmup = cmdletContext.EstimatedInstanceWarmup.Value;
}
if (cmdletContext.MetricAggregationType != null)
{
request.MetricAggregationType = cmdletContext.MetricAggregationType;
}
if (cmdletContext.MinAdjustmentMagnitude != null)
{
request.MinAdjustmentMagnitude = cmdletContext.MinAdjustmentMagnitude.Value;
}
if (cmdletContext.MinAdjustmentStep != null)
{
request.MinAdjustmentStep = cmdletContext.MinAdjustmentStep.Value;
}
if (cmdletContext.PolicyName != null)
{
request.PolicyName = cmdletContext.PolicyName;
}
if (cmdletContext.PolicyType != null)
{
request.PolicyType = cmdletContext.PolicyType;
}
// populate PredictiveScalingConfiguration
var requestPredictiveScalingConfigurationIsNull = true;
request.PredictiveScalingConfiguration = new Amazon.AutoScaling.Model.PredictiveScalingConfiguration();
Amazon.AutoScaling.PredictiveScalingMaxCapacityBreachBehavior requestPredictiveScalingConfiguration_predictiveScalingConfiguration_MaxCapacityBreachBehavior = null;
if (cmdletContext.PredictiveScalingConfiguration_MaxCapacityBreachBehavior != null)
{
requestPredictiveScalingConfiguration_predictiveScalingConfiguration_MaxCapacityBreachBehavior = cmdletContext.PredictiveScalingConfiguration_MaxCapacityBreachBehavior;
}
if (requestPredictiveScalingConfiguration_predictiveScalingConfiguration_MaxCapacityBreachBehavior != null)
{
request.PredictiveScalingConfiguration.MaxCapacityBreachBehavior = requestPredictiveScalingConfiguration_predictiveScalingConfiguration_MaxCapacityBreachBehavior;
requestPredictiveScalingConfigurationIsNull = false;
}
System.Int32? requestPredictiveScalingConfiguration_predictiveScalingConfiguration_MaxCapacityBuffer = null;
if (cmdletContext.PredictiveScalingConfiguration_MaxCapacityBuffer != null)
{
requestPredictiveScalingConfiguration_predictiveScalingConfiguration_MaxCapacityBuffer = cmdletContext.PredictiveScalingConfiguration_MaxCapacityBuffer.Value;
}
if (requestPredictiveScalingConfiguration_predictiveScalingConfiguration_MaxCapacityBuffer != null)
{
request.PredictiveScalingConfiguration.MaxCapacityBuffer = requestPredictiveScalingConfiguration_predictiveScalingConfiguration_MaxCapacityBuffer.Value;
requestPredictiveScalingConfigurationIsNull = false;
}
List requestPredictiveScalingConfiguration_predictiveScalingConfiguration_MetricSpecification = null;
if (cmdletContext.PredictiveScalingConfiguration_MetricSpecification != null)
{
requestPredictiveScalingConfiguration_predictiveScalingConfiguration_MetricSpecification = cmdletContext.PredictiveScalingConfiguration_MetricSpecification;
}
if (requestPredictiveScalingConfiguration_predictiveScalingConfiguration_MetricSpecification != null)
{
request.PredictiveScalingConfiguration.MetricSpecifications = requestPredictiveScalingConfiguration_predictiveScalingConfiguration_MetricSpecification;
requestPredictiveScalingConfigurationIsNull = false;
}
Amazon.AutoScaling.PredictiveScalingMode requestPredictiveScalingConfiguration_predictiveScalingConfiguration_Mode = null;
if (cmdletContext.PredictiveScalingConfiguration_Mode != null)
{
requestPredictiveScalingConfiguration_predictiveScalingConfiguration_Mode = cmdletContext.PredictiveScalingConfiguration_Mode;
}
if (requestPredictiveScalingConfiguration_predictiveScalingConfiguration_Mode != null)
{
request.PredictiveScalingConfiguration.Mode = requestPredictiveScalingConfiguration_predictiveScalingConfiguration_Mode;
requestPredictiveScalingConfigurationIsNull = false;
}
System.Int32? requestPredictiveScalingConfiguration_predictiveScalingConfiguration_SchedulingBufferTime = null;
if (cmdletContext.PredictiveScalingConfiguration_SchedulingBufferTime != null)
{
requestPredictiveScalingConfiguration_predictiveScalingConfiguration_SchedulingBufferTime = cmdletContext.PredictiveScalingConfiguration_SchedulingBufferTime.Value;
}
if (requestPredictiveScalingConfiguration_predictiveScalingConfiguration_SchedulingBufferTime != null)
{
request.PredictiveScalingConfiguration.SchedulingBufferTime = requestPredictiveScalingConfiguration_predictiveScalingConfiguration_SchedulingBufferTime.Value;
requestPredictiveScalingConfigurationIsNull = false;
}
// determine if request.PredictiveScalingConfiguration should be set to null
if (requestPredictiveScalingConfigurationIsNull)
{
request.PredictiveScalingConfiguration = null;
}
if (cmdletContext.ScalingAdjustment != null)
{
request.ScalingAdjustment = cmdletContext.ScalingAdjustment.Value;
}
if (cmdletContext.StepAdjustment != null)
{
request.StepAdjustments = cmdletContext.StepAdjustment;
}
// populate TargetTrackingConfiguration
var requestTargetTrackingConfigurationIsNull = true;
request.TargetTrackingConfiguration = new Amazon.AutoScaling.Model.TargetTrackingConfiguration();
System.Boolean? requestTargetTrackingConfiguration_targetTrackingConfiguration_DisableScaleIn = null;
if (cmdletContext.TargetTrackingConfiguration_DisableScaleIn != null)
{
requestTargetTrackingConfiguration_targetTrackingConfiguration_DisableScaleIn = cmdletContext.TargetTrackingConfiguration_DisableScaleIn.Value;
}
if (requestTargetTrackingConfiguration_targetTrackingConfiguration_DisableScaleIn != null)
{
request.TargetTrackingConfiguration.DisableScaleIn = requestTargetTrackingConfiguration_targetTrackingConfiguration_DisableScaleIn.Value;
requestTargetTrackingConfigurationIsNull = false;
}
System.Double? requestTargetTrackingConfiguration_targetTrackingConfiguration_TargetValue = null;
if (cmdletContext.TargetTrackingConfiguration_TargetValue != null)
{
requestTargetTrackingConfiguration_targetTrackingConfiguration_TargetValue = cmdletContext.TargetTrackingConfiguration_TargetValue.Value;
}
if (requestTargetTrackingConfiguration_targetTrackingConfiguration_TargetValue != null)
{
request.TargetTrackingConfiguration.TargetValue = requestTargetTrackingConfiguration_targetTrackingConfiguration_TargetValue.Value;
requestTargetTrackingConfigurationIsNull = false;
}
Amazon.AutoScaling.Model.PredefinedMetricSpecification requestTargetTrackingConfiguration_targetTrackingConfiguration_PredefinedMetricSpecification = null;
// populate PredefinedMetricSpecification
var requestTargetTrackingConfiguration_targetTrackingConfiguration_PredefinedMetricSpecificationIsNull = true;
requestTargetTrackingConfiguration_targetTrackingConfiguration_PredefinedMetricSpecification = new Amazon.AutoScaling.Model.PredefinedMetricSpecification();
Amazon.AutoScaling.MetricType requestTargetTrackingConfiguration_targetTrackingConfiguration_PredefinedMetricSpecification_predefinedMetricSpecification_PredefinedMetricType = null;
if (cmdletContext.PredefinedMetricSpecification_PredefinedMetricType != null)
{
requestTargetTrackingConfiguration_targetTrackingConfiguration_PredefinedMetricSpecification_predefinedMetricSpecification_PredefinedMetricType = cmdletContext.PredefinedMetricSpecification_PredefinedMetricType;
}
if (requestTargetTrackingConfiguration_targetTrackingConfiguration_PredefinedMetricSpecification_predefinedMetricSpecification_PredefinedMetricType != null)
{
requestTargetTrackingConfiguration_targetTrackingConfiguration_PredefinedMetricSpecification.PredefinedMetricType = requestTargetTrackingConfiguration_targetTrackingConfiguration_PredefinedMetricSpecification_predefinedMetricSpecification_PredefinedMetricType;
requestTargetTrackingConfiguration_targetTrackingConfiguration_PredefinedMetricSpecificationIsNull = false;
}
System.String requestTargetTrackingConfiguration_targetTrackingConfiguration_PredefinedMetricSpecification_predefinedMetricSpecification_ResourceLabel = null;
if (cmdletContext.PredefinedMetricSpecification_ResourceLabel != null)
{
requestTargetTrackingConfiguration_targetTrackingConfiguration_PredefinedMetricSpecification_predefinedMetricSpecification_ResourceLabel = cmdletContext.PredefinedMetricSpecification_ResourceLabel;
}
if (requestTargetTrackingConfiguration_targetTrackingConfiguration_PredefinedMetricSpecification_predefinedMetricSpecification_ResourceLabel != null)
{
requestTargetTrackingConfiguration_targetTrackingConfiguration_PredefinedMetricSpecification.ResourceLabel = requestTargetTrackingConfiguration_targetTrackingConfiguration_PredefinedMetricSpecification_predefinedMetricSpecification_ResourceLabel;
requestTargetTrackingConfiguration_targetTrackingConfiguration_PredefinedMetricSpecificationIsNull = false;
}
// determine if requestTargetTrackingConfiguration_targetTrackingConfiguration_PredefinedMetricSpecification should be set to null
if (requestTargetTrackingConfiguration_targetTrackingConfiguration_PredefinedMetricSpecificationIsNull)
{
requestTargetTrackingConfiguration_targetTrackingConfiguration_PredefinedMetricSpecification = null;
}
if (requestTargetTrackingConfiguration_targetTrackingConfiguration_PredefinedMetricSpecification != null)
{
request.TargetTrackingConfiguration.PredefinedMetricSpecification = requestTargetTrackingConfiguration_targetTrackingConfiguration_PredefinedMetricSpecification;
requestTargetTrackingConfigurationIsNull = false;
}
Amazon.AutoScaling.Model.CustomizedMetricSpecification requestTargetTrackingConfiguration_targetTrackingConfiguration_CustomizedMetricSpecification = null;
// populate CustomizedMetricSpecification
var requestTargetTrackingConfiguration_targetTrackingConfiguration_CustomizedMetricSpecificationIsNull = true;
requestTargetTrackingConfiguration_targetTrackingConfiguration_CustomizedMetricSpecification = new Amazon.AutoScaling.Model.CustomizedMetricSpecification();
List requestTargetTrackingConfiguration_targetTrackingConfiguration_CustomizedMetricSpecification_customizedMetricSpecification_Dimension = null;
if (cmdletContext.CustomizedMetricSpecification_Dimension != null)
{
requestTargetTrackingConfiguration_targetTrackingConfiguration_CustomizedMetricSpecification_customizedMetricSpecification_Dimension = cmdletContext.CustomizedMetricSpecification_Dimension;
}
if (requestTargetTrackingConfiguration_targetTrackingConfiguration_CustomizedMetricSpecification_customizedMetricSpecification_Dimension != null)
{
requestTargetTrackingConfiguration_targetTrackingConfiguration_CustomizedMetricSpecification.Dimensions = requestTargetTrackingConfiguration_targetTrackingConfiguration_CustomizedMetricSpecification_customizedMetricSpecification_Dimension;
requestTargetTrackingConfiguration_targetTrackingConfiguration_CustomizedMetricSpecificationIsNull = false;
}
System.String requestTargetTrackingConfiguration_targetTrackingConfiguration_CustomizedMetricSpecification_customizedMetricSpecification_MetricName = null;
if (cmdletContext.CustomizedMetricSpecification_MetricName != null)
{
requestTargetTrackingConfiguration_targetTrackingConfiguration_CustomizedMetricSpecification_customizedMetricSpecification_MetricName = cmdletContext.CustomizedMetricSpecification_MetricName;
}
if (requestTargetTrackingConfiguration_targetTrackingConfiguration_CustomizedMetricSpecification_customizedMetricSpecification_MetricName != null)
{
requestTargetTrackingConfiguration_targetTrackingConfiguration_CustomizedMetricSpecification.MetricName = requestTargetTrackingConfiguration_targetTrackingConfiguration_CustomizedMetricSpecification_customizedMetricSpecification_MetricName;
requestTargetTrackingConfiguration_targetTrackingConfiguration_CustomizedMetricSpecificationIsNull = false;
}
List requestTargetTrackingConfiguration_targetTrackingConfiguration_CustomizedMetricSpecification_customizedMetricSpecification_Metric = null;
if (cmdletContext.CustomizedMetricSpecification_Metric != null)
{
requestTargetTrackingConfiguration_targetTrackingConfiguration_CustomizedMetricSpecification_customizedMetricSpecification_Metric = cmdletContext.CustomizedMetricSpecification_Metric;
}
if (requestTargetTrackingConfiguration_targetTrackingConfiguration_CustomizedMetricSpecification_customizedMetricSpecification_Metric != null)
{
requestTargetTrackingConfiguration_targetTrackingConfiguration_CustomizedMetricSpecification.Metrics = requestTargetTrackingConfiguration_targetTrackingConfiguration_CustomizedMetricSpecification_customizedMetricSpecification_Metric;
requestTargetTrackingConfiguration_targetTrackingConfiguration_CustomizedMetricSpecificationIsNull = false;
}
System.String requestTargetTrackingConfiguration_targetTrackingConfiguration_CustomizedMetricSpecification_customizedMetricSpecification_Namespace = null;
if (cmdletContext.CustomizedMetricSpecification_Namespace != null)
{
requestTargetTrackingConfiguration_targetTrackingConfiguration_CustomizedMetricSpecification_customizedMetricSpecification_Namespace = cmdletContext.CustomizedMetricSpecification_Namespace;
}
if (requestTargetTrackingConfiguration_targetTrackingConfiguration_CustomizedMetricSpecification_customizedMetricSpecification_Namespace != null)
{
requestTargetTrackingConfiguration_targetTrackingConfiguration_CustomizedMetricSpecification.Namespace = requestTargetTrackingConfiguration_targetTrackingConfiguration_CustomizedMetricSpecification_customizedMetricSpecification_Namespace;
requestTargetTrackingConfiguration_targetTrackingConfiguration_CustomizedMetricSpecificationIsNull = false;
}
Amazon.AutoScaling.MetricStatistic requestTargetTrackingConfiguration_targetTrackingConfiguration_CustomizedMetricSpecification_customizedMetricSpecification_Statistic = null;
if (cmdletContext.CustomizedMetricSpecification_Statistic != null)
{
requestTargetTrackingConfiguration_targetTrackingConfiguration_CustomizedMetricSpecification_customizedMetricSpecification_Statistic = cmdletContext.CustomizedMetricSpecification_Statistic;
}
if (requestTargetTrackingConfiguration_targetTrackingConfiguration_CustomizedMetricSpecification_customizedMetricSpecification_Statistic != null)
{
requestTargetTrackingConfiguration_targetTrackingConfiguration_CustomizedMetricSpecification.Statistic = requestTargetTrackingConfiguration_targetTrackingConfiguration_CustomizedMetricSpecification_customizedMetricSpecification_Statistic;
requestTargetTrackingConfiguration_targetTrackingConfiguration_CustomizedMetricSpecificationIsNull = false;
}
System.String requestTargetTrackingConfiguration_targetTrackingConfiguration_CustomizedMetricSpecification_customizedMetricSpecification_Unit = null;
if (cmdletContext.CustomizedMetricSpecification_Unit != null)
{
requestTargetTrackingConfiguration_targetTrackingConfiguration_CustomizedMetricSpecification_customizedMetricSpecification_Unit = cmdletContext.CustomizedMetricSpecification_Unit;
}
if (requestTargetTrackingConfiguration_targetTrackingConfiguration_CustomizedMetricSpecification_customizedMetricSpecification_Unit != null)
{
requestTargetTrackingConfiguration_targetTrackingConfiguration_CustomizedMetricSpecification.Unit = requestTargetTrackingConfiguration_targetTrackingConfiguration_CustomizedMetricSpecification_customizedMetricSpecification_Unit;
requestTargetTrackingConfiguration_targetTrackingConfiguration_CustomizedMetricSpecificationIsNull = false;
}
// determine if requestTargetTrackingConfiguration_targetTrackingConfiguration_CustomizedMetricSpecification should be set to null
if (requestTargetTrackingConfiguration_targetTrackingConfiguration_CustomizedMetricSpecificationIsNull)
{
requestTargetTrackingConfiguration_targetTrackingConfiguration_CustomizedMetricSpecification = null;
}
if (requestTargetTrackingConfiguration_targetTrackingConfiguration_CustomizedMetricSpecification != null)
{
request.TargetTrackingConfiguration.CustomizedMetricSpecification = requestTargetTrackingConfiguration_targetTrackingConfiguration_CustomizedMetricSpecification;
requestTargetTrackingConfigurationIsNull = false;
}
// determine if request.TargetTrackingConfiguration should be set to null
if (requestTargetTrackingConfigurationIsNull)
{
request.TargetTrackingConfiguration = null;
}
CmdletOutput output;
// issue call
var client = Client ?? CreateClient(_CurrentCredentials, _RegionEndpoint);
try
{
var response = CallAWSServiceOperation(client, request);
object pipelineOutput = null;
pipelineOutput = cmdletContext.Select(response, this);
output = new CmdletOutput
{
PipelineOutput = pipelineOutput,
ServiceResponse = response
};
}
catch (Exception e)
{
output = new CmdletOutput { ErrorResponse = e };
}
return output;
}
public ExecutorContext CreateContext()
{
return new CmdletContext();
}
#endregion
#region AWS Service Operation Call
private Amazon.AutoScaling.Model.PutScalingPolicyResponse CallAWSServiceOperation(IAmazonAutoScaling client, Amazon.AutoScaling.Model.PutScalingPolicyRequest request)
{
Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "AWS Auto Scaling", "PutScalingPolicy");
try
{
#if DESKTOP
return client.PutScalingPolicy(request);
#elif CORECLR
return client.PutScalingPolicyAsync(request).GetAwaiter().GetResult();
#else
#error "Unknown build edition"
#endif
}
catch (AmazonServiceException exc)
{
var webException = exc.InnerException as System.Net.WebException;
if (webException != null)
{
throw new Exception(Utils.Common.FormatNameResolutionFailureMessage(client.Config, webException.Message), webException);
}
throw;
}
}
#endregion
internal partial class CmdletContext : ExecutorContext
{
public System.String AdjustmentType { get; set; }
public System.String AutoScalingGroupName { get; set; }
public System.Int32? Cooldown { get; set; }
public System.Boolean? Enabled { get; set; }
public System.Int32? EstimatedInstanceWarmup { get; set; }
public System.String MetricAggregationType { get; set; }
public System.Int32? MinAdjustmentMagnitude { get; set; }
public System.Int32? MinAdjustmentStep { get; set; }
public System.String PolicyName { get; set; }
public System.String PolicyType { get; set; }
public Amazon.AutoScaling.PredictiveScalingMaxCapacityBreachBehavior PredictiveScalingConfiguration_MaxCapacityBreachBehavior { get; set; }
public System.Int32? PredictiveScalingConfiguration_MaxCapacityBuffer { get; set; }
public List PredictiveScalingConfiguration_MetricSpecification { get; set; }
public Amazon.AutoScaling.PredictiveScalingMode PredictiveScalingConfiguration_Mode { get; set; }
public System.Int32? PredictiveScalingConfiguration_SchedulingBufferTime { get; set; }
public System.Int32? ScalingAdjustment { get; set; }
public List StepAdjustment { get; set; }
public List CustomizedMetricSpecification_Dimension { get; set; }
public System.String CustomizedMetricSpecification_MetricName { get; set; }
public List CustomizedMetricSpecification_Metric { get; set; }
public System.String CustomizedMetricSpecification_Namespace { get; set; }
public Amazon.AutoScaling.MetricStatistic CustomizedMetricSpecification_Statistic { get; set; }
public System.String CustomizedMetricSpecification_Unit { get; set; }
public System.Boolean? TargetTrackingConfiguration_DisableScaleIn { get; set; }
public Amazon.AutoScaling.MetricType PredefinedMetricSpecification_PredefinedMetricType { get; set; }
public System.String PredefinedMetricSpecification_ResourceLabel { get; set; }
public System.Double? TargetTrackingConfiguration_TargetValue { get; set; }
public System.Func Select { get; set; } =
(response, cmdlet) => response;
}
}
}