How to use the @pulumi/aws.autoscaling function in @pulumi/aws

To help you get started, we’ve selected a few @pulumi/aws examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pulumi / pulumi-awsx / nodejs / awsx / autoscaling / autoscaling.ts View on Github external
public scaleOnSchedule(name: string, args: ScheduleArgs, opts: pulumi.CustomResourceOptions = {}) {
        const recurrence = args.recurrence === undefined
            ? undefined
            : pulumi.output(args.recurrence).apply(
                x => typeof x === "string" ? x : cronExpression(x));

        return new aws.autoscaling.Schedule(name, {
            ...args,
            recurrence,
            autoscalingGroupName: this.group.name,
            scheduledActionName: args.scheduledActionName || name,
            // Have to explicitly set these to -1.  If we pass 'undefined' through these will become
            // 0, which will actually set the size/capacity to that.
            minSize: utils.ifUndefined(args.minSize, -1),
            maxSize: utils.ifUndefined(args.maxSize, -1),
            desiredCapacity: utils.ifUndefined(args.desiredCapacity, -1),
        }, { parent: this, ...opts });
    }
github pulumi / pulumi-awsx / nodejs / awsx / autoscaling / autoscaling.ts View on Github external
// Use cloudformation to actually construct the autoscaling group.
        this.stack = new aws.cloudformation.Stack(name, {
            ...args,
            name: this.launchConfiguration.stackName,
            templateBody: getCloudFormationTemplate(
                name,
                this.launchConfiguration.id,
                subnetIds,
                targetGroupArns,
                utils.ifUndefined(args.templateParameters, {})),
        }, parentOpts);

        // Now go and actually find the group created by cloudformation.  The id for the group will
        // be stored in `stack.outputs.Instances`.
        this.group = aws.autoscaling.Group.get(name, this.stack.outputs["Instances"], undefined, parentOpts);

        this.registerOutputs();
    }
github pulumi / pulumi-awsx / nodejs / awsx / autoscaling / stepScaling.ts View on Github external
metricAggregationType,
            ...args,
        };

        // AutoScaling recommends a metric of 60 to ensure that adjustments can happen in a timely
        // manner.
        const metric = args.metric.withPeriod(60);
        const evaluationPeriods = utils.ifUndefined(args.evaluationPeriods, 1);

        let upperPolicy: aws.autoscaling.Policy | undefined;
        let lowerPolicy: aws.autoscaling.Policy | undefined;
        let upperAlarm: aws.cloudwatch.MetricAlarm | undefined;
        let lowerAlarm: aws.cloudwatch.MetricAlarm | undefined;

        if (args.steps.upper) {
            upperPolicy = new aws.autoscaling.Policy(`${name}-upper`, {
                ...commonArgs,
                stepAdjustments: convertedSteps.upper.stepAdjustments,
            }, { parent });

            upperAlarm = metric.createAlarm(`${name}-upper`, {
                evaluationPeriods,
                // step ranges and alarms are inclusive on the lower end.
                comparisonOperator: "GreaterThanOrEqualToThreshold",
                threshold: convertedSteps.upper.threshold,
                alarmActions: [upperPolicy.arn],
            }, { parent });
        }

        if (args.steps.lower) {
            lowerPolicy = new aws.autoscaling.Policy(`${name}-lower`, {
                ...commonArgs,
github pulumi / pulumi-awsx / nodejs / awsx / autoscaling / autoscaling.ts View on Github external
public scaleOnSchedule(name: string, args: ScheduleArgs, opts: pulumi.CustomResourceOptions = {}) {
        const recurrence = args.recurrence === undefined
            ? undefined
            : pulumi.output(args.recurrence).apply(
                x => typeof x === "string" ? x : cronExpression(x));

        return new aws.autoscaling.Schedule(name, {
            ...args,
            recurrence,
            autoscalingGroupName: this.group.name,
            scheduledActionName: args.scheduledActionName || name,
            // Have to explicitly set these to -1.  If we pass 'undefined' through these will become
            // 0, which will actually set the size/capacity to that.
            minSize: utils.ifUndefined(args.minSize, -1),
            maxSize: utils.ifUndefined(args.maxSize, -1),
            desiredCapacity: utils.ifUndefined(args.desiredCapacity, -1),
        }, { parent: this, ...opts });
    }
github pulumi / examples / aws-ts-full-stack-web-app / compute.ts View on Github external
type: "forward",
        targetGroupArn: serverTargetGroup.arn,
    }],
});

let wwwHttpsListenerRules = new aws.elasticloadbalancingv2.ListenerRule("wwwHTTPSRedirect", {
    listenerArn: loadBalancer.httpsListener.arn,
    priority: 100,
    conditions: [{ field: "path-pattern", values: "/*" }],
    actions: [{
        type: "forward",
        targetGroupArn: serverTargetGroup.arn,
    }],
});

let lbAsgAttachment = new aws.autoscaling.Attachment("lbattachment", {
    albTargetGroupArn: serverTargetGroup.arn,
    autoscalingGroupName: autoscalinggroup.name,
});

async function tgResourceLabel(lb: aws.elasticloadbalancingv2.LoadBalancer,
    tg: aws.elasticloadbalancingv2.TargetGroup): Promise {
    // "app///targetgroup//"
    return await lb.arnSuffix + "/" + await tg.arnSuffix;
}

let scalingPolicy = new aws.autoscaling.Policy("scalingpolicy", {
    autoscalingGroupName: autoscalinggroup.name,
    policyType: "TargetTrackingScaling",
    adjustmentType: "ChangeInCapacity",
    scalingAdjustment: 1,
    targetTrackingConfiguration: {
github pulumi / pulumi-awsx / nodejs / awsx / autoscaling / autoscaling.ts View on Github external
// Use cloudformation to actually construct the autoscaling group.
        this.stack = new aws.cloudformation.Stack(name, {
            ...args,
            name: this.launchConfiguration.stackName,
            templateBody: getCloudFormationTemplate(
                name,
                this.launchConfiguration.id,
                subnetIds,
                targetGroupArns,
                utils.ifUndefined(args.templateParameters, {})),
        }, { parent: this });

        // Now go and actually find the group created by cloudformation.  The id for the group will
        // be stored in `stack.outputs.Instances`.
        this.group = aws.autoscaling.Group.get(name, this.stack.outputs["Instances"], undefined, { parent: this });

        this.registerOutputs();
    }
github pulumi / examples / aws-ts-full-stack-web-app / compute.ts View on Github external
tags: { "Name": "web-server-www" },
    instanceType: machineSize,
    securityGroups: [ vmSecurityGroup.name ],
    ami: ami,
    // TEMPORARY STEP.
    userData: userData
});

let launchConfiguration = new aws.ec2.LaunchConfiguration("launchconfiguration", {
    securityGroups: [ vmSecurityGroup.id ],
    instanceType: machineSize,
    imageId: ami,
    userData: userData,
});

let autoscalinggroup = new aws.autoscaling.Group("autoscalinggroup", {
    launchConfiguration: launchConfiguration.id,
    minSize: 1,
    maxSize: 10,
    desiredCapacity: 2,
});

// TODO: Create an auto scaling group, instead of the individual EC2 instance, and then
// attach that auto scaling group to the serverTargetGroup?

// Have the server recieve traffic from the load balancer.
export let serverTargetGroup = new aws.elasticloadbalancingv2.TargetGroup("serverTargetGroup", {
    port: 80,
    protocol: "HTTP",
    vpcId: defaultVpc.vpcId,

    deregistrationDelay: 30,  // seconds
github pulumi / examples / policy-packs / aws-advanced / compute.ts View on Github external
export function requireHealthChecksOnAsgElb(name: string): ResourceValidationPolicy {
    return {
        name: name,
        description:
            "Auto Scaling groups that are associated with a load balancer should use Elastic " +
            "Load Balancing health checks",
        enforcementLevel: "mandatory",
        validateResource: validateTypedResource(aws.autoscaling.Group, (group, args, reportViolation) => {
            const classicLbAttached = group.loadBalancers && group.loadBalancers.length > 0;
            const albAttached = group.targetGroupArns && group.targetGroupArns.length > 0;
            if (classicLbAttached || albAttached) {
                if (group.healthCheckType !== "ELB") {
                    reportViolation("Auto Scaling groups that are associated with a load balancer should use Elastic " +
                        "Load Balancing health checks");
                }
            }
        }),
    };
}