Skip to content

Commit

Permalink
Updating the readme and updating the runtime versions to latest avail…
Browse files Browse the repository at this point in the history
…able
  • Loading branch information
SankyRed committed Jan 25, 2023
1 parent 72aef8e commit 24f070f
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 37 deletions.
21 changes: 21 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,27 @@ 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 canary = 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_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
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-synthetics/lib/canary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ export interface CanaryProps {
readonly securityGroups?: ec2.ISecurityGroup[];

/**
* Whether or not the lambda resources are to be deleted when the canary is deleted
* 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
*
Expand Down
60 changes: 30 additions & 30 deletions packages/@aws-cdk/aws-synthetics/test/canary.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ test('Basic canary properties work', () => {
failureRetentionPeriod: Duration.days(10),
startAfterCreation: false,
timeToLive: Duration.minutes(30),
runtime: synthetics.Runtime.SYNTHETICS_1_0,
runtime: synthetics.Runtime.SYNTHETICS_NODEJS_PUPPETEER_3_8,
});

// THEN
Expand All @@ -30,11 +30,11 @@ test('Basic canary properties work', () => {
FailureRetentionPeriod: 10,
StartCanaryAfterCreation: false,
Schedule: Match.objectLike({ DurationInSeconds: '1800' }),
RuntimeVersion: 'syn-1.0',
RuntimeVersion: 'syn-nodejs-puppeteer-3.8',
});
});

test('Canary deletion leads to lambda resource deletion property is set', () => {
test('Can set `DeleteLambdaResourceOnCanaryDeletion`', () => {
// GIVEN
const stack = new Stack();

Expand All @@ -45,7 +45,7 @@ test('Canary deletion leads to lambda resource deletion property is set', () =>
code: synthetics.Code.fromInline('/* Synthetics handler code'),
}),
deleteLambdaResourcesOnCanaryDeletion: true,
runtime: synthetics.Runtime.SYNTHETICS_1_0,
runtime: synthetics.Runtime.SYNTHETICS_NODEJS_PUPPETEER_3_8,
});

// THEN
Expand All @@ -64,7 +64,7 @@ test('Canary can have generated name', () => {
handler: 'index.handler',
code: synthetics.Code.fromInline('/* Synthetics handler code */'),
}),
runtime: synthetics.Runtime.SYNTHETICS_NODEJS_PUPPETEER_3_1,
runtime: synthetics.Runtime.SYNTHETICS_NODEJS_PUPPETEER_3_8,
});

// THEN
Expand All @@ -84,7 +84,7 @@ test('Name validation does not fail when using Tokens', () => {
handler: 'index.handler',
code: synthetics.Code.fromInline('/* Synthetics handler code */'),
}),
runtime: synthetics.Runtime.SYNTHETICS_1_0,
runtime: synthetics.Runtime.SYNTHETICS_NODEJS_PUPPETEER_3_8,
});

// THEN: no exception
Expand All @@ -102,7 +102,7 @@ test('Throws when name is specified incorrectly', () => {
handler: 'index.handler',
code: synthetics.Code.fromInline('/* Synthetics handler code */'),
}),
runtime: synthetics.Runtime.SYNTHETICS_1_0,
runtime: synthetics.Runtime.SYNTHETICS_NODEJS_PUPPETEER_3_8,
}))
.toThrowError('Canary name must be lowercase, numbers, hyphens, or underscores (got "My Canary")');
});
Expand All @@ -118,7 +118,7 @@ test('Throws when name has more than 21 characters', () => {
handler: 'index.handler',
code: synthetics.Code.fromInline('/* Synthetics handler code */'),
}),
runtime: synthetics.Runtime.SYNTHETICS_1_0,
runtime: synthetics.Runtime.SYNTHETICS_NODEJS_PUPPETEER_3_8,
}))
.toThrowError(`Canary name is too large, must be between 1 and 21 characters, but is 22 (got "${'a'.repeat(22)}")`);
});
Expand All @@ -140,7 +140,7 @@ test('An existing role can be specified instead of auto-created', () => {
handler: 'index.handler',
code: synthetics.Code.fromInline('/* Synthetics handler code */'),
}),
runtime: synthetics.Runtime.SYNTHETICS_1_0,
runtime: synthetics.Runtime.SYNTHETICS_NODEJS_PUPPETEER_3_8,
});

// THEN
Expand All @@ -162,7 +162,7 @@ test('An existing bucket and prefix can be specified instead of auto-created', (
handler: 'index.handler',
code: synthetics.Code.fromInline('/* Synthetics handler code */'),
}),
runtime: synthetics.Runtime.SYNTHETICS_1_0,
runtime: synthetics.Runtime.SYNTHETICS_NODEJS_PUPPETEER_3_8,
});

// THEN
Expand All @@ -177,7 +177,7 @@ test('Runtime can be specified', () => {

// WHEN
new synthetics.Canary(stack, 'Canary', {
runtime: synthetics.Runtime.SYNTHETICS_1_0,
runtime: synthetics.Runtime.SYNTHETICS_NODEJS_PUPPETEER_3_8,
test: synthetics.Test.custom({
handler: 'index.handler',
code: synthetics.Code.fromInline('/* Synthetics handler code */'),
Expand All @@ -186,7 +186,7 @@ test('Runtime can be specified', () => {

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::Synthetics::Canary', {
RuntimeVersion: 'syn-1.0',
RuntimeVersion: 'syn-nodejs-puppeteer-3.8',
});
});

Expand All @@ -196,7 +196,7 @@ test('Python runtime can be specified', () => {

// WHEN
new synthetics.Canary(stack, 'Canary', {
runtime: synthetics.Runtime.SYNTHETICS_PYTHON_SELENIUM_1_0,
runtime: synthetics.Runtime.SYNTHETICS_PYTHON_SELENIUM_1_3,
test: synthetics.Test.custom({
handler: 'index.handler',
code: synthetics.Code.fromInline('# Synthetics handler code'),
Expand All @@ -205,7 +205,7 @@ test('Python runtime can be specified', () => {

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::Synthetics::Canary', {
RuntimeVersion: 'syn-python-selenium-1.0',
RuntimeVersion: 'syn-python-selenium-1.3',
});
});

Expand All @@ -219,7 +219,7 @@ test('environment variables can be specified', () => {

// WHEN
new synthetics.Canary(stack, 'Canary', {
runtime: synthetics.Runtime.SYNTHETICS_1_0,
runtime: synthetics.Runtime.SYNTHETICS_NODEJS_PUPPETEER_3_8,
test: synthetics.Test.custom({
handler: 'index.handler',
code: synthetics.Code.fromInline('/* Synthetics handler code */'),
Expand All @@ -241,7 +241,7 @@ test('environment variables are skipped if not provided', () => {

// WHEN
new synthetics.Canary(stack, 'Canary', {
runtime: synthetics.Runtime.SYNTHETICS_1_0,
runtime: synthetics.Runtime.SYNTHETICS_NODEJS_PUPPETEER_3_8,
test: synthetics.Test.custom({
handler: 'index.handler',
code: synthetics.Code.fromInline('/* Synthetics handler code */'),
Expand Down Expand Up @@ -284,7 +284,7 @@ test('Schedule can be set with Rate', () => {
handler: 'index.handler',
code: synthetics.Code.fromInline('/* Synthetics handler code */'),
}),
runtime: synthetics.Runtime.SYNTHETICS_1_0,
runtime: synthetics.Runtime.SYNTHETICS_NODEJS_PUPPETEER_3_8,
});

// THEN
Expand All @@ -304,7 +304,7 @@ test('Schedule can be set to 1 minute', () => {
handler: 'index.handler',
code: synthetics.Code.fromInline('/* Synthetics handler code */'),
}),
runtime: synthetics.Runtime.SYNTHETICS_NODEJS_2_0,
runtime: synthetics.Runtime.SYNTHETICS_NODEJS_PUPPETEER_3_8,
});

// THEN
Expand All @@ -324,7 +324,7 @@ test('Schedule can be set with Cron', () => {
handler: 'index.handler',
code: synthetics.Code.fromInline('/* Synthetics handler code */'),
}),
runtime: synthetics.Runtime.SYNTHETICS_NODEJS_PUPPETEER_3_3,
runtime: synthetics.Runtime.SYNTHETICS_NODEJS_PUPPETEER_3_8,
});

// THEN
Expand All @@ -345,7 +345,7 @@ test('Schedule can be set with Expression', () => {
handler: 'index.handler',
code: synthetics.Code.fromInline('/* Synthetics handler code */'),
}),
runtime: synthetics.Runtime.SYNTHETICS_NODEJS_2_0,
runtime: synthetics.Runtime.SYNTHETICS_NODEJS_PUPPETEER_3_8,
});

// THEN
Expand All @@ -365,7 +365,7 @@ test('Schedule can be set to run once', () => {
handler: 'index.handler',
code: synthetics.Code.fromInline('/* Synthetics handler code */'),
}),
runtime: synthetics.Runtime.SYNTHETICS_NODEJS_2_0,
runtime: synthetics.Runtime.SYNTHETICS_NODEJS_PUPPETEER_3_8,
});

// THEN
Expand All @@ -385,7 +385,7 @@ test('Throws when rate above 60 minutes', () => {
handler: 'index.handler',
code: synthetics.Code.fromInline('/* Synthetics handler code */'),
}),
runtime: synthetics.Runtime.SYNTHETICS_NODEJS_2_0,
runtime: synthetics.Runtime.SYNTHETICS_NODEJS_PUPPETEER_3_8,
}))
.toThrowError('Schedule duration must be between 1 and 60 minutes');
});
Expand All @@ -401,7 +401,7 @@ test('Throws when rate above is not a whole number of minutes', () => {
handler: 'index.handler',
code: synthetics.Code.fromInline('/* Synthetics handler code */'),
}),
runtime: synthetics.Runtime.SYNTHETICS_NODEJS_2_0,
runtime: synthetics.Runtime.SYNTHETICS_NODEJS_PUPPETEER_3_8,
}))
.toThrowError('\'59 seconds\' cannot be converted into a whole number of minutes.');
});
Expand All @@ -417,7 +417,7 @@ test('Can share artifacts bucket between canaries', () => {
handler: 'index.handler',
code: synthetics.Code.fromInline('/* Synthetics handler code */'),
}),
runtime: synthetics.Runtime.SYNTHETICS_NODEJS_2_0,
runtime: synthetics.Runtime.SYNTHETICS_NODEJS_PUPPETEER_3_8,
});

const canary2 = new synthetics.Canary(stack, 'Canary2', {
Expand All @@ -427,7 +427,7 @@ test('Can share artifacts bucket between canaries', () => {
code: synthetics.Code.fromInline('/* Synthetics handler code */'),
}),
artifactsBucketLocation: { bucket: canary1.artifactsBucket },
runtime: synthetics.Runtime.SYNTHETICS_NODEJS_2_0,
runtime: synthetics.Runtime.SYNTHETICS_NODEJS_PUPPETEER_3_8,
});

// THEN
Expand All @@ -447,7 +447,7 @@ test('can specify custom test', () => {
console.log(\'hello world\');
};`),
}),
runtime: synthetics.Runtime.SYNTHETICS_NODEJS_2_0,
runtime: synthetics.Runtime.SYNTHETICS_NODEJS_PUPPETEER_3_8,
});

// THEN
Expand Down Expand Up @@ -477,7 +477,7 @@ describe('canary in a vpc', () => {
console.log(\'hello world\');
};`),
}),
runtime: synthetics.Runtime.SYNTHETICS_NODEJS_2_0,
runtime: synthetics.Runtime.SYNTHETICS_NODEJS_PUPPETEER_3_8,
vpc,
});

Expand Down Expand Up @@ -512,7 +512,7 @@ describe('canary in a vpc', () => {
console.log(\'hello world\');
};`),
}),
runtime: synthetics.Runtime.SYNTHETICS_NODEJS_2_0,
runtime: synthetics.Runtime.SYNTHETICS_NODEJS_PUPPETEER_3_8,
vpc,
});

Expand Down Expand Up @@ -550,7 +550,7 @@ describe('canary in a vpc', () => {
console.log(\'hello world\');
};`),
}),
runtime: synthetics.Runtime.SYNTHETICS_NODEJS_2_0,
runtime: synthetics.Runtime.SYNTHETICS_NODEJS_PUPPETEER_3_8,
vpc,
securityGroups: [sg],
});
Expand Down Expand Up @@ -590,7 +590,7 @@ test('Role policy generated as expected', () => {
handler: 'index.handler',
code: synthetics.Code.fromInline('/* Synthetics handler code */'),
}),
runtime: synthetics.Runtime.SYNTHETICS_NODEJS_PUPPETEER_3_3,
runtime: synthetics.Runtime.SYNTHETICS_NODEJS_PUPPETEER_3_8,
});

// THEN
Expand Down
8 changes: 4 additions & 4 deletions packages/@aws-cdk/aws-synthetics/test/code.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe(synthetics.Code.fromAsset, () => {
handler: 'canary.handler',
code: directoryAsset,
}),
runtime: synthetics.Runtime.SYNTHETICS_NODEJS_2_0,
runtime: synthetics.Runtime.SYNTHETICS_NODEJS_PUPPETEER_3_8,
});

// THEN
Expand All @@ -75,7 +75,7 @@ describe(synthetics.Code.fromAsset, () => {
handler: 'canary.handler',
code: directoryAsset,
}),
runtime: synthetics.Runtime.SYNTHETICS_PYTHON_SELENIUM_1_0,
runtime: synthetics.Runtime.SYNTHETICS_PYTHON_SELENIUM_1_3,
});

// THEN
Expand Down Expand Up @@ -104,15 +104,15 @@ describe(synthetics.Code.fromAsset, () => {
handler: 'canary.handler',
code: directoryAsset,
}),
runtime: synthetics.Runtime.SYNTHETICS_NODEJS_2_0,
runtime: synthetics.Runtime.SYNTHETICS_NODEJS_PUPPETEER_3_8,
});

new synthetics.Canary(stack, 'Canary2', {
test: synthetics.Test.custom({
handler: 'canary.handler',
code: directoryAsset,
}),
runtime: synthetics.Runtime.SYNTHETICS_NODEJS_2_0,
runtime: synthetics.Runtime.SYNTHETICS_NODEJS_PUPPETEER_3_8,
});

// THEN
Expand Down
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-synthetics/test/metric.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ test('.metricXxx() methods can be used to obtain Metrics for the canary', () =>
handler: 'index.handler',
code: synthetics.Code.fromInline('foo'),
}),
runtime: synthetics.Runtime.SYNTHETICS_NODEJS_2_0,
runtime: synthetics.Runtime.SYNTHETICS_NODEJS_PUPPETEER_3_8,
});

// WHEN
Expand Down Expand Up @@ -50,7 +50,7 @@ test('Metric can specify statistic', () => {
handler: 'index.handler',
code: synthetics.Code.fromInline('foo'),
}),
runtime: synthetics.Runtime.SYNTHETICS_NODEJS_2_0,
runtime: synthetics.Runtime.SYNTHETICS_NODEJS_PUPPETEER_3_8,
});

// WHEN
Expand Down

0 comments on commit 24f070f

Please sign in to comment.