Skip to content

Commit

Permalink
fix: duration doesn't get accurately compared in multi alb service ba…
Browse files Browse the repository at this point in the history
…se (#27664)

Duration wasn't getting compared correctly and prevented some values, eg between 5 and 9 or 500 and 999 (perhaps others as well), from getting used for `ApplicationMultipleTargetGroupsService.idleTimeout`.

Relates to #21584, that fixes this issue for ApplicationLoadBalancedService (however the problem description was not fully correct in regards to what range of values were getting denied).

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
markanderstam authored Oct 26, 2023
1 parent 05f3453 commit 7e426c8
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,7 @@
},
{
"Key": "idle_timeout.timeout_seconds",
"Value": "400"
"Value": "5"
}
],
"Scheme": "internet-facing",
Expand Down Expand Up @@ -1101,7 +1101,7 @@
},
{
"Key": "idle_timeout.timeout_seconds",
"Value": "400"
"Value": "500"
}
],
"Scheme": "internet-facing",
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ new ApplicationMultipleTargetGroupsEc2Service(stack, 'myService', {
loadBalancers: [
{
name: 'lb',
idleTimeout: Duration.seconds(400),
idleTimeout: Duration.seconds(5),
domainName: 'api.example.com',
domainZone: zone,
listeners: [
Expand All @@ -41,7 +41,7 @@ new ApplicationMultipleTargetGroupsEc2Service(stack, 'myService', {
},
{
name: 'lb2',
idleTimeout: Duration.seconds(400),
idleTimeout: Duration.seconds(500),
domainName: 'frontend.example.com',
domainZone: zone,
listeners: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ export interface ApplicationLoadBalancerProps {
readonly domainZone?: IHostedZone;

/**
* The load balancer idle timeout, in seconds
* The load balancer idle timeout, in seconds. Can be between 1 and 4000 seconds.
*
* @default - CloudFormation sets idle timeout to 60 seconds
*/
Expand Down Expand Up @@ -585,7 +585,8 @@ export abstract class ApplicationMultipleTargetGroupsServiceBase extends Constru
private validateLbProps(props: ApplicationLoadBalancerProps[]) {
for (let prop of props) {
if (prop.idleTimeout) {
if (prop.idleTimeout > Duration.seconds(4000) || prop.idleTimeout < Duration.seconds(1)) {
const idleTimeout = prop.idleTimeout.toSeconds();
if (idleTimeout > Duration.seconds(4000).toSeconds() || idleTimeout < Duration.seconds(1).toSeconds()) {
throw new Error('Load balancer idle timeout must be between 1 and 4000 seconds.');
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/aws-cdk-lib/aws-ecs-patterns/test/ec2/l3s.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -983,7 +983,7 @@ test('passes when idleTimeout is between 1 and 4000 seconds for multiAlbService'
loadBalancers: [
{
name: 'lb',
idleTimeout: Duration.seconds(400),
idleTimeout: Duration.seconds(5),
domainName: 'api.example.com',
domainZone: new PublicHostedZone(stack, 'HostedZone', { zoneName: 'example.com' }),
listeners: [
Expand All @@ -997,7 +997,7 @@ test('passes when idleTimeout is between 1 and 4000 seconds for multiAlbService'
},
{
name: 'lb2',
idleTimeout: Duration.seconds(120),
idleTimeout: Duration.seconds(500),
domainName: 'frontend.com',
domainZone: new PublicHostedZone(stack, 'HostedZone2', { zoneName: 'frontend.com' }),
listeners: [
Expand Down

0 comments on commit 7e426c8

Please sign in to comment.