Spotinst Integration with OpsWorks -

Spotinst Integration with OpsWorks

Reading Time: 3 minutes

What is AWS OpsWorks?

AWS OpsWorks is a configuration management service that uses Chef, an automation platform that treats server configurations as a code. OpsWorks uses Chef to automate how servers are configured, deployed and managed across your instances.

Spotinst & OpsWorks

Spotinst integration adds a great value by enabling OpsWorks to utilize EC2 Spot Instances as a native part of its Stacks and layers with the latest changes that you made in your code repository, so instead of letting OpsWorks to launch only On-Demand instances, Spotinst Elastigroup will become the infrastructure layer for your OpsWorks and will launch a blend of On Demand / Spot or even Reserved Instances according to your configuration and specifications.

Our prediction algorithm identifies that a Spot should be terminated, and preemptively launches a new Spot Instance. So this enables you to keep your application highly available while unlocking the opportunity of saving 80% of the EC2 costs and still benefit from AWS’ OpsWorks features.

How does it work?

When configuring an Elastigroup to work with AWS OpsWorks you need to enter a pre-built user-data script provided by Spotinst. In that script, you will specify the OpsWorks Stack ID and Layer ID (an example will be followed by the next section).

Using these parameters Spotinst will register any new instance to your existing OpsWorks Stacks and Layers.

Once an Instance termination is predicted, Spotinst Elastigroup identifies this termination cause (whether it is a scale down activity \ Spot instance predicted to be terminated) and notifies OpsWorks API in order to delete this instance from the Stack.

How to get Started?

Step 1: Choose your AWS OpsWorks Stack

To get started, you need a working OpsWorks Stack, Go to AWS OpsWorks console and have your desired stack-id for the next steps.

Step 2: Configure IAM Role for OpsWorks

In order to register your Spot instances into OpsWorks, you need to create an IAM role first and associate it with your Elastigroup.

  1. Sign in to the AWS Management Console and open the IAM console.
  2. In the navigation pane of the console, click Roles and search for aws-opsworks-ec2-role.
  3. Click on the role name, and then in the Permissions tab click on “Attach Policy“.
  4. Search for the policies AWSOpsWorksRegisterCLI and AWSOpsWorksRole.
  5. Click on the policies to select them and then click “Attach Policy“.

Step 3: Create your Elastigroup with IAM Role and a custom startup-script

Once you have configured the IAM role, your Instances can perform operations and attach themselves to any OpsWorks stack. Create an Elastigroup, select the IAM Role from the previous step and set the user data (startup script) with the following command to register your the instance with your desired stack.



Please note: For regional OpsWorks Stacks, the Elastigroup must be in the same region as the Stack. Please do not change the instances hostname, as Elastigroup relies on it for API communication.

Go to Amazon OpsWorks Console, navigate to ‘Advanced options’ and then locate the value of “API endpoint region” (Possible values are CLASSIC or ‘regional’).



Based on your Stack ID, Layer ID and Stack Type (REGIONAL \ CLASSIC), adjust the following user-data script.

Compute Section → Additional Configuration tab:



Note: Before using this user-data shell script, please set the following parameters:




Step 4: Register your Stack and Layer ID

Expand the “Integrations” portion in the Compute tab and enable the OpsWork integration and select the Stack ID and Layer ID for your environment:



Now you can enjoy your OpsWorks while reducing your EC2 costs!