This solution helps you to schedule Datadog Synthetics (API and Browser tests) for a specific time-slot. This can save you money if you don't need the results 24/7.
❗ This solution will create several resources which will be billed by AWS.
An AWS EventBridge rule starts an AWS Lambda function at the time you specified. This function retrieves the credentials from the AWS Secrets Manager. After having the credentials, it calls the Datadog Rest API to start the configured Synthetic. A second AWS EventBridge rule starts a second AWS Lambda function to do nearly the same. But this time, the Synthetic is paused.
- AWS Secrets Manager
- AWS EventBridge
- AWS Lambda
- AWS X-Ray
- AWS Cloudwatch
Please follow all the steps below to deploy the solution. Please pay attention that the solution only can be deployed in a region where all mentioned services above are available.
- Python 3 (tested with version 3.8.0)
- Node.js (tested with version 12.12.0)
- Serverless (tested with version 1.57.0)
- Clone this repository
- Edit the parameters in the serverless.yml
- syntheticStart: Cron-expression when to start the Synthetic (see documentation)
- syntheticStop: Cron-expression when to stop the Synthetic (see documentation)
- syntheticPublicId: Public ID of the synthetic. You can find the public ID if you switch to the Synthetic in your browser. The url should look like this:
https://app.datadoghq.eu/synthetics/details/123-abc-456a
The Id can be found at the end of the url:123-abc-456
is the public id in this case. - datadogApiEndpoint: Suitable endpoints can be found here. (EU site: https://api.datadoghq.com/api/ // US site: https://api.datadoghq.com/api/)
- Deploy the solution to AWS with
sls deploy --region eu-central-1 --stage dev
. - Switch to the AWS Console and the Service
Secrets Manager
. Edit the value for the secretDatadogSyntheticSchedulerSecret
and enter your Datadog API and APP key.
❗ If you want to use this solution for multiple Synthetic tests in one AWS account, you need to modify the service name in the serverless.yml
(first line).
Just follow the next steps to undeploy the solution:
- Open the AWS Console and clean up the s3 bucket
- run
sls remove
to remove the solution
There are surely ways to improve. Just send a pull request. 😉