synthetics-patterns
TypeScript icon, indicating that this package has built-in type declarations

0.1.5 • Public • Published

CDK sythetics patterns

This is a CDK construct that simplifies the creation of aws Cloudwatch Synthetics tests.

Usage

make sure cdk is installed npm install -g aws-cdk

mkdir my-cool-app && cd my-cool-app
cdk init --language typescript
npm install synthetics-patterns

Navigate to lib/index.ts and add this:

new SyntheticsPatterns(this, 'simpleSynthetic', {
      email: 'my-email@example.com'
    })

This construct depends on a lambda function you need to create. first create the below directories and an index.js file where your lambda handler and code will live.

canary
└── nodejs
    └── node_modules
        └── index.js

This lambda needs to be a special synthetics lambda. You may use and adapt one of the blueprints that AWS provides in the console or use the Cloudwatch Synthetics recorder chrome extension. More information on Cloudwatch Synthetics can be found here.

An example of a simple lambda function:

var synthetics = require('Synthetics');
const log = require('SyntheticsLogger');

const recordedScript = async function () {
  let page = await synthetics.getPage();
  
  const navigationPromise = page.waitForNavigation()
  
  await synthetics.executeStep('Goto_0', async function() {
    await page.goto("http://example.com/", {waitUntil: 'domcontentloaded', timeout: 60000})
  })
  
  await page.setViewport({ width: 1533, height: 801 })
  
  await navigationPromise
  
  await synthetics.executeStep('Click_1', async function() {
    await page.waitForSelector('body > div > p > a')
    await page.click('body > div > p > a')
  })
  
  await navigationPromise
  
};
exports.handler = async () => {
    return await recordedScript();
};

Package Sidebar

Install

npm i synthetics-patterns

Weekly Downloads

5

Version

0.1.5

License

MIT

Unpacked Size

13.5 kB

Total Files

9

Last publish

Collaborators

  • androidwiltron