Skip to content

Commit

Permalink
Merge pull request #2 from clouddrove/internal101
Browse files Browse the repository at this point in the history
Feat: added canary-lambda.js.tpl file
  • Loading branch information
themaniskshah committed Mar 20, 2023
2 parents 59d1f2b + 05a5ccc commit 4e29021
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 29 deletions.
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,17 @@ Here are some examples of how you can use this module in your inventory structur
### Basic Example
```hcl
module "canaries" {
name = "canary"
environment = "test"
source = "../.."
schedule_expression = "rate(5 minutes)"
s3_artifact_bucket = "my-test-artifact-bucket" # must pre-exist
alarm_email = "test.user@clouddrove.com" # you need to confirm this email address
endpoints = { "test-example" = { url = "https://example.com" } }
subnet_ids = module.subnets.private_subnet_id
security_group_ids = [module.ssh.security_group_ids]
source = "clouddrove/cloudwatch-synthetics/aws"
version = "1.3.0"
name = "canary"
environment = "test"
label_order = ["name", "environment"]
schedule_expression = "rate(5 minutes)"
s3_artifact_bucket = "my-test-artifact-bucket" # must pre-exist
alarm_email = "test.user@clouddrove.com" # you need to confirm this email address
endpoints = { "test-example" = { url = "https://example.com" } }
subnet_ids = module.subnets.private_subnet_id
security_group_ids = [module.ssh.security_group_ids]
}
```

Expand Down
24 changes: 13 additions & 11 deletions README.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,17 @@ usage: |-
Here are some examples of how you can use this module in your inventory structure:
### Basic Example
```hcl
module "canaries" {
name = "canary"
environment = "test"
source = "../.."
schedule_expression = "rate(5 minutes)"
s3_artifact_bucket = "my-test-artifact-bucket" # must pre-exist
alarm_email = "test.user@clouddrove.com" # you need to confirm this email address
endpoints = { "test-example" = { url = "https://example.com" } }
subnet_ids = module.subnets.private_subnet_id
security_group_ids = [module.ssh.security_group_ids]
}
module "canaries" {
source = "clouddrove/cloudwatch-synthetics/aws"
version = "1.3.0"
name = "canary"
environment = "test"
label_order = ["name", "environment"]
schedule_expression = "rate(5 minutes)"
s3_artifact_bucket = "my-test-artifact-bucket" # must pre-exist
alarm_email = "test.user@clouddrove.com" # you need to confirm this email address
endpoints = { "test-example" = { url = "https://example.com" } }
subnet_ids = module.subnets.private_subnet_id
security_group_ids = [module.ssh.security_group_ids]
}
```
19 changes: 10 additions & 9 deletions _example/complete/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ provider "aws" {
region = "us-east-1"
}
module "canaries" {
name = "canary"
environment = "test"
source = "../.."
schedule_expression = "rate(5 minutes)"
s3_artifact_bucket = "test-bucket" # must pre-exist
alarm_email = "test.user@clouddrove.com" # you need to confirm this email address
endpoints = { "test-example" = { url = "https://example.com" } }
subnet_ids = module.subnets.private_subnet_id
security_group_ids = [module.ssh.security_group_ids]
source = "../.."
name = "canary"
environment = "test"
label_order = ["name", "environment"]
schedule_expression = "rate(5 minutes)"
s3_artifact_bucket = "test-bucket" # must pre-exist
alarm_email = "test.user@clouddrove.com" # you need to confirm this email address
endpoints = { "test-example" = { url = "https://example.com" } }
# subnet_ids = module.subnets.private_subnet_id
# security_group_ids = [module.ssh.security_group_ids]
}
23 changes: 23 additions & 0 deletions canary-lambda.js.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
var synthetics = require('Synthetics');
const log = require('SyntheticsLogger');

const pageLoadBlueprint = async function () {
const URL = "${endpoint}";
let page = await synthetics.getPage();
const response = await page.goto(URL, {waitUntil: 'domcontentloaded', timeout: 30000});
//Wait for page to render.
//Increase or decrease wait time based on endpoint being monitored.
await page.waitForTimeout(15000);
await synthetics.takeScreenshot('loaded', 'loaded');
let pageTitle = await page.title();
log.info('Page title: ' + pageTitle);
if (response.status() !== 200) {
throw "Failed to load page!";
}
};

exports.handler = async () => {
return await pageLoadBlueprint();
};

0 comments on commit 4e29021

Please sign in to comment.