[synthetics] add templates to test property
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 83
Description
Currently the synthetics' `test` property has one static method: `test.custom()`.
The AWS Console experience for creating canaries allows for blueprints, or templates, to be specified to get started quickly. It would be nice is the CDK could do the same.
### Use Case
Adding a "blueprints" feature to the synthetics' `test` property would make the CDK experience richer, and more like the AWS Console. Users can get started with synthetic canaries faster, especially if their needs are not unique.
The workaround currently is to use `test.custom()` to specify the script you want to run. My worry is that without blueprints, users will go to the console to copy/paste the templates that are available there. We might as well save our users the trouble of going to the console at all.
### Proposed Solution
In the console, there are 3 templates:
- monitor url heartbeat
- monitor api endpoint
- broken link checker
Each of these can be modeled as a template in the CDK Synthetics construct.
The API should look something like this:
```ts
const canary1 = new synthetics.Canary(this, 'TemplateCanary', {
test: synthetics.Test.heartbeat("https://www.example.com"),
});
const canary2 = new synthetics.Canary(this, 'TemplateCanary', {
test: synthetics.Test.apiEndpoint("https://www.example.com", apiOptions),
});
const canary3 = new synthetics.Canary(this, 'TemplateCanary', {
test: synthetics.Test.brokenLink("https://www.example.com", linkOptions),
});
```
In terms of implementation, I suggest we build and maintain a folder of templates that are referenced `fromAsset()` by static methods inside `test`. We might have to own these templates and be in charge of updates, if needed. At any rate, this issue is a good place to discuss implementation ideas.
Would look something like this:
```ts
export class Test {
// already implemented
public static custom(options): Test {
}
public static apiEndpoint(url: string, options: apiOptions): Test {
return {
code: Code.fromAsset(path.join(__dirname, 'templates')),
handler: 'api.handler',
}
// more templates
}
```
### Other
* [x] :wave: I may be able to implement this feature request
---
This is a :rocket: Feature Request
Contributor guide
Research direction
Start at the synthetics Test entry point and the existing test.custom() implementation, then inspect how Code.fromAsset() would package the proposed templates folder. Define the three template methods and their option shapes, and consider how template assets are maintained; done means heartbeat, API endpoint, and broken-link canaries are exposed with working packaged templates and coverage for their generated configuration.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, typescript
- Domain
- cloud, observability
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100