aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Chandler <mchandler89@gmail.com>2024-10-06 14:16:30 +1000
committerMichael Chandler <mchandler89@gmail.com>2024-10-06 14:16:30 +1000
commit9884a9771718ea7444039677ed9992418e1d6c09 (patch)
tree6cbf65c3da571e2a552edd3c3877340044778617
parent6e824670fc2cfd0081b3b31c855dbfe55a85c469 (diff)
feat: #31 allow user to specify vCPU / Memory and let AWS pick the best spot instance.
-rw-r--r--cf.yml54
-rw-r--r--readme.md4
2 files changed, 46 insertions, 12 deletions
diff --git a/cf.yml b/cf.yml
index 2eef48b..60f7870 100644
--- a/cf.yml
+++ b/cf.yml
@@ -20,16 +20,34 @@ Parameters:
- Running
- Stopped
+ InstancePurchaseMode:
+ Type: String
+ Description: "Spot: Much cheaper, but your instance might restart during gameplay with a few minutes of unsaved gameplay lost. On Demand: Instance will be created in on-demand mode. More expensive, but your gameplay is unlikely to be interrupted by the server going down."
+ Default: "Spot"
+ AllowedValues:
+ - "On Demand"
+ - "Spot"
+
InstanceType:
Type: String
- Description: "m3.medium is a good cost effective (albeit older) instance, 1 VCPU and 3.75 GB of RAM with moderate network performance. Change at your discretion. https://aws.amazon.com/ec2/instance-types/."
- Default: m3.medium
+ Description: "Spot: You should leave this blank to get the best value instance. Override at your discretion: https://aws.amazon.com/ec2/instance-types/. On Demand: You must specify this. "
+ Default: ""
SpotPrice:
Type: String
- Description: "An m3.medium shouldn't cost more than a cent per hour. Note: Leave this blank to use on-demand pricing."
+ Description: "Spot: the max cents/hr to pay for spot instance. On Demand: Ignored"
Default: "0.05"
+ SpotMinMemoryMiB:
+ Type: Number
+ Description: "Spot: the minimum desired memory for your instance. On Demand: Ignored"
+ Default: 2048
+
+ SpotMinVCpuCount:
+ Type: Number
+ Description: "Spot: the minimum desired VCPUs for your instance. On Demand: Ignored"
+ Default: 2
+
KeyPairName:
Type: String
Description: (Optional - An empty value disables this feature)
@@ -74,11 +92,17 @@ Metadata:
Parameters:
- FactorioImageTag
- ServerState
- - InstanceType
- - SpotPrice
- EnableRcon
- UpdateModsOnStart
- Label:
+ default: Instance Configuration
+ Parameters:
+ - InstancePurchaseMode
+ - InstanceType
+ - SpotPrice
+ - SpotMinMemoryMiB
+ - SpotMinVCpuCount
+ - Label:
default: Remote Access (SSH) Configuration (Optional)
Parameters:
- KeyPairName
@@ -95,8 +119,6 @@ Metadata:
default: "Update this parameter to shut down / start up your Factorio server as required to save on cost. Takes a few minutes to take effect."
InstanceType:
default: "Which instance type? You must make sure this is available in your region! https://aws.amazon.com/ec2/pricing/on-demand/"
- SpotPrice:
- default: "Maximum spot price per hour? Leave blank to disable spot pricing."
KeyPairName:
default: "If you wish to access the instance via SSH, select a Key Pair to use. https://console.aws.amazon.com/ec2/v2/home?#KeyPairs:sort=keyName"
YourIp:
@@ -113,8 +135,9 @@ Conditions:
KeyPairNameProvided: !Not [ !Equals [ !Ref KeyPairName, '' ] ]
IpAddressProvided: !Not [ !Equals [ !Ref YourIp, '' ] ]
DnsConfigEnabled: !And [ !Not [ !Equals [ !Ref HostedZoneId, '' ] ], !Not [ !Equals [ !Ref RecordName, '' ] ] ]
- SpotPriceProvided: !Not [ !Equals [ !Ref SpotPrice, '' ] ]
DoEnableRcon: !Equals [ !Ref EnableRcon, 'true' ]
+ UsingSpotInstance: !Equals [ !Ref InstancePurchaseMode, 'Spot' ]
+ InstanceTypeProvided: !Not [ !Equals [ !Ref InstanceType, '' ] ]
Mappings:
ServerState:
@@ -287,16 +310,23 @@ Resources:
MixedInstancesPolicy:
InstancesDistribution:
OnDemandPercentageAboveBaseCapacity:
- !If [ SpotPriceProvided, 0, 100 ]
- SpotAllocationStrategy: price-capacity-optimized
+ !If [ UsingSpotInstance, 0, 100 ]
+ SpotAllocationStrategy: lowest-price
SpotMaxPrice:
- !If [ SpotPriceProvided, !Ref SpotPrice, !Ref AWS::NoValue ]
+ !If [ UsingSpotInstance, !Ref SpotPrice, !Ref AWS::NoValue ]
LaunchTemplate:
LaunchTemplateSpecification:
LaunchTemplateId: !Ref LaunchTemplate
Version: !GetAtt LaunchTemplate.LatestVersionNumber
Overrides:
- - InstanceType: !Ref InstanceType
+ - Fn::If:
+ - InstanceTypeProvided
+ - InstanceType: !Ref InstanceType
+ - InstanceRequirements:
+ MemoryMiB:
+ Min: !Ref SpotMinMemoryMiB
+ VCpuCount:
+ Min: !Ref SpotMinVCpuCount
MaxSize: !FindInMap [ ServerState, !Ref ServerState, DesiredCapacity ]
MinSize: !FindInMap [ ServerState, !Ref ServerState, DesiredCapacity ]
VPCZoneIdentifier:
diff --git a/readme.md b/readme.md
index 04c4b02..d77bb1e 100644
--- a/readme.md
+++ b/readme.md
@@ -30,6 +30,10 @@ A few notes on the services we're using...
2. Ensure you've selected a suitable AWS Region (closest to you) via the selector at the top right.
3. Click Next to proceed through the CloudFormation deployment, provide parameters on the following page. You'll need a Key Pair and your Public IP address if you want to access the instance remotely via SSH (recommended). Refer to the Remote Access section below. There should be no need to touch any other parameters unless you have reason to do so. Continue through the rest of the deployment.
+## On Demand vs Spot
+
+You may switch between On Demand / Spot via the InstancePurchaseMode CloudFormation parameter. When using Spot, it is not necessary to specifcy an InstanceType. Simply adjust the SpotMinMemoryMiB and SpotMinVCPUCount to specify how much Memory and CPU you would like on your instance. AWS will find you the cheapest spot instance available (under the SpotPrice that you have specified). Should you wish to use a specific instance, you can specify it via the InstanceType parameter. If you are using On Demand, you must specify the InstanceType.
+
## Next Steps
All things going well, your Factorio server should be running in five minutes or so. Wait until CloudFormation reports the stack status as `CREATE_COMPLETE`. Go to the [EC2 dashboard in the AWS console](https://console.aws.amazon.com/ec2/v2/home?#Instances:sort=instanceId) and you should see a Factorio server running. Take note of the public IP address. You should be able to fire up Factorio, and join via this IP address. No need to provide a port number, we're using Factorio's default. *Bonus points* - Public IP addresses are ugly. Refer to Custom Domain Name within Optional Features for a better solution.
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage