Skip to content

Instantly share code, notes, and snippets.

@kaugm
Last active April 3, 2023 20:57
Show Gist options
  • Save kaugm/f51be2aa6679380efc46084d14c78dc4 to your computer and use it in GitHub Desktop.
Save kaugm/f51be2aa6679380efc46084d14c78dc4 to your computer and use it in GitHub Desktop.
Create an Elastigroup with CloudFormation (Example)
AWSTemplateFormatVersion: "2010-09-09"
Description: This template creates an Elastigroup. This is not meant to be run as a standalone CloudFormation template, but rather to have the Parameters and Resource added to existing ASG CloudFormation templates to create and manage both simultaneously. All API parameters in Spot documentation are valid for the Elastigroup resource https://docs.spot.io/api/#tag/Elastigroup-AWS/operation/elastigroupAwsCreate
Parameters:
ServiceToken:
Type: String
Description: ARN of Lambda function in Spot's AWS account that will handle creation of Elastigroup. DO NOT CHANGE THIS.
Default: arn:aws:lambda:us-west-2:178579023202:function:spotinst-cloudformation
accessToken:
NoEcho: 'true'
Type: String
Description: Spot.io access token. Create this within the Spot.io console.
accountId:
Type: String
Description: Account ID of the Spot.io account in which to create the Elastigroup. You can find this in the Spot.io console.
shouldRoll:
Type: String
Default: 'false'
Description: Should roll when updating. Defaults to YES if not set.
shouldUpdateTargetCapacity:
Type: String
Default: 'false'
AllowedValues:
- 'false'
- 'true'
Description: Should update target capacity on group update. Recommend FALSE if the target capacity is specified in Resources section.
batchSizePercentage:
Type: Number
Default: 50
Description: Percentage of Elastigroup that should be rolled/deployed at a single time (Rolling update size percentage)
gracePeriod:
Type: Number
Default: 600
Description: Wait time to check if instances are healthy before continuing with the next batch.
amiID:
Type: String
Default: 'ami-0620766f9d10d6c9e'
Description: Image ID of AMI to be used for EC2 nodes launched.
keyPair:
Type: String
Default: 'Karl-Lab-key-pair'
Description: SSH Key for EC2 nodes.
Resources:
SpotinstElastigroup:
Type: Custom::elasticgroup
Properties:
ServiceToken:
Ref: ServiceToken
accessToken:
Ref: accessToken
accountId:
Ref: accountId
updatePolicy:
shouldRoll:
Ref: shouldRoll
rollConfig:
batchSizePercentage:
Ref: batchSizePercentage
gracePeriod:
Ref: gracePeriod
shouldUpdateTargetCapacity:
Ref: shouldUpdateTargetCapacity
group:
name: KarlElastigroupCloudFormation
strategy:
risk: 100
onDemandCount: 0
availabilityVsCost: costOriented
utilizeReservedInstances: false
fallbackToOd: true
capacity:
target: 1
minimum: 1
maximum: 1
scaling:
target:
- policyName: target_policy_1
metricName: CPUUtilization
statistic: average
source: cloudWatch
unit: percent
target: 50
namespace: AWS/EC2
cooldown: 300
compute:
instanceTypes:
ondemand: m3.large
spot:
- m3.large
- m4.large
- c3.large
- c4.large
availabilityZones:
- name: us-west-2a
subnetId: !Ref PublicSubnet1
launchSpecification:
monitoring: false
imageId: !Ref amiID
keyPair: !Ref keyPair
securityGroupIds:
- !Ref InstanceSecurityGroup
product: Linux/UNIX
thirdPartiesIntegration: {}
Outputs:
groupId:
Value:
Ref: SpotinstElastigroup
@kaugm
Copy link
Author

kaugm commented Apr 3, 2023

All API parameters in Spot documentation are valid for the Elastigroup resource https://docs.spot.io/api/#tag/Elastigroup-AWS/operation/elastigroupAwsCreate

Configuration changes to Elastigroup can be done under the 'group' attributes block.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment