fbpx

Integrate Elastigroup with Your OpsWorks Stack in 3 Easy Steps

Introduction

AWS OpsWorks is a configuration management service that uses Chef, an automation platform that treats server configurations as code. OpsWorks uses Chef to automate how servers are configured, deployed and managed across your instances. You can easily associate your Elastigroup instances with your OpsWorks stack and layers with this simple three steps guide.

Prerequisites:

  • Make sure you are using the latest Spotinst Policy
  • Make sure you have an OpsWorks environment
  • Make sure you cancel the auto-healing feature in OpsWorks (for more information click here).

Step 1: Choose your AWS OpsWorks Stack

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

Step 2: Configure IAM Rule 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 AWSOpsWorksCMServiceRoleAWSOpsWorksInstanceRegistration and AWSOpsWorksRegisterCLI.
  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.

  1. Launch the Elastigroup Creation Wizard: Creating your first Elastigroup
  2. In the Compute tab under Advanced Configurations, select the IAM Role from the previous step.
  3. Under Integrations in the Compute tab, select the OpsWork integration, add it and set the Stack Type, Stack ID and Layer ID for your environment.

 

Once configured Elastigroup will retrieve the user data. Use the Copy feature to copy the user data from there:

 

     4. Paste the user data script in the User Data section under Additional Configuration. See the example template below:  

#!/bin/bash

curl -fsSL https://s3.amazonaws.com/spotinst-public/integrations/opsworks/spotinst_aws_opsworks_v5.sh | \
OPSWORKS_STACK_TYPE="myStackType" \
OPSWORKS_STACK_ID="myStackID" \
OPSWORKS_LAYER_ID="myLayerID" \
bash

 

Argument Reference

Set the following parameters in the user data script:
OPSWORKS_STACK_ID – The OpsWorks provided Stack ID – ”myStackID”
OPSWORKS_LAYER_ID – The OpsWorks provided Layer ID – ”myLayerID”
OPSWORKS_STACK_TYPE- The OpsWorks stack type. This information can be found via ‘API endpoint region’ parameter under ‘advanced options’ in OpsWorks. The possible values are  ‘REGIONAL’ or ‘CLASSIC’.

 

Please note: 

  • For regional opsworks stacks, the Elastigroup must be in the same region as the stack.
  • Do not change the instances hostname, as it is used to identify the instance in OpsWorks.
  • Please verify you cancel the auto-healing feature of OpsWorks. failiure to do so will cause the creation of new instnaces by OpsWorks once an Elastigroup terminates an instance (For scale down for example)
  • The AMI used in the Elastigroup should have Python installed (part of OpsWorks requirements)