Skip to content

Commit

Permalink
feat(synthetics): Adding DeleteLambdaResourcesOnCanaryDeletion prop t…
Browse files Browse the repository at this point in the history
…o the canary L2 (#23820)

This PR is to add the DeleteLambdaResourcesOnCanaryDeletion prop to the canary L2.
  • Loading branch information
SankyRed authored Jan 29, 2023
1 parent 0b25265 commit 45c191e
Show file tree
Hide file tree
Showing 20 changed files with 317 additions and 113 deletions.
23 changes: 23 additions & 0 deletions packages/@aws-cdk/aws-synthetics/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,29 @@ const schedule = synthetics.Schedule.cron({

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


### Canary DeleteLambdaResourcesOnCanaryDeletion

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.

This can be provisioned by setting the `DeleteLambdaResourcesOnCanaryDeletion` property to `true` when we define the canary.

```ts
const stack = new Stack();

const canary = new synthetics.Canary(stack, 'Canary', {
test: synthetics.Test.custom({
handler: 'index.handler',
code: synthetics.Code.fromInline('/* Synthetics handler code'),
}),
enableAutoDeleteLambdas: true,
runtime: synthetics.Runtime.SYNTHETICS_NODEJS_PUPPETEER_3_8,
});
```

Even when set to `true` there are resources such as S3 buckets/logs that do NOT get deleted and are to be deleted manually.


### Configuring the Canary Script

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.
Expand Down
10 changes: 10 additions & 0 deletions packages/@aws-cdk/aws-synthetics/lib/canary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,15 @@ export interface CanaryProps {
* not specified a dedicated security group will be created for this canary.
*/
readonly securityGroups?: ec2.ISecurityGroup[];

/**
* Whether or not to delete the lambda resources when the canary is deleted
*
* @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-synthetics-canary.html#cfn-synthetics-canary-deletelambdaresourcesoncanarydeletion
*
* @default false
*/
readonly enableAutoDeleteLambdas?: boolean;
}

/**
Expand Down Expand Up @@ -281,6 +290,7 @@ export class Canary extends cdk.Resource implements ec2.IConnectable {
code: this.createCode(props),
runConfig: this.createRunConfig(props),
vpcConfig: this.createVpcConfig(props),
deleteLambdaResourcesOnCanaryDeletion: props.enableAutoDeleteLambdas,
});

this.canaryId = resource.attrId;
Expand Down
54 changes: 53 additions & 1 deletion packages/@aws-cdk/aws-synthetics/lib/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ export class Runtime {
public static readonly SYNTHETICS_NODEJS_2_2 = new Runtime('syn-nodejs-2.2', RuntimeFamily.NODEJS);

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

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

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

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

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

/**
* `syn-python-selenium-1.1` includes the following:
* - Lambda runtime Python 3.8
* - Selenium version 3.141.0
* - Chromium version 83.0.4103.0
*
* New Features:
* - **Custom handler function**: You can now use a custom handler function for your canary scripts.
* - **Configuration options for adding metrics and step failure configurations**: These options were already available in runtimes for Node.js canaries.
* - **Custom arguments in Chrome**: You can now open a browser in incognito mode or pass in proxy server configuration.
* - **Cross-Region artifact buckets**: A canary can store its artifacts in an Amazon S3 bucket in a different Region.
*
* @see https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Synthetics_Library_python_selenium.html#CloudWatch_Synthetics_runtimeversion-syn-python-selenium-1.1
*/
public static readonly SYNTHETICS_PYTHON_SELENIUM_1_1 = new Runtime('syn-python-selenium-1.1', RuntimeFamily.PYTHON);

/**
* `syn-python-selenium-1.2` includes the following:
* - Lambda runtime Python 3.8
* - Selenium version 3.141.0
* - Chromium version 92.0.4512.0
*
* New Features:
* - **Updated dependencies**: The only new features in this runtime are the updated dependencies.
*
* @see https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Synthetics_Library_python_selenium.html#CloudWatch_Synthetics_runtimeversion-syn-python-selenium-1.2
*/
public static readonly SYNTHETICS_PYTHON_SELENIUM_1_2 = new Runtime('syn-python-selenium-1.2', RuntimeFamily.PYTHON);

/**
* `syn-python-selenium-1.3` includes the following:
* - Lambda runtime Python 3.8
* - Selenium version 3.141.0
* - Chromium version 92.0.4512.0
*
* New Features:
* - **More precise timestamps**: The start time and stop time of canary runs are now precise to the millisecond.
*
* @see https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Synthetics_Library_python_selenium.html#CloudWatch_Synthetics_runtimeversion-syn-python-selenium-1.3
*/
public static readonly SYNTHETICS_PYTHON_SELENIUM_1_3 = new Runtime('syn-python-selenium-1.3', RuntimeFamily.PYTHON);

/**
* @param name The name of the runtime version
* @param family The Lambda runtime family
Expand Down
Loading

0 comments on commit 45c191e

Please sign in to comment.