Skip to content

Commit

Permalink
feat(guest-webapp-sample): Replace LaunchConfiguration with LaunchTem…
Browse files Browse the repository at this point in the history
…plate (#183)

Due to deprecation of LaunchConfiguration, replace it with LaunchTemplate.
  • Loading branch information
tomoki10 authored Jan 31, 2023
1 parent a03b2b9 commit 0102836
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 61 deletions.
30 changes: 16 additions & 14 deletions usecases/guest-webapp-sample/lib/blea-asgapp-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,23 @@ export class BLEAASGAppStack extends cdk.Stack {
vpcSubnets: props.myVpc.selectSubnets({
subnetGroupName: 'Private',
}),
instanceType: ec2.InstanceType.of(ec2.InstanceClass.T3, ec2.InstanceSize.MICRO),
machineImage: new ec2.AmazonLinuxImage({
generation: ec2.AmazonLinuxGeneration.AMAZON_LINUX_2,
launchTemplate: new ec2.LaunchTemplate(this, 'LaunchTemplate', {
instanceType: ec2.InstanceType.of(ec2.InstanceClass.T3, ec2.InstanceSize.MICRO),
machineImage: new ec2.AmazonLinuxImage({
generation: ec2.AmazonLinuxGeneration.AMAZON_LINUX_2,
}),
userData: userDataForApp,
role: ssmInstanceRole,
blockDevices: [
{
deviceName: '/dev/xvda',
volume: autoscaling.BlockDeviceVolume.ebs(10, {
encrypted: true,
}),
},
],
securityGroup: securityGroupForApp,
}),
blockDevices: [
{
deviceName: '/dev/xvda',
volume: autoscaling.BlockDeviceVolume.ebs(10, {
encrypted: true,
}),
},
],
securityGroup: securityGroupForApp,
role: ssmInstanceRole,
userData: userDataForApp,
healthCheck: autoscaling.HealthCheck.elb({
grace: cdk.Duration.seconds(60),
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1946,8 +1946,16 @@ Object {
"Properties": Object {
"HealthCheckGracePeriod": 60,
"HealthCheckType": "ELB",
"LaunchConfigurationName": Object {
"Ref": "AsgAppLaunchConfig341A9477",
"LaunchTemplate": Object {
"LaunchTemplateId": Object {
"Ref": "LaunchTemplate04EC5460",
},
"Version": Object {
"Fn::GetAtt": Array [
"LaunchTemplate04EC5460",
"LatestVersionNumber",
],
},
},
"MaxSize": "4",
"MinSize": "2",
Expand Down Expand Up @@ -1989,70 +1997,117 @@ Object {
},
},
},
"AsgAppInstanceProfile21D0A966": Object {
"AsgAppScalingPolicykeepSpareCPU63DAB833": Object {
"Properties": Object {
"Roles": Array [
Object {
"Ref": "ssminstancerole0E7D791C",
"AutoScalingGroupName": Object {
"Ref": "AsgAppASG65DC93B2",
},
"PolicyType": "TargetTrackingScaling",
"TargetTrackingConfiguration": Object {
"PredefinedMetricSpecification": Object {
"PredefinedMetricType": "ASGAverageCPUUtilization",
},
],
"TargetValue": 50,
},
},
"Type": "AWS::IAM::InstanceProfile",
"Type": "AWS::AutoScaling::ScalingPolicy",
},
"AsgAppLaunchConfig341A9477": Object {
"DependsOn": Array [
"ssminstancerole0E7D791C",
],
"LaunchTemplate04EC5460": Object {
"Properties": Object {
"BlockDeviceMappings": Array [
Object {
"DeviceName": "/dev/xvda",
"Ebs": Object {
"Encrypted": true,
"VolumeSize": 10,
"LaunchTemplateData": Object {
"BlockDeviceMappings": Array [
Object {
"DeviceName": "/dev/xvda",
"Ebs": Object {
"Encrypted": true,
"VolumeSize": 10,
},
},
],
"IamInstanceProfile": Object {
"Arn": Object {
"Fn::GetAtt": Array [
"LaunchTemplateProfile94AA77CE",
"Arn",
],
},
},
],
"IamInstanceProfile": Object {
"Ref": "AsgAppInstanceProfile21D0A966",
},
"ImageId": Object {
"Ref": "SsmParameterValueawsserviceamiamazonlinuxlatestamzn2amihvmx8664gp2C96584B6F00A464EAD1953AFF4B05118Parameter",
},
"InstanceType": "t3.micro",
"SecurityGroups": Array [
Object {
"Fn::GetAtt": Array [
"SgApp7DE78E7E",
"GroupId",
],
"ImageId": Object {
"Ref": "SsmParameterValueawsserviceamiamazonlinuxlatestamzn2amihvmx8664gp2C96584B6F00A464EAD1953AFF4B05118Parameter",
},
],
"UserData": Object {
"Fn::Base64": "#!/bin/bash
"InstanceType": "t3.micro",
"SecurityGroupIds": Array [
Object {
"Fn::GetAtt": Array [
"SgApp7DE78E7E",
"GroupId",
],
},
],
"TagSpecifications": Array [
Object {
"ResourceType": "instance",
"Tags": Array [
Object {
"Key": "Environment",
"Value": "Development",
},
Object {
"Key": "Name",
"Value": "BLEA-ASGApp/LaunchTemplate",
},
],
},
Object {
"ResourceType": "volume",
"Tags": Array [
Object {
"Key": "Environment",
"Value": "Development",
},
Object {
"Key": "Name",
"Value": "BLEA-ASGApp/LaunchTemplate",
},
],
},
],
"UserData": Object {
"Fn::Base64": "#!/bin/bash
sudo yum -y install httpd
sudo systemctl enable httpd
sudo systemctl start httpd
touch /var/www/html/index.html
chown apache.apache /var/www/html/index.html",
},
},
"TagSpecifications": Array [
Object {
"ResourceType": "launch-template",
"Tags": Array [
Object {
"Key": "Environment",
"Value": "Development",
},
Object {
"Key": "Name",
"Value": "BLEA-ASGApp/LaunchTemplate",
},
],
},
],
},
"Type": "AWS::AutoScaling::LaunchConfiguration",
"Type": "AWS::EC2::LaunchTemplate",
},
"AsgAppScalingPolicykeepSpareCPU63DAB833": Object {
"LaunchTemplateProfile94AA77CE": Object {
"Properties": Object {
"AutoScalingGroupName": Object {
"Ref": "AsgAppASG65DC93B2",
},
"PolicyType": "TargetTrackingScaling",
"TargetTrackingConfiguration": Object {
"PredefinedMetricSpecification": Object {
"PredefinedMetricType": "ASGAverageCPUUtilization",
"Roles": Array [
Object {
"Ref": "ssminstancerole0E7D791C",
},
"TargetValue": 50,
},
],
},
"Type": "AWS::AutoScaling::ScalingPolicy",
"Type": "AWS::IAM::InstanceProfile",
},
"SgAlbEA3AC417": Object {
"Properties": Object {
Expand Down

0 comments on commit 0102836

Please sign in to comment.