AWS Synthetic Canary with Gitlab CI

Creating Synthetic Canary for E2E testing and deploying with Gitlab CI CD pipeline


#AWS #Synthetic Canary #Gitlab #CICD #Terraform

Synthetic Canary

Description & overview

You can use CloudWatch Synthetics to create a canary for your website or endpoint.

Canaries are configurable scripts that run on a schedule to monitor your endpoints and APIs. You can configure canaries to perform the same actions that your customers perform on your website. This means you can monitor your customer experience and proactively find problems before your customer does.

AWS provides a Runtime Solution based on Selenium (Python) or Puppeteer (JavaScript) using Lambda Layers to run browser tests against an application. It`s technically almost identical to writing an E2E Test for a web-based application.

Canaries have multiple applications. You can check the availability and latency of your endpoints, get load time data, and take screenshots of your user interface. You can also use Canaries to publish metrics for failures and errors, enable continuous monitoring.

Example UseCases for Syntatic Canary:

1. Continuously monitoring for page load, APIs etc.

2. Provide load latency data for the application endpoint

3. Check for broken or dead links

4. E2E and integration in the whole system testing

5. Notifications in case of failures

Useful links:

CloudWatch Synthetics Canaries (docs) Wie überwache ich die Leistung meiner Website mit CloudWatch Synthetics (de)

Architectur Overview

Big Picture

architecture

Architectur Description

Architectur overview & description

Architectur in my case consists 2 parts: monitoring part with canary infrastructure and alerting part to notify reposible persosns in case of failers.

S3 Bucket will be encrypted using AWS KMS key. Canary uses alarm with event bus to trigger notification lamda to send message to MS Teams.

All infrastructur is defined in terraform. All scripts and examples can be found here:

Infrastructure and examples

- In terraform_modul you will find the terraform modul to create whole monitoring infrastructure.

- In lambda_notification you will find the example of the notification service, that is implemented as lambda python script. The script use MS Teams webhook to notify the resposible persones.

- In init_modul are defined terraform scripts for initial infrastructure. The script includes for example: S3 bucket for staging, DynamoDB Table for locking etc. These scripts used only for initial stage and not for deploying of the syntatic canary.

- In example you can find an syntatic canary example that uses named terraform modul. You can find in this directory an example how to use the AWS syntatic canary framework. But it's only an example, for better understending you should read an offitial AWS docs:

How to implement syntatic canaries

- In gitlab are scripts for gitlab CI pipeline.

Structure

Architectur overview & description

How to create a canary for a new test or monitoring case:

1. Create a new folder with name like "Use_Case_0001". The folder should have the same structure as example folder.

Initianl (in folder 'init') terraform scripts should be adjusted (names for S2 bucket and DynamoDB locking table). Than you can create an terraform infrastructure to persist terraform state in S3. To create an infrastructure you have to run scripts with classical TF (terraform) commands: terraform initterraform apply

2. Use only canary.js as a name for canary script or you have adjust terraform scripts in modul folder. How to create a syntatic canary and how you can use AWS framework you can find here: How to implement syntatic canaries

3. Create webhook for MS Teams. How to create a web hook in MS Teams you can find here: How to create incoming webhook

4. Upload the created webhook to AWS Secret Manager under key 'teams_webhook_url'. You can use another key too, but in this case you have to adjust lambda notification script to use a new key. How to use AWS Secret Manager

5. In the example the request body for REST call is persisted the separate S3 bicket. In this case you have to crete S3 bucker to persist your requests for test case.

6. Adjust S3 bucket names in the 'main.tf' deployment script. You should change another configs in deploymnt script additionaly too, for example: ARN of the secret manager etc.

7. Add ne use case to gitlab CI CD pipeline. The example of the pipeline can be found in the expmple project. How to write the basic CI CD pipeline you can find here: Gitlab CI CD

8. After each deployment canary scripts should be started via web console or AWS CLI.

KONTAKT

Standort

Hamburg, DE

Web

trunov.de