aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Chandler <mchandler89@gmail.com>2024-10-06 13:44:47 +1000
committerMichael Chandler <mchandler89@gmail.com>2024-10-06 13:44:47 +1000
commit6e824670fc2cfd0081b3b31c855dbfe55a85c469 (patch)
treef88da7c2965507e4c817da0fb61adead97db72f0
parenta8b38421654e3fa2fd14fec8f4b60a2f533b5f65 (diff)
feat: Migrate from EC2 Launch Configuration to Launch Template.
-rw-r--r--cf.yml48
1 files changed, 31 insertions, 17 deletions
diff --git a/cf.yml b/cf.yml
index b269586..2eef48b 100644
--- a/cf.yml
+++ b/cf.yml
@@ -144,7 +144,8 @@ Resources:
- !GetAZs
Ref: 'AWS::Region'
CidrBlock: !Select [ 0, !Cidr [ 10.100.0.0/26, 4, 4 ] ]
- VpcId: !Ref Vpc
+ VpcId: !Ref Vpc
+ MapPublicIpOnLaunch: true
SubnetARoute:
Type: AWS::EC2::SubnetRouteTableAssociation
@@ -167,6 +168,7 @@ Resources:
Ref: 'AWS::Region'
CidrBlock: !Select [ 1, !Cidr [ 10.100.0.0/26, 4, 4 ] ]
VpcId: !Ref Vpc
+ MapPublicIpOnLaunch: true
InternetGateway:
Type: AWS::EC2::InternetGateway
@@ -260,29 +262,41 @@ Resources:
- !Ref 'AWS::NoValue'
VpcId: !Ref Vpc
- LaunchConfiguration:
- Type: AWS::AutoScaling::LaunchConfiguration
+ LaunchTemplate:
+ Type: AWS::EC2::LaunchTemplate
Properties:
- AssociatePublicIpAddress: true
- IamInstanceProfile: !Ref InstanceProfile
- ImageId: !Ref ECSAMI
- InstanceType: !Ref InstanceType
- KeyName:
- !If [ KeyPairNameProvided, !Ref KeyPairName, !Ref 'AWS::NoValue' ]
- SecurityGroups:
- - !Ref Ec2Sg
- SpotPrice: !If [ SpotPriceProvided, !Ref SpotPrice, !Ref 'AWS::NoValue' ]
- UserData:
- Fn::Base64: !Sub |
- #!/bin/bash -xe
- echo ECS_CLUSTER=${EcsCluster} >> /etc/ecs/ecs.config
+ LaunchTemplateName: !Sub ${AWS::StackName}-launch-template
+ LaunchTemplateData:
+ IamInstanceProfile:
+ Arn: !GetAtt InstanceProfile.Arn
+ ImageId: !Ref ECSAMI
+ SecurityGroupIds:
+ - !Ref Ec2Sg
+ KeyName:
+ !If [ KeyPairNameProvided, !Ref KeyPairName, !Ref 'AWS::NoValue' ]
+ UserData:
+ Fn::Base64: !Sub |
+ #!/bin/bash -xe
+ echo ECS_CLUSTER=${EcsCluster} >> /etc/ecs/ecs.config
AutoScalingGroup:
Type: AWS::AutoScaling::AutoScalingGroup
Properties:
AutoScalingGroupName: !Sub "${AWS::StackName}-asg"
DesiredCapacity: !FindInMap [ ServerState, !Ref ServerState, DesiredCapacity ]
- LaunchConfigurationName: !Ref LaunchConfiguration
+ MixedInstancesPolicy:
+ InstancesDistribution:
+ OnDemandPercentageAboveBaseCapacity:
+ !If [ SpotPriceProvided, 0, 100 ]
+ SpotAllocationStrategy: price-capacity-optimized
+ SpotMaxPrice:
+ !If [ SpotPriceProvided, !Ref SpotPrice, !Ref AWS::NoValue ]
+ LaunchTemplate:
+ LaunchTemplateSpecification:
+ LaunchTemplateId: !Ref LaunchTemplate
+ Version: !GetAtt LaunchTemplate.LatestVersionNumber
+ Overrides:
+ - InstanceType: !Ref InstanceType
MaxSize: !FindInMap [ ServerState, !Ref ServerState, DesiredCapacity ]
MinSize: !FindInMap [ ServerState, !Ref ServerState, DesiredCapacity ]
VPCZoneIdentifier:
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage