fbpx

Elastigroup & CloudFormation

Creating Elastigroups directly from your AWS CloudFormation Templates

Aharon Twizer
Spotinst, Co-Founder and CTO

AWS CloudFormation gives developers and systems administrators an easy way to create and manage a collection of related AWS resources, provisioning and updating them in an orderly and predictable fashion.

CloudFormation

Infrastructure as a code

As developers and DevOps engineers want to manage their infrastructure as a code using tools like AWS CloudFormation and HashiCorp Terraform, Spotinst is happy to release an easy integration for CloudFormation that ease the process of using Elastigroup custom resource, as part of a CloudFormation stack.

Elastigroup is the equivalent product to Amazon AutoScaling Groups, and therefore it is recommend to replace your AWS::AutoScaling::AutoScalingGroupAWS::AutoScaling::LaunchConfiguration and AWS::AutoScaling::ScalingPolicy with a new resource called "Custom::elasticgroup"

High Level Overview

Spotinst_CloudFormation

Step by Step

1. Generate A Personal Access token from Spotinst

Generating a Personal access token from your Spotinst account. Go to Settings -> Personal Access Tokens -> Generate

Once you have the Personal Access Token, save it – we should use it later on in the CloudFormation template.

2. Create an Elastigroup

Create Spotinst Elasticgroup custom resource with the Personal Access Token and Spotinst’s Lambda ARN.

Spotinst Lambda Function

The Lambda ARN is region dependent, please set the correct region:

arn:aws:lambda:<REGION>:178579023202:function:spotinst-cloudformation

example for us-east-1:

arn:aws:lambda:us-east-1:178579023202:function:spotinst-cloudformation

In the following example of the CloudFormation template, we create a custom resource "Type": "Custom::elasticgroup"

This resource contains the following elements that need be covered:

  1. accessToken – Spotinst Access Token that was generated in step #1.
  2. ServiceToken – Spotinst’s Lambda function ARN.
  3. group – Spotinst Elastigroup configuration.
Here is the CloudFormation Template example – adjust it with your own accessToken and group.
{
  "AWSTemplateFormatVersion": "2010-09-09",
  "Resources": {
    "CFCR195GN": {
      "Type": "Custom::elasticgroup",
      "Properties": {
        "ServiceToken": "arn:aws:lambda:us-east-1:178579023202:function:spotinst-cloudformation",                      
        "accessToken": "4378fdd1bb97e9dba31b0b19bd1234123465vr65c6dctdx4e55e35d129837198273981723",  // Your Personal AccessToken
        "group": {
          "name": "Spotinst-CloudFormation",
          "strategy": {
            "risk": 100,
            "availabilityVsCost": "balanced"
          },
          "capacity": {
            "target": 1,
            "minimum": 1,
            "maximum": 1
          },
          "scaling": {},
          "compute": {
            "instanceTypes": {
              "ondemand": "m3.large",
              "spot": [
                "m3.large",
                "m4.large",
                "c3.large",
                "c4.large"
                ]
            },
            "availabilityZones": [
              {
                "name": "us-west-2c",
                "subnetId": "subnet-fa8861a3"
              },
              {
                "name": "us-west-2b",
                "subnetId": "subnet-cw219d2"
              }
            ],
            "launchSpecification": {
              "monitoring": false,
              "imageId": "ami-63b25203",
              "keyPair": "my-keypair",
              "securityGroupIds": [
                "sg-dd68abba"
                ]
            },
            "product": "Linux/UNIX"
          },
          "scheduling": {},
          "thirdPartiesIntegration": {}
        }
      }
    }
  }
}
Best Regards,
The Spotinst Team.
Aharon Twizer
Spotinst, Co-Founder and CTO

Stay current

Sign up for our newsletter, and we'll send you the latest updates on Spotinst, tips, tutorials and more cool stuff!