A Pulumi package for creating and managing Amazon Web Services (AWS) cloud resources with infrastructure-as-code.
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Amazon EC2 Auto Scaling helps maintain application availability and scale EC2 capacity automatically.
const asg = new aws.autoscaling.Group("web-asg", {
maxSize: 5,
minSize: 1,
desiredCapacity: 2,
launchTemplate: {
id: template.id,
version: "$Latest",
},
vpcZoneIdentifiers: [subnet1.id, subnet2.id],
healthCheckType: "ELB",
healthCheckGracePeriod: 300,
});const policy = new aws.autoscaling.Policy("cpu-scaling", {
autoscalingGroupName: asg.name,
policyType: "TargetTrackingScaling",
targetTrackingConfiguration: {
predefinedMetricSpecification: {
predefinedMetricType: "ASGAverageCPUUtilization",
},
targetValue: 70.0,
},
});class Group extends pulumi.CustomResource {
constructor(name: string, args: GroupArgs, opts?: pulumi.CustomResourceOptions);
}
interface GroupArgs {
maxSize: pulumi.Input<number>;
minSize: pulumi.Input<number>;
desiredCapacity?: pulumi.Input<number>;
launchConfiguration?: pulumi.Input<string>;
launchTemplate?: pulumi.Input<GroupLaunchTemplate>;
vpcZoneIdentifiers?: pulumi.Input<pulumi.Input<string>[]>;
healthCheckType?: pulumi.Input<"EC2" | "ELB">;
tags?: pulumi.Input<pulumi.Input<GroupTag>[]>;
}
interface GroupLaunchTemplate {
id?: pulumi.Input<string>;
name?: pulumi.Input<string>;
version?: pulumi.Input<string>;
}
interface GroupTag {
key: pulumi.Input<string>;
value: pulumi.Input<string>;
propagateAtLaunch: pulumi.Input<boolean>;
}Usage Example:
// Create launch template
const template = new aws.ec2.LaunchTemplate("web-template", {
imageId: ami.id,
instanceType: "t3.micro",
vpcSecurityGroupIds: [sg.id],
userData: pulumi.interpolate`#!/bin/bash
echo "Hello from Auto Scaling!" > /var/www/html/index.html
yum install -y httpd
systemctl start httpd
`,
});
// Create auto scaling group
const asg = new aws.autoscaling.Group("web-asg", {
maxSize: 5,
minSize: 1,
desiredCapacity: 2,
launchTemplate: {
id: template.id,
version: "$Latest",
},
vpcZoneIdentifiers: [subnet1.id, subnet2.id],
healthCheckType: "ELB",
healthCheckGracePeriod: 300,
tags: [{
key: "Name",
value: "web-server",
propagateAtLaunch: true,
}],
});class Policy extends pulumi.CustomResource {
constructor(name: string, args: PolicyArgs, opts?: pulumi.CustomResourceOptions);
}
interface PolicyArgs {
autoscalingGroupName: pulumi.Input<string>;
policyType?: pulumi.Input<"SimpleScaling" | "StepScaling" | "TargetTrackingScaling">;
adjustmentType?: pulumi.Input<string>;
scalingAdjustment?: pulumi.Input<number>;
}Usage Example:
// Simple scaling policy
const simplePolicy = new aws.autoscaling.Policy("scale-up", {
autoscalingGroupName: asg.name,
policyType: "SimpleScaling",
adjustmentType: "ChangeInCapacity",
scalingAdjustment: 1,
cooldown: 300,
});
// Target tracking policy
const targetPolicy = new aws.autoscaling.Policy("cpu-tracking", {
autoscalingGroupName: asg.name,
policyType: "TargetTrackingScaling",
targetTrackingConfiguration: {
predefinedMetricSpecification: {
predefinedMetricType: "ASGAverageCPUUtilization",
},
targetValue: 70.0,
},
});
// Step scaling policy
const stepPolicy = new aws.autoscaling.Policy("step-scaling", {
autoscalingGroupName: asg.name,
policyType: "StepScaling",
adjustmentType: "PercentChangeInCapacity",
metricAggregationType: "Average",
stepAdjustments: [
{
metricIntervalLowerBound: 0,
metricIntervalUpperBound: 10,
scalingAdjustment: 10,
},
{
metricIntervalLowerBound: 10,
scalingAdjustment: 20,
},
],
});import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
// Create launch template
const template = new aws.ec2.LaunchTemplate("web-template", {
imageId: ami.id,
instanceType: "t3.micro",
vpcSecurityGroupIds: [sg.id],
iamInstanceProfile: {
arn: instanceProfile.arn,
},
});
// Create auto scaling group
const asg = new aws.autoscaling.Group("web-asg", {
maxSize: 10,
minSize: 2,
desiredCapacity: 3,
launchTemplate: {
id: template.id,
version: "$Latest",
},
vpcZoneIdentifiers: [subnet1.id, subnet2.id, subnet3.id],
healthCheckType: "ELB",
healthCheckGracePeriod: 300,
targetGroupArns: [targetGroup.arn],
tags: [{
key: "Name",
value: "web-server",
propagateAtLaunch: true,
}],
});
// Create target tracking scaling policy
const policy = new aws.autoscaling.Policy("cpu-scaling", {
autoscalingGroupName: asg.name,
policyType: "TargetTrackingScaling",
targetTrackingConfiguration: {
predefinedMetricSpecification: {
predefinedMetricType: "ASGAverageCPUUtilization",
},
targetValue: 70.0,
},
});
export const asgName = asg.name;For complete Auto Scaling API, see All Services.
Install with Tessl CLI
npx tessl i tessl/npm-pulumi--aws