diff --git a/lib/argument-store.js b/lib/argument-store.js index 3cc4f79..c4b3118 100644 --- a/lib/argument-store.js +++ b/lib/argument-store.js @@ -43,6 +43,9 @@ class ArgumentStore { "SEMAPHORE_AGENT_OVERPROVISION_FACTOR": "0", "SEMAPHORE_AGENT_USE_IPV6": "false", "SEMAPHORE_AGENT_ALLOW_PUBLIC_SUBNET": "false", + "SEMAPHORE_AGENT_ON_DEMAND_BASE_CAPACITY": "0", + "SEMAPHORE_AGENT_ON_DEMAND_PERCENTAGE_ABOVE_BASE": "100", + "SEMAPHORE_AGENT_SPOT_ALLOCATION_STRATEGY": "", } static validOverprovisionStrategies = ["none", "number", "percentage"] diff --git a/lib/aws-semaphore-agent-stack.js b/lib/aws-semaphore-agent-stack.js index b18968f..e7a0678 100644 --- a/lib/aws-semaphore-agent-stack.js +++ b/lib/aws-semaphore-agent-stack.js @@ -470,11 +470,11 @@ class AwsSemaphoreAgentStack extends Stack { createAutoScalingGroup(launchTemplate) { const cfnLaunchTemplate = launchTemplate.node.defaultChild - let autoScalingGroup = new CfnAutoScalingGroup(this, 'autoScalingGroup', { - launchTemplate: { - launchTemplateId: cfnLaunchTemplate.ref, - version: cfnLaunchTemplate.attrLatestVersionNumber - }, + const onDemandBaseCapacity = this.argumentStore.getAsNumber("SEMAPHORE_AGENT_ON_DEMAND_BASE_CAPACITY"); + const onDemandPercentageAboveBase = this.argumentStore.getAsNumber("SEMAPHORE_AGENT_ON_DEMAND_PERCENTAGE_ABOVE_BASE"); + const spotAllocationStrategy = this.argumentStore.get("SEMAPHORE_AGENT_SPOT_ALLOCATION_STRATEGY"); + + let autoScalingGroupProps = { minSize: this.argumentStore.get("SEMAPHORE_AGENT_ASG_MIN_SIZE"), maxSize: this.argumentStore.get("SEMAPHORE_AGENT_ASG_MAX_SIZE"), cooldown: "60", @@ -485,7 +485,28 @@ class AwsSemaphoreAgentStack extends Stack { propagateAtLaunch: true } ], - }); + }; + + const instancesDistribution = { + onDemandBaseCapacity: onDemandBaseCapacity, + onDemandPercentageAboveBaseCapacity: onDemandPercentageAboveBase + }; + + if (spotAllocationStrategy != "") { + instancesDistribution.spotAllocationStrategy = spotAllocationStrategy; + } + + autoScalingGroupProps.mixedInstancesPolicy = { + instancesDistribution: instancesDistribution, + launchTemplate: { + launchTemplateSpecification: { + launchTemplateId: cfnLaunchTemplate.ref, + version: cfnLaunchTemplate.attrLatestVersionNumber + } + } + }; + + let autoScalingGroup = new CfnAutoScalingGroup(this, 'autoScalingGroup', autoScalingGroupProps); const maxInstanceLifetime = this.argumentStore.getAsNumber("SEMAPHORE_AGENT_ASG_MAX_INSTANCE_LIFETIME"); if (maxInstanceLifetime !== 0) {