This project we will connect your Elastigroups to Data Dog to send an event notification when you add, delete or have an unhealthy instance.
To download this project as a template for your own Spotinst Function please use this command
serverless create --template-url https://github.com/spotinst/spotinst-functions-examples/tree/master/node-datadog-event
You will need to have the serverless framework installed, your Spotinst credentials set up and you will need Data Dog account in order to run this project.
First you will want to install the serverless framework onto your local machine using the terminal command
npm install -g serverless
Once this has finished downloading you will have to set up your credentials to link your local machine projects to your Spotinst console. To do this please follow the directions listed here.
You will also need your environment ID for your function. This can be found on the Spotinst console under the Serverless Functions tab. Select the application you wish to deploy this funciton to and locate the environment that you wish to use. Copy the environment ID and save this for later use
Next you will need an API key from Data Dog.
The last thing you will need is your account ID which can be found in the Spotinst console under user setting. Save this for later use.
First you will need to fork this repository and set it up on your local machine. Then you will need to install the serverless-spotinst-functions plugin, the request and the request promise libraries by running this command inside the project repository:
npm install
Once this has been completed you will need to navigate to the serverless.yml file and under environment add in the environment ID in the environment section.
Next you will want to deploy this function using this command:
sls deploy
The first time you run this command your new function will be created and linked to your Spotinst account under the environment that you specified. You can check this on the Spotinst Functions console.
After the project has been deployed you will need to enter you Data Dog API token as an environment variable. To do this go to your function on the Spotinst Console and find the variable key datadogAPI
then enter the value followed by pressing Update Function.
Warning: If you edit your code then re-deploy the function your environment variables will get over written. To stop this from happening delete the list of environment variables from the serverless.yml
file after the first deploy
To set up your Elastigroup to send HTTPS notifications that link to this function you will first need to make sure that you have already deployed this function at least once. This is because you will need the unique URL that is create for each function. Once you have obtained the URL you will need to run the node file PostNotificationSpotinst.js that is provided. In that file you will need to enter your token, group ID, and the URL that was generated from this function. Then you select the event type to be one of the following:
AWS_EC2_INSTANCE_TERMINATE
AWS_EC2_INSTANCE_TERMINATED
AWS_EC2_INSTANCE_LAUNCH
AWS_EC2_INSTANCE_UNHEALTHY_IN_ELB
GROUP_ROLL_FAILED
GROUP_ROLL_FINISHED
CANT_SCALE_UP_GROUP_MAX_CAPACITY
Note: The options you select here will have to match the options that you input for the checkEventType() function in the handler.js