NOTE: This repo contains only the documentation for the private BoltsOps Pro repo code. Original file: https://github.com/boltopspro/asg-worker/blob/master/README.md The docs are publish so they are available for interested customers. For access to the source code, you must be a paying BoltOps Pro subscriber. If are interested, you can contact us at contact@boltops.com or https://www.boltops.com
This blueprint provisions an AutoScaling fleet of instances. It can be used as a worker tier among other use cases.
- Several AWS::AutoScaling::AutoScalingGroup properties are configurable with Parameters. Additionally, properties that require further customization are configurable with Variables. The blueprint is extremely flexible and configurable for your needs.
- Template makes use of the flexible AWS::AutoScaling::AutoScalingGroup MixedInstancesPolicy. This allows you to use spot, on-demand, or mixed instance types. For example, you can run 70% spot and 30% on-demand instances. Set
OnDemandPercentageAboveBaseCapacity=0
to run all spot instances. - You can launch instances in a Custom VPC and Subnet by configuring
VPCZoneIdentifier
andVpcId
. - You can customize the UserData script and control the bootstrap process with a
@user_data_script
variable.
- Add blueprint to Gemfile
- Configure: configs/asg-worker values
- Deploy
Add the blueprint to your lono project's Gemfile
.
gem "asg-worker", git: "git@github.com:boltopspro/asg-worker.git"
First you want to configure the configs files. Use lono seed to configure starter values quickly.
LONO_ENV=development lono seed asg-worker
To deploy to additional environments:
LONO_ENV=production lono seed asg-worker
The generated files in config/asg-worker
folder look something like this:
configs/asg-worker/
├── params
│ ├── development.txt
│ └── production.txt
└── variables
├── development.rb
└── production.rb
Here's a params example.
configs/asg-worker/params/development.txt:
# Parameter Group: AWS::AutoScaling::AutoScalingGroup
VPCZoneIdentifier=<%= lookup_output("vpc.PrivateAppSubnets") %> # (required)
# MaxSize=8
# MinSize=1
# Parameter Group: AWS::AutoScaling::AutoScalingGroup MixedInstancesPolicy InstancesDistribution
OnDemandPercentageAboveBaseCapacity=0 # 0 means all spot instances, 100 means all on-demand instances. Default is 100
# OnDemandBaseCapacity= # The minimum amount of the Auto Scaling group's capacity that must be fulfilled by On-Demand Instances.
# SpotAllocationStrategy= # lowest-price | capacity-optimized
# SpotInstancePools= # The range is 1 to 20. Higher means more spot pools.
# Parameter Group: AWS::EC2::LaunchTemplate LaunchTemplateData
# InstanceType=t3.micro
# KeyName=
# Parameter Group: AWS::EC2::SecurityGroup
VpcId=<%= lookup_output("vpc.PrivateAppSubnets") %> # Required. Though only used if SecurityGroupIds not set to create Security Group. # (required)
Use the lono cfn deploy command to deploy. Example:
LONO_ENV=development lono cfn deploy asg-worker-development --blueprint asg-worker --sure
LONO_ENV=production lono cfn deploy asg-worker-production --blueprint asg-worker --sure
To customer the UserData launch script to use, use the @user_data_script
variable. Example:
configs/asg-worker/variables/development.rb:
@user_data_script = "configs/asg-worker/user_data/bootstrap.sh"
Here's an example bootstrap.sh
script:
#!/bin/bash
uptime