Created
June 8, 2020 08:50
-
-
Save darko-mesaros/96da6f5178b6ce444118d1ca996d8738 to your computer and use it in GitHub Desktop.
AWS CDK - Launch an EC2 Autoscaling Group with userdata read of disk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// VPC | |
const vpc = new ec2.Vpc(this, 'VPC'); | |
// Security group | |
const webSg = new ec2.SecurityGroup(this, 'WebSG',{ | |
vpc: vpc, | |
allowAllOutbound: true, | |
description: "Web Server Security Group" | |
}); | |
webSg.addIngressRule(ec2.Peer.anyIpv4(), ec2.Port.tcp(8080), 'Web from anywhere') | |
// ASG Configuration | |
const asg = new autoscaling.AutoScalingGroup(this, 'ASG', { | |
vpc: vpc, | |
instanceType: ec2.InstanceType.of(ec2.InstanceClass.BURSTABLE2, ec2.InstanceSize.MICRO), | |
machineImage: new ec2.AmazonLinuxImage(), // get the latest Amazon Linux image | |
maxCapacity: 5, | |
minCapacity: 1, | |
desiredCapacity: 3, | |
role: instanceRole | |
}); | |
// Add user Data | |
var bootscript:string; | |
bootscript = fs.readFileSync('assets/userdata.sh','utf8'); | |
asg.addUserData(bootscript); | |
asg.addSecurityGroup(webSg) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment