# Pulumi Examples - Checkly Docs

> Comprehensive examples for different check types and configurations using the Checkly Pulumi provider

Source: https://www.checklyhq.com/docs/integrations/iac/pulumi/examples/

---

Back to top
- Basic API Checks Simple GET Request
- POST Request with JSON Body

- Browser Checks Basic Page Load Check
- Login Flow Check

- Check Groups Organizing Related Checks

- Alert Channels Email Alert Channel
- Slack Alert Channel

- Advanced Configurations Environment-Specific Configurations

- Best Practices

Pulumi

# Pulumi Examples

Comprehensive examples for different check types and configurations using the Checkly Pulumi provider

This page provides comprehensive examples of how to use the Checkly Pulumi provider to create various types of monitoring checks and configurations.

## ​ Basic API Checks

### ​ Simple GET Request

- JavaScript
- TypeScript

```
const checkly = require('@checkly/pulumi')

new checkly.Check('simple-get-api', {
name: 'Simple GET API Check',
activated: true,
frequency: 10,
type: 'API',
locations: ['eu-west-1', 'us-west-2'],
tags: ['api', 'simple'],
request: {
method: 'GET',
url: 'https://api.example.com/health',
assertions: [
{
source: 'STATUS_CODE',
comparison: 'EQUALS',
target: '200',
},
],
},
useGlobalAlertSettings: true,
})
```

```
import * as checkly from '@checkly/pulumi'

new checkly.Check('simple-get-api', {
name: 'Simple GET API Check',
activated: true,
frequency: 10,
type: 'API',
locations: ['eu-west-1', 'us-west-2'],
tags: ['api', 'simple'],
request: {
method: 'GET',
url: 'https://api.example.com/health',
assertions: [
{
source: 'STATUS_CODE',
comparison: 'EQUALS',
target: '200',
},
],
},
useGlobalAlertSettings: true,
})
```

### ​ POST Request with JSON Body

- JavaScript
- TypeScript

```
const checkly = require('@checkly/pulumi')

new checkly.Check('post-api-check', {
name: 'POST API with JSON Body',
activated: true,
frequency: 10,
type: 'API',
locations: ['eu-west-1'],
tags: ['api', 'post'],
request: {
method: 'POST',
url: 'https://api.example.com/users',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${process.env.API_TOKEN}`,
},
body: JSON.stringify({
name: 'John Doe',
email: 'john@example.com',
}),
assertions: [
{
source: 'STATUS_CODE',
comparison: 'EQUALS',
target: '201',
},
{
source: 'JSON_BODY',
property: '$.id',
comparison: 'NOT_EMPTY',
},
],
},
useGlobalAlertSettings: true,
})
```

```
import * as checkly from '@checkly/pulumi'

new checkly.Check('post-api-check', {
name: 'POST API with JSON Body',
activated: true,
frequency: 10,
type: 'API',
locations: ['eu-west-1'],
tags: ['api', 'post'],
request: {
method: 'POST',
url: 'https://api.example.com/users',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${process.env.API_TOKEN}`,
},
body: JSON.stringify({
name: 'John Doe',
email: 'john@example.com',
}),
assertions: [
{
source: 'STATUS_CODE',
comparison: 'EQUALS',
target: '201',
},
{
source: 'JSON_BODY',
property: '$.id',
comparison: 'NOT_EMPTY',
},
],
},
useGlobalAlertSettings: true,
})
```

## ​ Browser Checks

### ​ Basic Page Load Check

- JavaScript
- TypeScript

```
const checkly = require('@checkly/pulumi')

new checkly.Check('basic-browser-check', {
name: 'Basic Page Load Check',
activated: true,
frequency: 10,
type: 'BROWSER',
locations: ['eu-west-1'],
tags: ['browser', 'basic'],
script: `
const { expect, test } = require('@playwright/test')

test('basic page load', async ({ page }) => {
const response = await page.goto('https://example.com')
expect(response.status()).toBeLessThan(400)

// Check page title
await expect(page).toHaveTitle(/Example Domain/)

// Take screenshot
await page.screenshot({ path: 'screenshot.jpg' })
})`,
useGlobalAlertSettings: true,
})
```

```
import * as checkly from '@checkly/pulumi'

new checkly.Check('basic-browser-check', {
name: 'Basic Page Load Check',
activated: true,
frequency: 10,
type: 'BROWSER',
locations: ['eu-west-1'],
tags: ['browser', 'basic'],
script: `
const { expect, test } = require('@playwright/test')

test('basic page load', async ({ page }) => {
const response = await page.goto('https://example.com')
expect(response.status()).toBeLessThan(400)

// Check page title
await expect(page).toHaveTitle(/Example Domain/)

// Take screenshot
await page.screenshot({ path: 'screenshot.jpg' })
})`,
useGlobalAlertSettings: true,
})
```

### ​ Login Flow Check

- JavaScript
- TypeScript

```
const checkly = require('@checkly/pulumi')

new checkly.Check('login-flow-check', {
name: 'Login Flow Check',
activated: true,
frequency: 10,
type: 'BROWSER',
locations: ['eu-west-1'],
tags: ['browser', 'login'],
script: `
const { expect, test } = require('@playwright/test')

test('login flow', async ({ page }) => {
// Navigate to login page
await page.goto('https://app.example.com/login')

// Fill login form
await page.fill('#email', process.env.TEST_USER_EMAIL)
await page.fill('#password', process.env.TEST_USER_PASSWORD)

// Submit form
await page.click('#login-button')

// Wait for redirect and verify login
await page.waitForURL('**/dashboard')
await expect(page.locator('.user-profile')).toBeVisible()

// Verify user is logged in
const userText = await page.locator('.user-name').textContent()
expect(userText).toContain('Test User')
})`,
useGlobalAlertSettings: true,
})
```

```
import * as checkly from '@checkly/pulumi'

new checkly.Check('login-flow-check', {
name: 'Login Flow Check',
activated: true,
frequency: 10,
type: 'BROWSER',
locations: ['eu-west-1'],
tags: ['browser', 'login'],
script: `
const { expect, test } = require('@playwright/test')

test('login flow', async ({ page }) => {
// Navigate to login page
await page.goto('https://app.example.com/login')

// Fill login form
await page.fill('#email', process.env.TEST_USER_EMAIL)
await page.fill('#password', process.env.TEST_USER_PASSWORD)

// Submit form
await page.click('#login-button')

// Wait for redirect and verify login
await page.waitForURL('**/dashboard')
await expect(page.locator('.user-profile')).toBeVisible()

// Verify user is logged in
const userText = await page.locator('.user-name').textContent()
expect(userText).toContain('Test User')
})`,
useGlobalAlertSettings: true,
})
```

## ​ Check Groups

### ​ Organizing Related Checks

- JavaScript
- TypeScript

```
const checkly = require('@checkly/pulumi')

// Create a check group
const apiGroup = new checkly.CheckGroup('api-monitoring-group', {
name: 'API Monitoring Group',
activated: true,
locations: ['eu-west-1', 'us-west-2'],
tags: ['api', 'group'],
concurrency: 2,
useGlobalAlertSettings: true,
})

// Add checks to the group
new checkly.Check('health-check', {
name: 'Health Check',
activated: true,
frequency: 10,
type: 'API',
groupId: apiGroup.id,
request: {
method: 'GET',
url: 'https://api.example.com/health',
assertions: [
{
source: 'STATUS_CODE',
comparison: 'EQUALS',
target: '200',
},
],
},
useGlobalAlertSettings: true,
})

new checkly.Check('metrics-check', {
name: 'Metrics Check',
activated: true,
frequency: 10,
type: 'API',
groupId: apiGroup.id,
request: {
method: 'GET',
url: 'https://api.example.com/metrics',
assertions: [
{
source: 'STATUS_CODE',
comparison: 'EQUALS',
target: '200',
},
],
},
useGlobalAlertSettings: true,
})
```

```
import * as checkly from '@checkly/pulumi'

// Create a check group
const apiGroup = new checkly.CheckGroup('api-monitoring-group', {
name: 'API Monitoring Group',
activated: true,
locations: ['eu-west-1', 'us-west-2'],
tags: ['api', 'group'],
concurrency: 2,
useGlobalAlertSettings: true,
})

// Add checks to the group
new checkly.Check('health-check', {
name: 'Health Check',
activated: true,
frequency: 10,
type: 'API',
groupId: apiGroup.id.apply(id => parseInt(id)),
request: {
method: 'GET',
url: 'https://api.example.com/health',
assertions: [
{
source: 'STATUS_CODE',
comparison: 'EQUALS',
target: '200',
},
],
},
useGlobalAlertSettings: true,
})

new checkly.Check('metrics-check', {
name: 'Metrics Check',
activated: true,
frequency: 10,
type: 'API',
groupId: apiGroup.id.apply(id => parseInt(id)),
request: {
method: 'GET',
url: 'https://api.example.com/metrics',
assertions: [
{
source: 'STATUS_CODE',
comparison: 'EQUALS',
target: '200',
},
],
},
useGlobalAlertSettings: true,
})
```

## ​ Alert Channels

### ​ Email Alert Channel

- JavaScript
- TypeScript

```
const checkly = require('@checkly/pulumi')

const emailAlertChannel = new checkly.AlertChannel('email-alerts', {
email: {
address: 'alerts@example.com',
},
sendRecovery: true,
sendFailure: true,
sendDegraded: false,
})

// Use the alert channel in a check
new checkly.Check('monitored-api', {
name: 'Monitored API',
activated: true,
frequency: 10,
type: 'API',
locations: ['eu-west-1'],
alertChannelSubscriptions: [{
channelId: emailAlertChannel.id.apply(id => parseInt(id)),
activated: true,
}],
request: {
method: 'GET',
url: 'https://api.example.com/health',
assertions: [
{
source: 'STATUS_CODE',
comparison: 'EQUALS',
target: '200',
},
],
},
useGlobalAlertSettings: false,
})
```

```
import * as checkly from '@checkly/pulumi'

const emailAlertChannel = new checkly.AlertChannel('email-alerts', {
email: {
address: 'alerts@example.com',
},
sendRecovery: true,
sendFailure: true,
sendDegraded: false,
})

// Use the alert channel in a check
new checkly.Check('monitored-api', {
name: 'Monitored API',
activated: true,
frequency: 10,
type: 'API',
locations: ['eu-west-1'],
alertChannelSubscriptions: [{
channelId: emailAlertChannel.id.apply(id => parseInt(id)),
activated: true,
}],
request: {
method: 'GET',
url: 'https://api.example.com/health',
assertions: [
{
source: 'STATUS_CODE',
comparison: 'EQUALS',
target: '200',
},
],
},
useGlobalAlertSettings: false,
})
```

### ​ Slack Alert Channel

- JavaScript
- TypeScript

```
const checkly = require('@checkly/pulumi')

const slackAlertChannel = new checkly.AlertChannel('slack-alerts', {
slack: {
channel: '#monitoring',
url: process.env.SLACK_WEBHOOK_URL,
},
sendRecovery: true,
sendFailure: true,
sendDegraded: true,
})

// Use the alert channel in a check
new checkly.Check('critical-api', {
name: 'Critical API',
activated: true,
frequency: 10,
type: 'API',
locations: ['eu-west-1', 'us-west-2'],
alertChannelSubscriptions: [{
channelId: slackAlertChannel.id.apply(id => parseInt(id)),
activated: true,
}],
request: {
method: 'GET',
url: 'https://api.example.com/critical',
assertions: [
{
source: 'STATUS_CODE',
comparison: 'EQUALS',
target: '200',
},
],
},
useGlobalAlertSettings: false,
})
```

```
import * as checkly from '@checkly/pulumi'

const slackAlertChannel = new checkly.AlertChannel('slack-alerts', {
slack: {
channel: '#monitoring',
url: process.env.SLACK_WEBHOOK_URL,
},
sendRecovery: true,
sendFailure: true,
sendDegraded: true,
})

// Use the alert channel in a check
new checkly.Check('critical-api', {
name: 'Critical API',
activated: true,
frequency: 10,
type: 'API',
locations: ['eu-west-1', 'us-west-2'],
alertChannelSubscriptions: [{
channelId: slackAlertChannel.id.apply(id => parseInt(id)),
activated: true,
}],
request: {
method: 'GET',
url: 'https://api.example.com/critical',
assertions: [
{
source: 'STATUS_CODE',
comparison: 'EQUALS',
target: '200',
},
],
},
useGlobalAlertSettings: false,
})
```

## ​ Advanced Configurations

### ​ Environment-Specific Configurations

- JavaScript
- TypeScript

```
const checkly = require('@checkly/pulumi')
const pulumi = require('@pulumi/pulumi')

const config = new pulumi.Config()
const environment = config.require('environment')

// Environment-specific configurations
const envConfigs = {
dev: {
frequency: 30,
locations: ['eu-west-1'],
tags: ['dev'],
},
staging: {
frequency: 15,
locations: ['eu-west-1', 'us-west-2'],
tags: ['staging'],
},
prod: {
frequency: 5,
locations: ['eu-west-1', 'us-west-2', 'ap-southeast-1'],
tags: ['prod'],
},
}

const currentConfig = envConfigs[environment]

new checkly.Check('environment-aware-check', {
name: `API Check - ${environment}`,
activated: true,
frequency: currentConfig.frequency,
type: 'API',
locations: currentConfig.locations,
tags: currentConfig.tags,
request: {
method: 'GET',
url: `https://${environment}-api.example.com/health`,
assertions: [
{
source: 'STATUS_CODE',
comparison: 'EQUALS',
target: '200',
},
],
},
useGlobalAlertSettings: true,
})
```

```
import * as checkly from '@checkly/pulumi'
import * as pulumi from '@pulumi/pulumi'

const config = new pulumi.Config()
const environment = config.require('environment')

// Environment-specific configurations
const envConfigs: Record = {
dev: {
frequency: 30,
locations: ['eu-west-1'],
tags: ['dev'],
},
staging: {
frequency: 15,
locations: ['eu-west-1', 'us-west-2'],
tags: ['staging'],
},
prod: {
frequency: 5,
locations: ['eu-west-1', 'us-west-2', 'ap-southeast-1'],
tags: ['prod'],
},
}

const currentConfig = envConfigs[environment]

new checkly.Check('environment-aware-check', {
name: `API Check - ${environment}`,
activated: true,
frequency: currentConfig.frequency,
type: 'API',
locations: currentConfig.locations,
tags: currentConfig.tags,
request: {
method: 'GET',
url: `https://${environment}-api.example.com/health`,
assertions: [
{
source: 'STATUS_CODE',
comparison: 'EQUALS',
target: '200',
},
],
},
useGlobalAlertSettings: true,
})
```

## ​ Best Practices

## Naming Conventions

**Consistent Naming**

- Use descriptive names for resources

- Include environment prefixes

- Follow team naming conventions

- Use consistent tagging strategies

## Resource Organization

**Logical Grouping**

- Group related checks together

- Use check groups for organization

- Separate environments with stacks

- Maintain clear resource hierarchy

## Security

**Secure Configuration**

- Use environment variables for secrets

- Never commit API keys to version control

- Use Pulumi’s secret management

- Implement least-privilege access

## Monitoring Strategy

**Effective Monitoring**

- Define clear success criteria

- Use appropriate check frequencies

- Implement proper alerting

- Monitor from multiple locations

When creating multiple similar checks, consider using loops or functions to reduce code duplication and maintain consistency.

Always test your Pulumi configurations in a development environment before deploying to production. Use `pulumi preview` to review changes before applying them.

Was this page helpful?

[Suggest edits](https://github.com/checkly/docs/edit/main/integrations/iac/pulumi/examples.mdx)[Raise issue](https://github.com/checkly/docs/issues/new?title=Issue%20on%20docs&body=Path:%20/integrations/iac/pulumi/examples)

[Pulumi Setup Guide Previous](https://www.checklyhq.com/docs/integrations/iac/pulumi/setup)[CI/CD Integration Next](https://www.checklyhq.com/docs/integrations/iac/pulumi/ci-cd)

[x](https://x.com/checklyhq)[github](https://github.com/checkly)[linkedin](https://linkedin.com/company/checkly)

[Powered by This documentation is built and hosted on Mintlify, a developer documentation platform](https://www.mintlify.com/?utm_campaign=poweredBy&utm_medium=referral&utm_source=checkly-422f444a)
