@guardian/cdk 51.0.0 → 52.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/constructs/loadbalancing/index.d.ts +0 -1
- package/lib/constructs/loadbalancing/index.d.ts.map +1 -1
- package/lib/constructs/loadbalancing/index.js +0 -1
- package/lib/constructs/loadbalancing/index.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +12 -12
- package/lib/constructs/loadbalancing/elb.d.ts +0 -91
- package/lib/constructs/loadbalancing/elb.d.ts.map +0 -1
- package/lib/constructs/loadbalancing/elb.js +0 -109
- package/lib/constructs/loadbalancing/elb.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@guardian/cdk",
|
|
3
3
|
"description": "Generic Guardian flavoured AWS CDK components",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "52.0.0",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
7
7
|
"files": [
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"test:dev": "jest --detectOpenHandles --runInBand --watch",
|
|
23
23
|
"prepare": "tsc",
|
|
24
24
|
"prepack": "cp -r src/bin/commands/new-project/template lib/bin/commands/new-project/template",
|
|
25
|
-
"release": "
|
|
25
|
+
"release": "npx changeset",
|
|
26
26
|
"release:docs": "rm -rf target && typedoc && gh-pages -d target -u \"github-actions-bot <support+actions@github.com>\"",
|
|
27
27
|
"serve:docs": "rm -rf target && typedoc && serve target",
|
|
28
28
|
"cli:dev": "ts-node src/bin/index.ts"
|
|
@@ -32,13 +32,13 @@
|
|
|
32
32
|
"@guardian/eslint-plugin-tsdoc-required": "^0.1.3",
|
|
33
33
|
"@guardian/tsconfig": "^0.2.0",
|
|
34
34
|
"@types/git-url-parse": "^9.0.1",
|
|
35
|
-
"@types/jest": "^29.5.
|
|
36
|
-
"@types/js-yaml": "^4.0.
|
|
37
|
-
"@types/lodash.camelcase": "^4.3.
|
|
38
|
-
"@types/lodash.kebabcase": "^4.1.
|
|
39
|
-
"@types/lodash.upperfirst": "^4.3.
|
|
40
|
-
"@types/node": "20.8.
|
|
41
|
-
"@types/yargs": "^17.0.
|
|
35
|
+
"@types/jest": "^29.5.6",
|
|
36
|
+
"@types/js-yaml": "^4.0.8",
|
|
37
|
+
"@types/lodash.camelcase": "^4.3.8",
|
|
38
|
+
"@types/lodash.kebabcase": "^4.1.8",
|
|
39
|
+
"@types/lodash.upperfirst": "^4.3.8",
|
|
40
|
+
"@types/node": "20.8.8",
|
|
41
|
+
"@types/yargs": "^17.0.28",
|
|
42
42
|
"aws-cdk": "2.100.0",
|
|
43
43
|
"cz-conventional-changelog": "^3.3.0",
|
|
44
44
|
"eslint": "^8.50.0",
|
|
@@ -46,19 +46,19 @@
|
|
|
46
46
|
"gh-pages": "^6.0.0",
|
|
47
47
|
"jest": "^29.7.0",
|
|
48
48
|
"prettier": "^3.0.3",
|
|
49
|
-
"semantic-release": "^22.0.5",
|
|
50
49
|
"serve": "^14.2.1",
|
|
51
50
|
"ts-jest": "^29.1.1",
|
|
52
51
|
"ts-node": "^10.9.1",
|
|
53
|
-
"typedoc": "^0.25.
|
|
52
|
+
"typedoc": "^0.25.2",
|
|
54
53
|
"typescript": "5.1.6"
|
|
55
54
|
},
|
|
56
55
|
"dependencies": {
|
|
56
|
+
"@changesets/cli": "^2.26.2",
|
|
57
57
|
"@oclif/core": "2.15.0",
|
|
58
58
|
"aws-cdk-lib": "2.100.0",
|
|
59
59
|
"aws-sdk": "^2.1469.0",
|
|
60
60
|
"chalk": "^4.1.2",
|
|
61
|
-
"codemaker": "^1.
|
|
61
|
+
"codemaker": "^1.91.0",
|
|
62
62
|
"constructs": "10.3.0",
|
|
63
63
|
"git-url-parse": "^13.1.0",
|
|
64
64
|
"js-yaml": "^4.1.0",
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { Duration } from "aws-cdk-lib";
|
|
2
|
-
import { LoadBalancer, LoadBalancingProtocol } from "aws-cdk-lib/aws-elasticloadbalancing";
|
|
3
|
-
import type { HealthCheck, LoadBalancerListener, LoadBalancerProps } from "aws-cdk-lib/aws-elasticloadbalancing";
|
|
4
|
-
import type { AppIdentity, GuStack } from "../core";
|
|
5
|
-
interface GuClassicLoadBalancerProps extends Omit<LoadBalancerProps, "healthCheck">, AppIdentity {
|
|
6
|
-
propertiesToOverride?: Record<string, unknown>;
|
|
7
|
-
healthCheck?: Partial<HealthCheck>;
|
|
8
|
-
/**
|
|
9
|
-
* If your CloudFormation does not define the Scheme of your Load Balancer, you must set this boolean to true to avoid
|
|
10
|
-
* resource [replacement](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-elb.html#cfn-ec2-elb-scheme).
|
|
11
|
-
* If a Load Balancer is replaced it is likely to lead to downtime.
|
|
12
|
-
*/
|
|
13
|
-
removeScheme?: boolean;
|
|
14
|
-
}
|
|
15
|
-
declare const GuClassicLoadBalancer_base: {
|
|
16
|
-
new (...args: any[]): {
|
|
17
|
-
readonly idWithApp: string;
|
|
18
|
-
};
|
|
19
|
-
} & typeof LoadBalancer;
|
|
20
|
-
/**
|
|
21
|
-
* **IMPORTANT**: This construct should **only** be used if you are migrating an existing stack and you need to retain the load balancer.
|
|
22
|
-
* Please use [[`GuApplicationLoadBalancer`]] instead of [[`GuClassicLoadBalancer`]] wherever possible.
|
|
23
|
-
*
|
|
24
|
-
* By default, load balancers created via this construct will perform a healthcheck against `/healthcheck` on port 9000. All healthcheck
|
|
25
|
-
* defaults can be overridden via the `healthcheck` prop.
|
|
26
|
-
*
|
|
27
|
-
* For example, to use `/test` for the healthcheck path use:
|
|
28
|
-
*
|
|
29
|
-
* ```typescript
|
|
30
|
-
* new GuClassicLoadBalancer(stack, "ClassicLoadBalancer", {
|
|
31
|
-
* // other props
|
|
32
|
-
* healthCheck: {
|
|
33
|
-
* path: "/test",
|
|
34
|
-
* },
|
|
35
|
-
* });
|
|
36
|
-
* ```
|
|
37
|
-
* If you are running an application which only accepts traffic over HTTPs, consider using [[`GuHttpsClassicLoadBalancer`]]
|
|
38
|
-
* to reduce the amount of boilerplate needed when configuring your load balancer.
|
|
39
|
-
*
|
|
40
|
-
* This resource is stateful.
|
|
41
|
-
* @see https://github.com/guardian/cdk/blob/main/docs/stateful-resources.md
|
|
42
|
-
*/
|
|
43
|
-
export declare class GuClassicLoadBalancer extends GuClassicLoadBalancer_base {
|
|
44
|
-
static DefaultHealthCheck: {
|
|
45
|
-
port: number;
|
|
46
|
-
path: string;
|
|
47
|
-
protocol: LoadBalancingProtocol;
|
|
48
|
-
healthyThreshold: number;
|
|
49
|
-
unhealthyThreshold: number;
|
|
50
|
-
interval: Duration;
|
|
51
|
-
timeout: Duration;
|
|
52
|
-
};
|
|
53
|
-
constructor(scope: GuStack, id: string, props: GuClassicLoadBalancerProps);
|
|
54
|
-
}
|
|
55
|
-
interface GuHttpsClassicLoadBalancerProps extends Omit<GuClassicLoadBalancerProps, "listeners"> {
|
|
56
|
-
listener?: Partial<LoadBalancerListener>;
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* **IMPORTANT**: This construct should **only** be used if you are migrating an existing stack and you need to retain the load balancer.
|
|
60
|
-
* Please use [[`GuHttpsApplicationListener`]] instead of [[`GuHttpsClassicLoadBalancer`]] wherever possible.
|
|
61
|
-
*
|
|
62
|
-
* This construct creates a classic load balancer which accepts HTTPS traffic. It communicates with EC2 instances over port 9000
|
|
63
|
-
* by default. This default can be overridden via the listener prop, for example:
|
|
64
|
-
* ```typescript
|
|
65
|
-
* new GuHttpsClassicLoadBalancer(stack, "HttpsClassicLoadBalancer", {
|
|
66
|
-
* // other props
|
|
67
|
-
* listener: {
|
|
68
|
-
* internalPort: 3000,
|
|
69
|
-
* },
|
|
70
|
-
* });
|
|
71
|
-
* ```
|
|
72
|
-
*
|
|
73
|
-
* You can pass a certificate id to this construct via the listener interface, for example:
|
|
74
|
-
* ```typescript
|
|
75
|
-
* new GuHttpsClassicLoadBalancer(stack, "HttpsClassicLoadBalancer", {
|
|
76
|
-
* // other props
|
|
77
|
-
* listener: {
|
|
78
|
-
* sslCertificateId: "certificateId",
|
|
79
|
-
* },
|
|
80
|
-
* });
|
|
81
|
-
* ```
|
|
82
|
-
* If certificate id is omitted the library will create a Parameter which allows you to pass in a certificate ARN.
|
|
83
|
-
*
|
|
84
|
-
* For more details on migrating an existing load balancer and general load balancer defaults, see [[`GuClassicLoadBalancer`]].
|
|
85
|
-
*/
|
|
86
|
-
export declare class GuHttpsClassicLoadBalancer extends GuClassicLoadBalancer {
|
|
87
|
-
static DefaultListener: LoadBalancerListener;
|
|
88
|
-
constructor(scope: GuStack, id: string, props: GuHttpsClassicLoadBalancerProps);
|
|
89
|
-
}
|
|
90
|
-
export {};
|
|
91
|
-
//# sourceMappingURL=elb.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"elb.d.ts","sourceRoot":"","sources":["../../../src/constructs/loadbalancing/elb.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,sCAAsC,CAAC;AAC3F,OAAO,KAAK,EAEV,WAAW,EACX,oBAAoB,EACpB,iBAAiB,EAClB,MAAM,sCAAsC,CAAC;AAG9C,OAAO,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAEpD,UAAU,0BAA2B,SAAQ,IAAI,CAAC,iBAAiB,EAAE,aAAa,CAAC,EAAE,WAAW;IAC9F,oBAAoB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/C,WAAW,CAAC,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC;IACnC;;;;OAIG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;;;;;;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,qBAAa,qBAAsB,SAAQ,0BAAiC;IAC1E,MAAM,CAAC,kBAAkB;;;;;;;;MAQvB;gBAEU,KAAK,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,0BAA0B;CAiB1E;AAED,UAAU,+BAAgC,SAAQ,IAAI,CAAC,0BAA0B,EAAE,WAAW,CAAC;IAC7F,QAAQ,CAAC,EAAE,OAAO,CAAC,oBAAoB,CAAC,CAAC;CAC1C;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,qBAAa,0BAA2B,SAAQ,qBAAqB;IACnE,MAAM,CAAC,eAAe,EAAE,oBAAoB,CAK1C;gBAEU,KAAK,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,+BAA+B;CAmB/E"}
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.GuHttpsClassicLoadBalancer = exports.GuClassicLoadBalancer = void 0;
|
|
4
|
-
const aws_cdk_lib_1 = require("aws-cdk-lib");
|
|
5
|
-
const aws_elasticloadbalancing_1 = require("aws-cdk-lib/aws-elasticloadbalancing");
|
|
6
|
-
const app_aware_construct_1 = require("../../utils/mixin/app-aware-construct");
|
|
7
|
-
const core_1 = require("../core");
|
|
8
|
-
/**
|
|
9
|
-
* **IMPORTANT**: This construct should **only** be used if you are migrating an existing stack and you need to retain the load balancer.
|
|
10
|
-
* Please use [[`GuApplicationLoadBalancer`]] instead of [[`GuClassicLoadBalancer`]] wherever possible.
|
|
11
|
-
*
|
|
12
|
-
* By default, load balancers created via this construct will perform a healthcheck against `/healthcheck` on port 9000. All healthcheck
|
|
13
|
-
* defaults can be overridden via the `healthcheck` prop.
|
|
14
|
-
*
|
|
15
|
-
* For example, to use `/test` for the healthcheck path use:
|
|
16
|
-
*
|
|
17
|
-
* ```typescript
|
|
18
|
-
* new GuClassicLoadBalancer(stack, "ClassicLoadBalancer", {
|
|
19
|
-
* // other props
|
|
20
|
-
* healthCheck: {
|
|
21
|
-
* path: "/test",
|
|
22
|
-
* },
|
|
23
|
-
* });
|
|
24
|
-
* ```
|
|
25
|
-
* If you are running an application which only accepts traffic over HTTPs, consider using [[`GuHttpsClassicLoadBalancer`]]
|
|
26
|
-
* to reduce the amount of boilerplate needed when configuring your load balancer.
|
|
27
|
-
*
|
|
28
|
-
* This resource is stateful.
|
|
29
|
-
* @see https://github.com/guardian/cdk/blob/main/docs/stateful-resources.md
|
|
30
|
-
*/
|
|
31
|
-
class GuClassicLoadBalancer extends (0, app_aware_construct_1.GuAppAwareConstruct)(aws_elasticloadbalancing_1.LoadBalancer) {
|
|
32
|
-
constructor(scope, id, props) {
|
|
33
|
-
const mergedProps = {
|
|
34
|
-
...props,
|
|
35
|
-
healthCheck: { ...GuClassicLoadBalancer.DefaultHealthCheck, ...props.healthCheck },
|
|
36
|
-
};
|
|
37
|
-
super(scope, id, mergedProps);
|
|
38
|
-
const cfnLb = this.node.defaultChild;
|
|
39
|
-
if (props.removeScheme) {
|
|
40
|
-
cfnLb.addPropertyDeletionOverride("Scheme");
|
|
41
|
-
}
|
|
42
|
-
mergedProps.propertiesToOverride &&
|
|
43
|
-
Object.entries(mergedProps.propertiesToOverride).forEach(([key, value]) => cfnLb.addPropertyOverride(key, value));
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
exports.GuClassicLoadBalancer = GuClassicLoadBalancer;
|
|
47
|
-
GuClassicLoadBalancer.DefaultHealthCheck = {
|
|
48
|
-
port: 9000,
|
|
49
|
-
path: "/healthcheck",
|
|
50
|
-
protocol: aws_elasticloadbalancing_1.LoadBalancingProtocol.HTTP,
|
|
51
|
-
healthyThreshold: 2,
|
|
52
|
-
unhealthyThreshold: 5,
|
|
53
|
-
interval: aws_cdk_lib_1.Duration.seconds(30),
|
|
54
|
-
timeout: aws_cdk_lib_1.Duration.seconds(10),
|
|
55
|
-
};
|
|
56
|
-
/**
|
|
57
|
-
* **IMPORTANT**: This construct should **only** be used if you are migrating an existing stack and you need to retain the load balancer.
|
|
58
|
-
* Please use [[`GuHttpsApplicationListener`]] instead of [[`GuHttpsClassicLoadBalancer`]] wherever possible.
|
|
59
|
-
*
|
|
60
|
-
* This construct creates a classic load balancer which accepts HTTPS traffic. It communicates with EC2 instances over port 9000
|
|
61
|
-
* by default. This default can be overridden via the listener prop, for example:
|
|
62
|
-
* ```typescript
|
|
63
|
-
* new GuHttpsClassicLoadBalancer(stack, "HttpsClassicLoadBalancer", {
|
|
64
|
-
* // other props
|
|
65
|
-
* listener: {
|
|
66
|
-
* internalPort: 3000,
|
|
67
|
-
* },
|
|
68
|
-
* });
|
|
69
|
-
* ```
|
|
70
|
-
*
|
|
71
|
-
* You can pass a certificate id to this construct via the listener interface, for example:
|
|
72
|
-
* ```typescript
|
|
73
|
-
* new GuHttpsClassicLoadBalancer(stack, "HttpsClassicLoadBalancer", {
|
|
74
|
-
* // other props
|
|
75
|
-
* listener: {
|
|
76
|
-
* sslCertificateId: "certificateId",
|
|
77
|
-
* },
|
|
78
|
-
* });
|
|
79
|
-
* ```
|
|
80
|
-
* If certificate id is omitted the library will create a Parameter which allows you to pass in a certificate ARN.
|
|
81
|
-
*
|
|
82
|
-
* For more details on migrating an existing load balancer and general load balancer defaults, see [[`GuClassicLoadBalancer`]].
|
|
83
|
-
*/
|
|
84
|
-
class GuHttpsClassicLoadBalancer extends GuClassicLoadBalancer {
|
|
85
|
-
constructor(scope, id, props) {
|
|
86
|
-
const listenerProps = { ...GuHttpsClassicLoadBalancer.DefaultListener, ...props.listener };
|
|
87
|
-
const mergedProps = {
|
|
88
|
-
...props,
|
|
89
|
-
listeners: [
|
|
90
|
-
{
|
|
91
|
-
...listenerProps,
|
|
92
|
-
sslCertificateArn: listenerProps.sslCertificateArn ??
|
|
93
|
-
new core_1.GuArnParameter(scope, "CertificateARN", {
|
|
94
|
-
description: "Certificate ARN for ELB",
|
|
95
|
-
}).valueAsString,
|
|
96
|
-
},
|
|
97
|
-
],
|
|
98
|
-
};
|
|
99
|
-
super(scope, id, mergedProps);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
exports.GuHttpsClassicLoadBalancer = GuHttpsClassicLoadBalancer;
|
|
103
|
-
GuHttpsClassicLoadBalancer.DefaultListener = {
|
|
104
|
-
internalPort: 9000,
|
|
105
|
-
externalPort: 443,
|
|
106
|
-
internalProtocol: aws_elasticloadbalancing_1.LoadBalancingProtocol.HTTP,
|
|
107
|
-
externalProtocol: aws_elasticloadbalancing_1.LoadBalancingProtocol.HTTPS,
|
|
108
|
-
};
|
|
109
|
-
//# sourceMappingURL=elb.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"elb.js","sourceRoot":"","sources":["../../../src/constructs/loadbalancing/elb.ts"],"names":[],"mappings":";;;AAAA,6CAAuC;AACvC,mFAA2F;AAO3F,+EAA4E;AAC5E,kCAAyC;AAczC;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAa,qBAAsB,SAAQ,IAAA,yCAAmB,EAAC,uCAAY,CAAC;IAW1E,YAAY,KAAc,EAAE,EAAU,EAAE,KAAiC;QACvE,MAAM,WAAW,GAAG;YAClB,GAAG,KAAK;YACR,WAAW,EAAE,EAAE,GAAG,qBAAqB,CAAC,kBAAkB,EAAE,GAAG,KAAK,CAAC,WAAW,EAAE;SACnF,CAAC;QAEF,KAAK,CAAC,KAAK,EAAE,EAAE,EAAE,WAAW,CAAC,CAAC;QAE9B,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,YAA+B,CAAC;QAExD,IAAI,KAAK,CAAC,YAAY,EAAE;YACtB,KAAK,CAAC,2BAA2B,CAAC,QAAQ,CAAC,CAAC;SAC7C;QAED,WAAW,CAAC,oBAAoB;YAC9B,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,oBAAoB,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,mBAAmB,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC;IACtH,CAAC;;AA3BH,sDA4BC;AA3BQ,wCAAkB,GAAG;IAC1B,IAAI,EAAE,IAAI;IACV,IAAI,EAAE,cAAc;IACpB,QAAQ,EAAE,gDAAqB,CAAC,IAAI;IACpC,gBAAgB,EAAE,CAAC;IACnB,kBAAkB,EAAE,CAAC;IACrB,QAAQ,EAAE,sBAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;IAC9B,OAAO,EAAE,sBAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;CAC9B,CAAC;AAyBJ;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAa,0BAA2B,SAAQ,qBAAqB;IAQnE,YAAY,KAAc,EAAE,EAAU,EAAE,KAAsC;QAC5E,MAAM,aAAa,GAAyB,EAAE,GAAG,0BAA0B,CAAC,eAAe,EAAE,GAAG,KAAK,CAAC,QAAQ,EAAE,CAAC;QAEjH,MAAM,WAAW,GAA+B;YAC9C,GAAG,KAAK;YACR,SAAS,EAAE;gBACT;oBACE,GAAG,aAAa;oBAChB,iBAAiB,EACf,aAAa,CAAC,iBAAiB;wBAC/B,IAAI,qBAAc,CAAC,KAAK,EAAE,gBAAgB,EAAE;4BAC1C,WAAW,EAAE,yBAAyB;yBACvC,CAAC,CAAC,aAAa;iBACnB;aACF;SACF,CAAC;QAEF,KAAK,CAAC,KAAK,EAAE,EAAE,EAAE,WAAW,CAAC,CAAC;IAChC,CAAC;;AA1BH,gEA2BC;AA1BQ,0CAAe,GAAyB;IAC7C,YAAY,EAAE,IAAI;IAClB,YAAY,EAAE,GAAG;IACjB,gBAAgB,EAAE,gDAAqB,CAAC,IAAI;IAC5C,gBAAgB,EAAE,gDAAqB,CAAC,KAAK;CAC9C,CAAC","sourcesContent":["import { Duration } from \"aws-cdk-lib\";\nimport { LoadBalancer, LoadBalancingProtocol } from \"aws-cdk-lib/aws-elasticloadbalancing\";\nimport type {\n CfnLoadBalancer,\n HealthCheck,\n LoadBalancerListener,\n LoadBalancerProps,\n} from \"aws-cdk-lib/aws-elasticloadbalancing\";\nimport { GuAppAwareConstruct } from \"../../utils/mixin/app-aware-construct\";\nimport { GuArnParameter } from \"../core\";\nimport type { AppIdentity, GuStack } from \"../core\";\n\ninterface GuClassicLoadBalancerProps extends Omit<LoadBalancerProps, \"healthCheck\">, AppIdentity {\n propertiesToOverride?: Record<string, unknown>;\n healthCheck?: Partial<HealthCheck>;\n /**\n * If your CloudFormation does not define the Scheme of your Load Balancer, you must set this boolean to true to avoid\n * resource [replacement](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-elb.html#cfn-ec2-elb-scheme).\n * If a Load Balancer is replaced it is likely to lead to downtime.\n */\n removeScheme?: boolean;\n}\n\n/**\n * **IMPORTANT**: This construct should **only** be used if you are migrating an existing stack and you need to retain the load balancer.\n * Please use [[`GuApplicationLoadBalancer`]] instead of [[`GuClassicLoadBalancer`]] wherever possible.\n *\n * By default, load balancers created via this construct will perform a healthcheck against `/healthcheck` on port 9000. All healthcheck\n * defaults can be overridden via the `healthcheck` prop.\n *\n * For example, to use `/test` for the healthcheck path use:\n *\n * ```typescript\n * new GuClassicLoadBalancer(stack, \"ClassicLoadBalancer\", {\n * // other props\n * healthCheck: {\n * path: \"/test\",\n * },\n * });\n * ```\n * If you are running an application which only accepts traffic over HTTPs, consider using [[`GuHttpsClassicLoadBalancer`]]\n * to reduce the amount of boilerplate needed when configuring your load balancer.\n *\n * This resource is stateful.\n * @see https://github.com/guardian/cdk/blob/main/docs/stateful-resources.md\n */\nexport class GuClassicLoadBalancer extends GuAppAwareConstruct(LoadBalancer) {\n static DefaultHealthCheck = {\n port: 9000,\n path: \"/healthcheck\",\n protocol: LoadBalancingProtocol.HTTP,\n healthyThreshold: 2,\n unhealthyThreshold: 5,\n interval: Duration.seconds(30),\n timeout: Duration.seconds(10),\n };\n\n constructor(scope: GuStack, id: string, props: GuClassicLoadBalancerProps) {\n const mergedProps = {\n ...props,\n healthCheck: { ...GuClassicLoadBalancer.DefaultHealthCheck, ...props.healthCheck },\n };\n\n super(scope, id, mergedProps);\n\n const cfnLb = this.node.defaultChild as CfnLoadBalancer;\n\n if (props.removeScheme) {\n cfnLb.addPropertyDeletionOverride(\"Scheme\");\n }\n\n mergedProps.propertiesToOverride &&\n Object.entries(mergedProps.propertiesToOverride).forEach(([key, value]) => cfnLb.addPropertyOverride(key, value));\n }\n}\n\ninterface GuHttpsClassicLoadBalancerProps extends Omit<GuClassicLoadBalancerProps, \"listeners\"> {\n listener?: Partial<LoadBalancerListener>;\n}\n\n/**\n * **IMPORTANT**: This construct should **only** be used if you are migrating an existing stack and you need to retain the load balancer.\n * Please use [[`GuHttpsApplicationListener`]] instead of [[`GuHttpsClassicLoadBalancer`]] wherever possible.\n *\n * This construct creates a classic load balancer which accepts HTTPS traffic. It communicates with EC2 instances over port 9000\n * by default. This default can be overridden via the listener prop, for example:\n * ```typescript\n * new GuHttpsClassicLoadBalancer(stack, \"HttpsClassicLoadBalancer\", {\n * // other props\n * listener: {\n * internalPort: 3000,\n * },\n * });\n * ```\n *\n * You can pass a certificate id to this construct via the listener interface, for example:\n * ```typescript\n * new GuHttpsClassicLoadBalancer(stack, \"HttpsClassicLoadBalancer\", {\n * // other props\n * listener: {\n * sslCertificateId: \"certificateId\",\n * },\n * });\n * ```\n * If certificate id is omitted the library will create a Parameter which allows you to pass in a certificate ARN.\n *\n * For more details on migrating an existing load balancer and general load balancer defaults, see [[`GuClassicLoadBalancer`]].\n */\nexport class GuHttpsClassicLoadBalancer extends GuClassicLoadBalancer {\n static DefaultListener: LoadBalancerListener = {\n internalPort: 9000,\n externalPort: 443,\n internalProtocol: LoadBalancingProtocol.HTTP,\n externalProtocol: LoadBalancingProtocol.HTTPS,\n };\n\n constructor(scope: GuStack, id: string, props: GuHttpsClassicLoadBalancerProps) {\n const listenerProps: LoadBalancerListener = { ...GuHttpsClassicLoadBalancer.DefaultListener, ...props.listener };\n\n const mergedProps: GuClassicLoadBalancerProps = {\n ...props,\n listeners: [\n {\n ...listenerProps,\n sslCertificateArn:\n listenerProps.sslCertificateArn ??\n new GuArnParameter(scope, \"CertificateARN\", {\n description: \"Certificate ARN for ELB\",\n }).valueAsString,\n },\n ],\n };\n\n super(scope, id, mergedProps);\n }\n}\n"]}
|