UNPKG

@pulumi/aws

Version:

A Pulumi package for creating and managing Amazon Web Services (AWS) cloud resources.

268 lines • 11.3 kB
"use strict"; // *** WARNING: this file was generated by pulumi-language-nodejs. *** // *** Do not edit by hand unless you're certain you know what you are doing! *** Object.defineProperty(exports, "__esModule", { value: true }); exports.Policy = void 0; const pulumi = require("@pulumi/pulumi"); const utilities = require("../utilities"); /** * Provides an AutoScaling Scaling Policy resource. * * > **NOTE:** You may want to omit `desiredCapacity` attribute from attached `aws.autoscaling.Group` * when using autoscaling policies. It's good practice to pick either * [manual](https://docs.aws.amazon.com/AutoScaling/latest/DeveloperGuide/as-manual-scaling.html) * or [dynamic](https://docs.aws.amazon.com/AutoScaling/latest/DeveloperGuide/as-scale-based-on-demand.html) * (policy-based) scaling. * * ## Example Usage * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as aws from "@pulumi/aws"; * * const bar = new aws.autoscaling.Group("bar", { * availabilityZones: ["us-east-1a"], * name: "foobar3-test", * maxSize: 5, * minSize: 2, * healthCheckGracePeriod: 300, * healthCheckType: "ELB", * forceDelete: true, * launchConfiguration: foo.name, * }); * const bat = new aws.autoscaling.Policy("bat", { * name: "foobar3-test", * scalingAdjustment: 4, * adjustmentType: "ChangeInCapacity", * cooldown: 300, * autoscalingGroupName: bar.name, * }); * ``` * * ### Create target tracking scaling policy using metric math * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as aws from "@pulumi/aws"; * * const example = new aws.autoscaling.Policy("example", { * autoscalingGroupName: "my-test-asg", * name: "foo", * policyType: "TargetTrackingScaling", * targetTrackingConfiguration: { * targetValue: 100, * customizedMetricSpecification: { * metrics: [ * { * label: "Get the queue size (the number of messages waiting to be processed)", * id: "m1", * metricStat: { * metric: { * namespace: "AWS/SQS", * metricName: "ApproximateNumberOfMessagesVisible", * dimensions: [{ * name: "QueueName", * value: "my-queue", * }], * }, * stat: "Sum", * period: 10, * }, * returnData: false, * }, * { * label: "Get the group size (the number of InService instances)", * id: "m2", * metricStat: { * metric: { * namespace: "AWS/AutoScaling", * metricName: "GroupInServiceInstances", * dimensions: [{ * name: "AutoScalingGroupName", * value: "my-asg", * }], * }, * stat: "Average", * period: 10, * }, * returnData: false, * }, * { * label: "Calculate the backlog per instance", * id: "e1", * expression: "m1 / m2", * returnData: true, * }, * ], * }, * }, * }); * ``` * * ### Create predictive scaling policy using customized metrics * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as aws from "@pulumi/aws"; * * const example = new aws.autoscaling.Policy("example", { * autoscalingGroupName: "my-test-asg", * name: "foo", * policyType: "PredictiveScaling", * predictiveScalingConfiguration: { * metricSpecification: { * targetValue: 10, * customizedLoadMetricSpecification: { * metricDataQueries: [{ * id: "load_sum", * expression: "SUM(SEARCH('{AWS/EC2,AutoScalingGroupName} MetricName=\"CPUUtilization\" my-test-asg', 'Sum', 3600))", * }], * }, * customizedCapacityMetricSpecification: { * metricDataQueries: [{ * id: "capacity_sum", * expression: "SUM(SEARCH('{AWS/AutoScaling,AutoScalingGroupName} MetricName=\"GroupInServiceIntances\" my-test-asg', 'Average', 300))", * }], * }, * customizedScalingMetricSpecification: { * metricDataQueries: [ * { * id: "capacity_sum", * expression: "SUM(SEARCH('{AWS/AutoScaling,AutoScalingGroupName} MetricName=\"GroupInServiceIntances\" my-test-asg', 'Average', 300))", * returnData: false, * }, * { * id: "load_sum", * expression: "SUM(SEARCH('{AWS/EC2,AutoScalingGroupName} MetricName=\"CPUUtilization\" my-test-asg', 'Sum', 300))", * returnData: false, * }, * { * id: "weighted_average", * expression: "load_sum / (capacity_sum * PERIOD(capacity_sum) / 60)", * }, * ], * }, * }, * }, * }); * ``` * * ### Create predictive scaling policy using customized scaling and predefined load metric * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as aws from "@pulumi/aws"; * * const example = new aws.autoscaling.Policy("example", { * autoscalingGroupName: "my-test-asg", * name: "foo", * policyType: "PredictiveScaling", * predictiveScalingConfiguration: { * metricSpecification: { * targetValue: 10, * predefinedLoadMetricSpecification: { * predefinedMetricType: "ASGTotalCPUUtilization", * resourceLabel: "app/my-alb/778d41231b141a0f/targetgroup/my-alb-target-group/943f017f100becff", * }, * customizedScalingMetricSpecification: { * metricDataQueries: [{ * id: "scaling", * metricStat: { * metric: { * metricName: "CPUUtilization", * namespace: "AWS/EC2", * dimensions: [{ * name: "AutoScalingGroupName", * value: "my-test-asg", * }], * }, * stat: "Average", * }, * }], * }, * }, * }, * }); * ``` * * ## Import * * Using `pulumi import`, import AutoScaling scaling policy using the role autoscaling_group_name and name separated by `/`. For example: * * ```sh * $ pulumi import aws:autoscaling/policy:Policy test-policy asg-name/policy-name * ``` */ class Policy extends pulumi.CustomResource { /** * Get an existing Policy resource's state with the given name, ID, and optional extra * properties used to qualify the lookup. * * @param name The _unique_ name of the resulting resource. * @param id The _unique_ provider ID of the resource to lookup. * @param state Any extra arguments used during the lookup. * @param opts Optional settings to control the behavior of the CustomResource. */ static get(name, id, state, opts) { return new Policy(name, state, { ...opts, id: id }); } /** * Returns true if the given object is an instance of Policy. This is designed to work even * when multiple copies of the Pulumi SDK have been loaded into the same process. */ static isInstance(obj) { if (obj === undefined || obj === null) { return false; } return obj['__pulumiType'] === Policy.__pulumiType; } constructor(name, argsOrState, opts) { let resourceInputs = {}; opts = opts || {}; if (opts.id) { const state = argsOrState; resourceInputs["adjustmentType"] = state?.adjustmentType; resourceInputs["arn"] = state?.arn; resourceInputs["autoscalingGroupName"] = state?.autoscalingGroupName; resourceInputs["cooldown"] = state?.cooldown; resourceInputs["enabled"] = state?.enabled; resourceInputs["estimatedInstanceWarmup"] = state?.estimatedInstanceWarmup; resourceInputs["metricAggregationType"] = state?.metricAggregationType; resourceInputs["minAdjustmentMagnitude"] = state?.minAdjustmentMagnitude; resourceInputs["name"] = state?.name; resourceInputs["policyType"] = state?.policyType; resourceInputs["predictiveScalingConfiguration"] = state?.predictiveScalingConfiguration; resourceInputs["region"] = state?.region; resourceInputs["scalingAdjustment"] = state?.scalingAdjustment; resourceInputs["stepAdjustments"] = state?.stepAdjustments; resourceInputs["targetTrackingConfiguration"] = state?.targetTrackingConfiguration; } else { const args = argsOrState; if (args?.autoscalingGroupName === undefined && !opts.urn) { throw new Error("Missing required property 'autoscalingGroupName'"); } resourceInputs["adjustmentType"] = args?.adjustmentType; resourceInputs["autoscalingGroupName"] = args?.autoscalingGroupName; resourceInputs["cooldown"] = args?.cooldown; resourceInputs["enabled"] = args?.enabled; resourceInputs["estimatedInstanceWarmup"] = args?.estimatedInstanceWarmup; resourceInputs["metricAggregationType"] = args?.metricAggregationType; resourceInputs["minAdjustmentMagnitude"] = args?.minAdjustmentMagnitude; resourceInputs["name"] = args?.name; resourceInputs["policyType"] = args?.policyType; resourceInputs["predictiveScalingConfiguration"] = args?.predictiveScalingConfiguration; resourceInputs["region"] = args?.region; resourceInputs["scalingAdjustment"] = args?.scalingAdjustment; resourceInputs["stepAdjustments"] = args?.stepAdjustments; resourceInputs["targetTrackingConfiguration"] = args?.targetTrackingConfiguration; resourceInputs["arn"] = undefined /*out*/; } opts = pulumi.mergeOptions(utilities.resourceOptsDefaults(), opts); super(Policy.__pulumiType, name, resourceInputs, opts); } } exports.Policy = Policy; /** @internal */ Policy.__pulumiType = 'aws:autoscaling/policy:Policy'; //# sourceMappingURL=policy.js.map