Giter VIP home page Giter VIP logo

cloudwatch-synthetics-boilerplate's Introduction

Cloudwatch Synthetics Boilerplate

This is a boilerplate project to help teams get started using AWS CloudWatch canary test scripts. They are used for continuous monitoring of UX flows in production.

Motivation

Synthetic checks are continuously run tests that validate critical flows that a user would take on your app. These critical user flows could be things like logging in, navigating or watching a video.

There are many products on the market that provide synthetic checks as a service. We created this project because it allowed us to achieve functionality that other products on the market did not have:

  • We wanted to write synthetic checks in code and version control them
  • We wanted to develop, run and validate synthetic checks locally before deploying them
  • The costs for running synthetic checks with other products was high. We found that AWS Cloudwatch synthetics were approximately 10 times cheaper than other products (each test is $0.0012 per canary run).

Setup

Start by creating a fork of this repository.

Navigate to the root of the forked repository and install dependencies with:

npm install

Running synthetic checks locally

We have mocked the AWS Synthetics environment(syn-1.0) locally, which allows us to write and execute synthetic checks before deploying them.

To run a test locally:

node -e 'require(".tests/example-test").handler()'

One option is to map the scripts for running tests to npm scripts in the packages.json.

// package.json
...
"scripts": {
  "test:example-test": "node -e 'require(\"./tests/example-test\").handler()'",
  "test:another-test": "node -e 'require(\"./tests/another-test\").handler()'"
},
...

Then you can run tests with simpler command:

npm run test:example-test

To setup a new test:

  1. Create the test file in ./tests. For demo purposes this file will be called another-test.js
  2. Add required boilerplate to the test file
const synthetics = require('Synthetics');
const log = require('SyntheticsLogger');

const testFunction = async function () {
  // your synthetic check test code here
};

exports.handler = async () => {
    return await testFunction();
};
  1. Add your test script to package.json
"scripts": {
  "test:test-example": "node -e 'require(\"./tests/another-test\").handler()'"
},

Deployment

We have included some basic Cloudformation templates for automatically provisioning the required AWS services as part of this project.

You will need to add a AWS::Synthetics::Canary entity in cfn/synthetic_checks_template.yaml for each synthetic check you want to deploy.

It is up to you to decide how to deploy the artifact and Cloudformation templates. For this example we will deploy our synthetic checks using the AWS CLI.

Please note this is an example deployment and is probably not what you should be doing for production.

  1. Deploy the cfn/synthetic_checks_buckets_template.yaml to AWS (you only have to do this when first setting up the project in AWS)
aws cloudformation deploy --template ./cfn/synthetic_checks_buckets_template.yaml --stack-name synthetic-checks-buckets
  1. Compile the deploy artifact
npm run build
  1. Deploy the artifact to s3
aws s3 cp artifact.zip s3://synthetics-tests/artifact.zip
  1. Deploy the cfn/synthetics_checks_template.yaml to AWS.
aws cloudformation deploy --template ./cfn/synthetic_checks_template.yaml --stack-name synthetic-checks --capabilities CAPABILITY_NAMED_IAM

cloudwatch-synthetics-boilerplate's People

Contributors

dependabot[bot] avatar simonschwartz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

kkashyap1707

cloudwatch-synthetics-boilerplate's Issues

Can't run the tests

Hello,

I'm new to Node JS, when I run npm test:example-test or node -e 'require(\"./tests/example-test\").handler()' nothing happens.

node -v
v12.16.1

npm -v
6.13.4

I created a simple server.js and I can run it with node.

How do I run the tests please?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.