Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(synthetics): Adding DeleteLambdaResourcesOnCanaryDeletion prop to the canary L2 #23820

Merged
merged 6 commits into from
Jan 29, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 the lambda resources are to be deleted when the canary is deleted
SankyRed marked this conversation as resolved.
Show resolved Hide resolved
*
* @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-synthetics-canary.html#cfn-synthetics-canary-deletelambdaresourcesoncanarydeletion
*
* @default false
*/
readonly deleteLambdaResourcesOnCanaryDeletion?: boolean;
SankyRed marked this conversation as resolved.
Show resolved Hide resolved
}

/**
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.deleteLambdaResourcesOnCanaryDeletion,
});

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.
SankyRed marked this conversation as resolved.
Show resolved Hide resolved
*
* @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.
*
comcalvi marked this conversation as resolved.
Show resolved Hide resolved
* @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
20 changes: 20 additions & 0 deletions packages/@aws-cdk/aws-synthetics/test/canary.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,26 @@ test('Basic canary properties work', () => {
});
});

test('Canary deletion leads to lambda resource deletion property is set', () => {
SankyRed marked this conversation as resolved.
Show resolved Hide resolved
// GIVEN
const stack = new Stack();

// WHEN
new synthetics.Canary(stack, 'Canary', {
test: synthetics.Test.custom({
handler: 'index.handler',
code: synthetics.Code.fromInline('/* Synthetics handler code'),
}),
deleteLambdaResourcesOnCanaryDeletion: true,
runtime: synthetics.Runtime.SYNTHETICS_1_0,
});

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::Synthetics::Canary', {
DeleteLambdaResourcesOnCanaryDeletion: true,
});
});

test('Canary can have generated name', () => {
// GIVEN
const stack = new Stack();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "21.0.0",
"version": "29.0.0",
"files": {
"9d00e437db1f5f8788ce938a3f00a9a1b946820e78c9b4c36207c8475db882bb": {
"source": {
Expand Down Expand Up @@ -27,15 +27,15 @@
}
}
},
"32cb6cc1550e67ae5e77eb85a64192d2aa44c328b778079b139e3965fb042575": {
"4c74166545778fe2f895f948e7d6aec9c5427ffedc8ba02dcb70d5c2ea975967": {
"source": {
"path": "canary-one.template.json",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "32cb6cc1550e67ae5e77eb85a64192d2aa44c328b778079b139e3965fb042575.json",
"objectKey": "4c74166545778fe2f895f948e7d6aec9c5427ffedc8ba02dcb70d5c2ea975967.json",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
]
},
"Name": "canary-integ",
"RuntimeVersion": "syn-nodejs-puppeteer-3.2",
"RuntimeVersion": "syn-nodejs-puppeteer-3.8",
"Schedule": {
"DurationInSeconds": "0",
"Expression": "rate(1 minute)"
Expand Down Expand Up @@ -326,12 +326,13 @@
]
},
"Name": "assetcanary-one",
"RuntimeVersion": "syn-nodejs-puppeteer-3.2",
"RuntimeVersion": "syn-nodejs-puppeteer-3.8",
"Schedule": {
"DurationInSeconds": "0",
"Expression": "rate(5 minutes)"
},
"StartCanaryAfterCreation": true
"StartCanaryAfterCreation": true,
"DeleteLambdaResourcesOnCanaryDeletion": true
}
},
"MyCanaryTwoArtifactsBucket79B179B6": {
Expand Down Expand Up @@ -523,7 +524,7 @@
]
},
"Name": "assetcanary-two",
"RuntimeVersion": "syn-nodejs-puppeteer-3.2",
"RuntimeVersion": "syn-nodejs-puppeteer-3.8",
"Schedule": {
"DurationInSeconds": "0",
"Expression": "rate(5 minutes)"
Expand Down Expand Up @@ -720,7 +721,7 @@
]
},
"Name": "assetcanary-three",
"RuntimeVersion": "syn-nodejs-puppeteer-3.3",
"RuntimeVersion": "syn-nodejs-puppeteer-3.8",
"Schedule": {
"DurationInSeconds": "0",
"Expression": "rate(5 minutes)"
Expand Down Expand Up @@ -917,7 +918,7 @@
]
},
"Name": "assetcanary-four",
"RuntimeVersion": "syn-nodejs-puppeteer-3.7",
"RuntimeVersion": "syn-nodejs-puppeteer-3.8",
"Schedule": {
"DurationInSeconds": "0",
"Expression": "rate(5 minutes)"
Expand Down Expand Up @@ -1311,7 +1312,7 @@
]
},
"Name": "py-canary-integ",
"RuntimeVersion": "syn-python-selenium-1.0",
"RuntimeVersion": "syn-python-selenium-1.3",
"Schedule": {
"DurationInSeconds": "0",
"Expression": "rate(5 minutes)"
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"version":"21.0.0"}
{"version":"29.0.0"}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "21.0.0",
"version": "29.0.0",
"testCases": {
"integ.canary": {
"stacks": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
{
"version": "21.0.0",
"version": "29.0.0",
"artifacts": {
"Tree": {
"type": "cdk:tree",
"properties": {
"file": "tree.json"
}
},
"canary-one.assets": {
"type": "cdk:asset-manifest",
"properties": {
Expand All @@ -23,7 +17,7 @@
"validateOnSynth": false,
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}",
"cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}",
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/32cb6cc1550e67ae5e77eb85a64192d2aa44c328b778079b139e3965fb042575.json",
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/4c74166545778fe2f895f948e7d6aec9c5427ffedc8ba02dcb70d5c2ea975967.json",
"requiresBootstrapStackVersion": 6,
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version",
"additionalDependencies": [
Expand Down Expand Up @@ -215,6 +209,12 @@
]
},
"displayName": "canary-one"
},
"Tree": {
"type": "cdk:tree",
"properties": {
"file": "tree.json"
}
}
}
}
Loading