---
# System prepended metadata

title: Query 288

---

AWS CloudWatch Synthetics supports custom scripting languages, including JavaScript, Python, and PowerShell, for creating Canary tests. However, CloudWatch Synthetics primarily uses Node.js (JavaScript) as the default runtime for creating Canary tests. To use Python or PowerShell, you'll need to call external scripts written in those languages from within the Node.js runtime. Below is a simplified example in C++ that demonstrates how to create a Canary test using CloudWatch Synthetics with Node.js and call external Python and PowerShell scripts:
```
#include <iostream>
#include <cstdlib>

int main() {
    // This C++ program demonstrates how to create a CloudWatch Synthetics Canary test
    // using Node.js as the runtime and call external Python and PowerShell scripts.

    // Define the Node.js script for the Canary test
    std::string nodeScript = R"(
const synthetics = require('Synthetics');
const log = require('SyntheticsLogger');

const canary = synthetics.createCanary('MyCustomCanary', {
    runtime: 'syn-python3.7',
    handler: 'index.handler',
    executionRole: 'arn:aws:iam::123456789012:role/MyCanaryRole'
});

canary.run(async () => {
    // Execute the Python script
    const { spawnSync } = require('child_process');
    const pythonScript = 'python_script.py';
    const pythonProcess = spawnSync('python', [pythonScript]);
    log.debug(`Python Script Output: ${pythonProcess.stdout.toString()}`);
    
    // Execute the PowerShell script
    const powershellScript = 'powershell_script.ps1';
    const powershellProcess = spawnSync('powershell.exe', [powershellScript]);
    log.debug(`PowerShell Script Output: ${powershellProcess.stdout.toString()}`);
});
    )";

    // Write the Node.js script to a file (e.g., canary_script.js)
    std::ofstream file("canary_script.js");
    file << nodeScript;
    file.close();

    // Call CloudWatch Synthetics Canary createCanary API to create the Canary test
    // ...

    // Cleanup: Remove the Node.js script file
    std::remove("canary_script.js");

    std::cout << "CloudWatch Synthetics Canary test created with custom scripts." << std::endl;
    return 0;
}
```
In this example:
* We define a C++ program that showcases how to create a CloudWatch Synthetics Canary test with Node.js as the runtime.
* Inside the Node.js script, we use the child_process module to execute external Python and PowerShell scripts.
* We write the Node.js script to a file (e.g., canary_script.js) to be used for the Canary test.
* The program calls the CloudWatch Synthetics Canary createCanary API to create the Canary test. The actual API call is not shown in this simplified example.
* After creating the Canary test, we remove the Node.js script file as it's no longer needed.

Please note that this is a simplified example, and in a real scenario, you would need to configure the Canary test, IAM roles, CloudWatch alarms, and CloudWatch Logs for monitoring and alerting. The actual API calls and Canary test configuration are not included in this code snippet.