Tutorial: WayScript for DevOps Automation
Tags: tutorial, beginners, devops, python
Published: 2020-04-29 15:05:13

---
title: "Tutorial: WayScript for DevOps Automation"
canonical_url: https://wayscript.com/learn/wayscript-devops
---
##WayScript uses WayScript
WayScript uses WayScript to simplify and automate many of our DevOps processes. We make heavy use of our own [Python API](https://github.com/wayscript/wayscript-python) for error tracking and performance monitoring on the live site. We also use our WayScript API for reporting during our AWS deployment process.

In this article, we'll show you some of the ways we use WayScript to make our developers' lives easier and our site more reliable, with the hope that you will be able to use WayScript to improve your own DevOps workflows.

##Deployment Status Notifications
One pain point of our deployment process was that our developers were unaware of when a deployment was taking place or what the status was of an ongoing deployment.

Our team uses Slack, so we decided to solve this problem by using the WayScript API to send deployment updates to a Slack channel.

![Slack](https://cdn.wayscript.com/blog_img/42/deployment_program.png)

##Creating a Deployment Program
To send these Slack notifications throughout our deployment process, we created a "Deployment" program.
This program serves three main functions:
Send a link to the deployment progress page when a deployment begins.
Notify the team that a deployment has completed.
Notify the team that an autoscaling event has occurred.

![Notifications](https://cdn.wayscript.com/blog_img/42/deployment_tracker.png)

While it may look complicated, the program flow is pretty simple.
<ol><li>The program starts out with a Webhook Trigger so that it can be triggered by an API call.</li>
<li>When the message is received, a series of if/else statements determines what type of message to send to Slack, based on the arguments passed to the Webhook Trigger.</li>
<li>The Slack Module sends the message to our developers.</li></ol>

![send message](https://cdn.wayscript.com/blog_img/42/deployment_program_tree.png)

##Calling the WayScript API During the Deployment Process
We use [AWS CodeDeploy](https://aws.amazon.com/codedeploy/) for our deployments. The CodeDeploy configuration allows you to use ["hooks"](https://docs.aws.amazon.com/codedeploy/latest/userguide/reference-appspec-file-structure-hooks.html) to run different shell scripts or lambda functions at different stages of the deployment lifecycle. By calling the WayScript API from these hooks, we can easily track the progress of our deployment.

![Track progress](https://cdn.wayscript.com/blog_img/42/aws_deployment_lifecycle.png)

Here is an example of calling the WayScript API from a shell script. This example will run a "Deployment" program, with the argument "Deployment Started!".

<pre>WS_API_KEY="your_api_key"  # Get this from your Profile page

PROGRAM_ID=1234  # ID of your WayScript "Deployment" program

​
python -c "from wayscript import WayScript; WayScript('$WS_API_KEY').run_program($PROGRAM_ID, 'Deployment Started!')"</pre>


Of course, for this to work, you'll need to have the WayScript Python Library installed on your application instance.

<pre>pip install wayscript</pre>

##Other DevOps Notifications
###Debug Logs###
Often, there are times when the development team wants to know if certain events occurred in the code, but doesn't want to dig through various debug logs to find them. These debug events are another great use case for the WayScript API and Slack Module.

![Slack](https://cdn.wayscript.com/blog_img/42/debug_to_slack_tree.png)

##Warnings and Critical Errors
Most of the time, we're ok with sending debug event notifications to a Slack channel that the development team occasionally monitors, but some errors are critical enough that we want to alert the team with an [email](https://wayscript.com/documentation/module/smtp_email) or [text message](https://wayscript.com/documentation/module/text_message).

To achieve this, we can expand on the debug program above by also passing a "Log Level" argument via our WayScript API call. We can then branch on the value of "Log Level" to:
<ol><li>Write to Slack "If Log Level is the same as Debug"</li>
<li>Send an email "If Log Level is the same as Warning"</li>
<li>Send a text message "If Log Level is the same as Error"</li></ol>

##Performance Monitoring
Similar to the way we use WayScript for debugging and error reporting, we can also use WayScript to alert us on performance regressions.

For example, we could send API performance data to WayScript, store it in an [Excel](https://docs.wayscript.com/library/modules/excel) file, and run analysis on top of that data, such as determining if a value crosses a certain threshold, or [changes by a certain percent](https://wayscript.com/documentation/module/calculator).

##General Site Notifications
We also utilize WayScript API calls to notify us of general site activity, such as a user submitting feedback or a bug report.

##Ensure that Your Site is Always Reachable
You can even use WayScript to detect if your site goes down or becomes unreachable. Create a program that uses the [Python Module](https://docs.wayscript.com/library/modules/python) to ping your site. If the ping fails, send an email. Add a [Time Trigger](https://wayscript.com/documentation/trigger/time_trigger) to your program to run it every ten minutes (or every minute), and voila, you will now get an email from WayScript if your site goes down!

![Trigger](https://cdn.wayscript.com/blog_img/42/ping.png)

##Sky's The Limit
These are just a few of the ways WayScript uses WayScript to simplify our DevOps workflows and ensure our site is performant and reliable. There are endless ways to use the WayScript API to innovative and enhance your DevOps activities.

We'd love to hear how your team uses the WayScript API in your application. As always, feel free to drop us a line at founders@wayscript.com with success stories, feedback, or suggestions for new functionality that would make your DevOps workflows easier.