Skip to content

Commit 45c191e

Browse files
authored
feat(synthetics): Adding DeleteLambdaResourcesOnCanaryDeletion prop to the canary L2 (#23820)
This PR is to add the DeleteLambdaResourcesOnCanaryDeletion prop to the canary L2.
1 parent 0b25265 commit 45c191e

20 files changed

+317
-113
lines changed

Diff for: packages/@aws-cdk/aws-synthetics/README.md

+23
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,29 @@ const schedule = synthetics.Schedule.cron({
110110

111111
If you want the canary to run just once upon deployment, you can use `Schedule.once()`.
112112

113+
114+
### Canary DeleteLambdaResourcesOnCanaryDeletion
115+
116+
You can specify whether the AWS CloudFormation is to also delete the Lambda functions and layers used by this canary, when the canary is deleted.
117+
118+
This can be provisioned by setting the `DeleteLambdaResourcesOnCanaryDeletion` property to `true` when we define the canary.
119+
120+
```ts
121+
const stack = new Stack();
122+
123+
const canary = new synthetics.Canary(stack, 'Canary', {
124+
test: synthetics.Test.custom({
125+
handler: 'index.handler',
126+
code: synthetics.Code.fromInline('/* Synthetics handler code'),
127+
}),
128+
enableAutoDeleteLambdas: true,
129+
runtime: synthetics.Runtime.SYNTHETICS_NODEJS_PUPPETEER_3_8,
130+
});
131+
```
132+
133+
Even when set to `true` there are resources such as S3 buckets/logs that do NOT get deleted and are to be deleted manually.
134+
135+
113136
### Configuring the Canary Script
114137

115138
To configure the script the canary executes, use the `test` property. The `test` property accepts a `Test` instance that can be initialized by the `Test` class static methods. Currently, the only implemented method is `Test.custom()`, which allows you to bring your own code. In the future, other methods will be added. `Test.custom()` accepts `code` and `handler` properties -- both are required by Synthetics to create a lambda function on your behalf.

Diff for: packages/@aws-cdk/aws-synthetics/lib/canary.ts

+10
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,15 @@ export interface CanaryProps {
204204
* not specified a dedicated security group will be created for this canary.
205205
*/
206206
readonly securityGroups?: ec2.ISecurityGroup[];
207+
208+
/**
209+
* Whether or not to delete the lambda resources when the canary is deleted
210+
*
211+
* @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-synthetics-canary.html#cfn-synthetics-canary-deletelambdaresourcesoncanarydeletion
212+
*
213+
* @default false
214+
*/
215+
readonly enableAutoDeleteLambdas?: boolean;
207216
}
208217

209218
/**
@@ -281,6 +290,7 @@ export class Canary extends cdk.Resource implements ec2.IConnectable {
281290
code: this.createCode(props),
282291
runConfig: this.createRunConfig(props),
283292
vpcConfig: this.createVpcConfig(props),
293+
deleteLambdaResourcesOnCanaryDeletion: props.enableAutoDeleteLambdas,
284294
});
285295

286296
this.canaryId = resource.attrId;

Diff for: packages/@aws-cdk/aws-synthetics/lib/runtime.ts

+53-1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ export class Runtime {
7575
public static readonly SYNTHETICS_NODEJS_2_2 = new Runtime('syn-nodejs-2.2', RuntimeFamily.NODEJS);
7676

7777
/**
78+
* **Deprecated by AWS Synthetics. You can't create canaries with deprecated runtimes.**
79+
*
7880
* `syn-nodejs-puppeteer-3.0` includes the following:
7981
* - Lambda runtime Node.js 12.x
8082
* - Puppeteer-core version 5.5.0
@@ -85,6 +87,8 @@ export class Runtime {
8587
public static readonly SYNTHETICS_NODEJS_PUPPETEER_3_0 = new Runtime('syn-nodejs-puppeteer-3.0', RuntimeFamily.NODEJS);
8688

8789
/**
90+
* **Deprecated by AWS Synthetics. You can't create canaries with deprecated runtimes.**
91+
*
8892
* `syn-nodejs-puppeteer-3.1` includes the following:
8993
* - Lambda runtime Node.js 12.x
9094
* - Puppeteer-core version 5.5.0
@@ -95,6 +99,8 @@ export class Runtime {
9599
public static readonly SYNTHETICS_NODEJS_PUPPETEER_3_1 = new Runtime('syn-nodejs-puppeteer-3.1', RuntimeFamily.NODEJS);
96100

97101
/**
102+
* **Deprecated by AWS Synthetics. You can't create canaries with deprecated runtimes.**
103+
*
98104
* `syn-nodejs-puppeteer-3.2` includes the following:
99105
* - Lambda runtime Node.js 12.x
100106
* - Puppeteer-core version 5.5.0
@@ -106,6 +112,8 @@ export class Runtime {
106112

107113
/**
108114
* `syn-nodejs-puppeteer-3.3` includes the following:
115+
* **Deprecated by AWS Synthetics. You can't create canaries with deprecated runtimes.**
116+
*
109117
* - Lambda runtime Node.js 12.x
110118
* - Puppeteer-core version 5.5.0
111119
* - Chromium version 88.0.4298.0
@@ -115,6 +123,8 @@ export class Runtime {
115123
public static readonly SYNTHETICS_NODEJS_PUPPETEER_3_3 = new Runtime('syn-nodejs-puppeteer-3.3', RuntimeFamily.NODEJS);
116124

117125
/**
126+
* **Deprecated by AWS Synthetics. You can't create canaries with deprecated runtimes.**
127+
*
118128
* `syn-nodejs-puppeteer-3.4` includes the following:
119129
* - Lambda runtime Node.js 12.x
120130
* - Puppeteer-core version 5.5.0
@@ -177,10 +187,52 @@ export class Runtime {
177187
* - Selenium version 3.141.0
178188
* - Chromium version 83.0.4103.0
179189
*
180-
* @see https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Synthetics_Library_python_selenium.html
190+
* @see https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Synthetics_Library_python_selenium.html#CloudWatch_Synthetics_runtimeversion-syn-python-selenium-1.0
181191
*/
182192
public static readonly SYNTHETICS_PYTHON_SELENIUM_1_0 = new Runtime('syn-python-selenium-1.0', RuntimeFamily.PYTHON);
183193

194+
/**
195+
* `syn-python-selenium-1.1` includes the following:
196+
* - Lambda runtime Python 3.8
197+
* - Selenium version 3.141.0
198+
* - Chromium version 83.0.4103.0
199+
*
200+
* New Features:
201+
* - **Custom handler function**: You can now use a custom handler function for your canary scripts.
202+
* - **Configuration options for adding metrics and step failure configurations**: These options were already available in runtimes for Node.js canaries.
203+
* - **Custom arguments in Chrome**: You can now open a browser in incognito mode or pass in proxy server configuration.
204+
* - **Cross-Region artifact buckets**: A canary can store its artifacts in an Amazon S3 bucket in a different Region.
205+
*
206+
* @see https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Synthetics_Library_python_selenium.html#CloudWatch_Synthetics_runtimeversion-syn-python-selenium-1.1
207+
*/
208+
public static readonly SYNTHETICS_PYTHON_SELENIUM_1_1 = new Runtime('syn-python-selenium-1.1', RuntimeFamily.PYTHON);
209+
210+
/**
211+
* `syn-python-selenium-1.2` includes the following:
212+
* - Lambda runtime Python 3.8
213+
* - Selenium version 3.141.0
214+
* - Chromium version 92.0.4512.0
215+
*
216+
* New Features:
217+
* - **Updated dependencies**: The only new features in this runtime are the updated dependencies.
218+
*
219+
* @see https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Synthetics_Library_python_selenium.html#CloudWatch_Synthetics_runtimeversion-syn-python-selenium-1.2
220+
*/
221+
public static readonly SYNTHETICS_PYTHON_SELENIUM_1_2 = new Runtime('syn-python-selenium-1.2', RuntimeFamily.PYTHON);
222+
223+
/**
224+
* `syn-python-selenium-1.3` includes the following:
225+
* - Lambda runtime Python 3.8
226+
* - Selenium version 3.141.0
227+
* - Chromium version 92.0.4512.0
228+
*
229+
* New Features:
230+
* - **More precise timestamps**: The start time and stop time of canary runs are now precise to the millisecond.
231+
*
232+
* @see https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Synthetics_Library_python_selenium.html#CloudWatch_Synthetics_runtimeversion-syn-python-selenium-1.3
233+
*/
234+
public static readonly SYNTHETICS_PYTHON_SELENIUM_1_3 = new Runtime('syn-python-selenium-1.3', RuntimeFamily.PYTHON);
235+
184236
/**
185237
* @param name The name of the runtime version
186238
* @param family The Lambda runtime family

0 commit comments

Comments
 (0)