Skip to content

Commit

Permalink
refactor: don't change public method
Browse files Browse the repository at this point in the history
  • Loading branch information
iRoachie committed Oct 28, 2021
1 parent 0e7ddaa commit ccc444e
Showing 1 changed file with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,11 @@ export class ApplicationTargetGroup extends TargetGroupBase implements IApplicat
this.setAttribute('slow_start.duration_seconds', props.slowStart.toSeconds().toString());
}

this.enableCookieStickiness(props.stickinessCookieDuration, props.stickinessCookieName);
if (props.stickinessCookieDuration) {
this.enableCookieStickiness(props.stickinessCookieDuration, props.stickinessCookieName);
} else {
this.setAttribute('stickiness.enabled', 'false');
}

if (props.loadBalancingAlgorithmType) {
this.setAttribute('load_balancing.algorithm.type', props.loadBalancingAlgorithmType);
Expand All @@ -172,12 +176,7 @@ export class ApplicationTargetGroup extends TargetGroupBase implements IApplicat
*
* @see https://docs.aws.amazon.com/elasticloadbalancing/latest/application/sticky-sessions.html
*/
public enableCookieStickiness(duration?: Duration, cookieName?: string) {
if (typeof duration === 'undefined') {
this.setAttribute('stickiness.enabled', 'false');
return;
}

public enableCookieStickiness(duration: Duration, cookieName?: string) {
if (duration.toSeconds() < 1 || duration.toSeconds() > 604800) {
throw new Error('Stickiness cookie duration value must be between 1 second and 7 days (604800 seconds).');
}
Expand Down

0 comments on commit ccc444e

Please sign in to comment.