Automate Start/Stop/Delete/Create AWS synthetic canaries
Tags: python, cloud, aws, beginners
Published: 2021-08-21 07:37:33

This is the second post in the series. This guide will walk you through starting, stopping, deleting, and creating a synthetic canary. Useful if you want to automate the process of producing canaries as part of your devops pipeline or if you don't want to log into the AWS console every time you want to create, start, stop or delete a canary. 

All of this can be achieved with the **_[Python script](https://github.com/hseera/aws-python-utilities/blob/main/synthetic_canary.py)_** I developed using AWS Python SDK and shared on github. The script's current version allows you to do the following:  

* Start & Stop All Canaries
* Start & Stop a Canary
* Delete a Canary
* Script Runtime Versions
* Create a Canary


## Start & Stop All Canaries
To Start & Stop all canaries, run the script with the following command.
```
./synthetic_canary.py stop
./synthetic_canary.py start
```

## Start & Stop A Canary
To Start & Stop a canary, run the script with the following command.
```
./synthetic_canary.py stop/start {canary name}
```
Example
```
./synthetic_canary.py stop workload
./synthetic_canary.py start workload
```

## Delete A Canary
To delete a canary, run the script with the following command.
```
./synthetic_canary.py delete {canary name}
```
Example
```
./synthetic_canary.py delete workload
```

## Script Runtime Versions
Returns a list of Synthetics canary runtime versions and their dependencies. When creating a canary, you must pass in the script runtime version. Make this call first, then extract the appropriate version to use for the create canary script. 
```
./synthetic_canary.py runtime
```

## Create A Canary
To create a canary, run the script with the following command.
```
./synthetic_canary.py create {canary name}
```
Example
```
./synthetic_canary.py create workload
```
A [sample python GET api canary blueprint script](https://github.com/hseera/aws-python-utilities/blob/main/canaryblueprint/python/apiSampleCanaryBlueprint.py) is also included in the github repo to assist you to get started with developing an api synthetic canary. For it to work in your environment, you must change the script with the correct api end point and headers. Make sure you follow the correct folder structure when uploading the zip [nodejs](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Synthetics_Canaries_WritingCanary_Nodejs.html) or [python](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Synthetics_Canaries_WritingCanary_Python.html) canary script to S3.

Hopefully, this script will come in handy to you in the aforementioned case. Keep an eye out for the script updates as I add new features. **_Contact me if you would like to contribute to the code. Also, leave a comment or a star on the git repo if you find the script useful_**.

**Note**: Before using the script in production, try it in your development/test environment first.



------------------------------------------------------------------

Thanks for reading!

If you enjoyed this article feel free to share it on social media 🙂

Say Hello on: [Linkedin](https://www.linkedin.com/in/harinderseera/) | [Twitter](https://twitter.com/harinderseera) | [Polywork](https://www.polywork.com/harinderseera) 

Blogging: [Dev](https://dev.to/harinderseera) | [Hashnode](https://harinderseera.hashnode.dev/)

Github: [hseera](https://github.com/hseera)