Skip to content

Commit

Permalink
fix(synthetics): canary name can be up to 255 characters (aws#32385)
Browse files Browse the repository at this point in the history
Fixes aws#32376

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
kaizencc authored Dec 9, 2024
1 parent 453045b commit 231e1bf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions packages/aws-cdk-lib/aws-synthetics/lib/canary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -745,8 +745,8 @@ const nameRegex: RegExp = /^[0-9a-z_\-]+$/;
* @param name - the given name of the canary
*/
function validateName(name: string) {
if (name.length > 21) {
throw new Error(`Canary name is too large, must be between 1 and 21 characters, but is ${name.length} (got "${name}")`);
if (name.length > 255) {
throw new Error(`Canary name is too large, must be between 1 and 255 characters, but is ${name.length} (got "${name}")`);
}
if (!nameRegex.test(name)) {
throw new Error(`Canary name must be lowercase, numbers, hyphens, or underscores (got "${name}")`);
Expand Down
12 changes: 6 additions & 6 deletions packages/aws-cdk-lib/aws-synthetics/test/canary.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,23 +104,23 @@ test('Throws when name is specified incorrectly', () => {
}),
runtime: synthetics.Runtime.SYNTHETICS_NODEJS_PUPPETEER_8_0,
}))
.toThrowError('Canary name must be lowercase, numbers, hyphens, or underscores (got "My Canary")');
.toThrow('Canary name must be lowercase, numbers, hyphens, or underscores (got "My Canary")');
});

test('Throws when name has more than 21 characters', () => {
test('Throws when name has more than 255 characters', () => {
// GIVEN
const stack = new Stack();

// THEN
expect(() => new synthetics.Canary(stack, 'Canary', {
canaryName: 'a'.repeat(22),
canaryName: 'a'.repeat(256),
test: synthetics.Test.custom({
handler: 'index.handler',
code: synthetics.Code.fromInline('/* Synthetics handler code */'),
}),
runtime: synthetics.Runtime.SYNTHETICS_NODEJS_PUPPETEER_8_0,
}))
.toThrowError(`Canary name is too large, must be between 1 and 21 characters, but is 22 (got "${'a'.repeat(22)}")`);
.toThrow(`Canary name is too large, must be between 1 and 255 characters, but is 256 (got "${'a'.repeat(256)}")`);
});

test('An existing role can be specified instead of auto-created', () => {
Expand Down Expand Up @@ -561,7 +561,7 @@ test('Throws when rate above 60 minutes', () => {
}),
runtime: synthetics.Runtime.SYNTHETICS_NODEJS_PUPPETEER_8_0,
}))
.toThrowError('Schedule duration must be between 1 and 60 minutes');
.toThrow('Schedule duration must be between 1 and 60 minutes');
});

test('Throws when rate above is not a whole number of minutes', () => {
Expand All @@ -577,7 +577,7 @@ test('Throws when rate above is not a whole number of minutes', () => {
}),
runtime: synthetics.Runtime.SYNTHETICS_NODEJS_PUPPETEER_8_0,
}))
.toThrowError('\'59 seconds\' cannot be converted into a whole number of minutes.');
.toThrow('\'59 seconds\' cannot be converted into a whole number of minutes.');
});

test('Can share artifacts bucket between canaries', () => {
Expand Down

0 comments on commit 231e1bf

Please sign in to comment.