@composurecdk/ec2 0.8.4 → 0.8.6

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.
Files changed (50) hide show
  1. package/README.md +200 -0
  2. package/dist/commonjs/index.d.ts +4 -0
  3. package/dist/commonjs/index.d.ts.map +1 -1
  4. package/dist/commonjs/index.js +7 -1
  5. package/dist/commonjs/index.js.map +1 -1
  6. package/dist/commonjs/interface-endpoint-alarm-config.d.ts +34 -0
  7. package/dist/commonjs/interface-endpoint-alarm-config.d.ts.map +1 -0
  8. package/dist/commonjs/interface-endpoint-alarm-config.js +3 -0
  9. package/dist/commonjs/interface-endpoint-alarm-config.js.map +1 -0
  10. package/dist/commonjs/interface-endpoint-alarm-defaults.d.ts +13 -0
  11. package/dist/commonjs/interface-endpoint-alarm-defaults.d.ts.map +1 -0
  12. package/dist/commonjs/interface-endpoint-alarm-defaults.js +28 -0
  13. package/dist/commonjs/interface-endpoint-alarm-defaults.js.map +1 -0
  14. package/dist/commonjs/interface-endpoint-alarms.d.ts +13 -0
  15. package/dist/commonjs/interface-endpoint-alarms.d.ts.map +1 -0
  16. package/dist/commonjs/interface-endpoint-alarms.js +58 -0
  17. package/dist/commonjs/interface-endpoint-alarms.js.map +1 -0
  18. package/dist/commonjs/interface-endpoint-builder.d.ts +135 -0
  19. package/dist/commonjs/interface-endpoint-builder.d.ts.map +1 -0
  20. package/dist/commonjs/interface-endpoint-builder.js +126 -0
  21. package/dist/commonjs/interface-endpoint-builder.js.map +1 -0
  22. package/dist/commonjs/interface-endpoint-defaults.d.ts +14 -0
  23. package/dist/commonjs/interface-endpoint-defaults.d.ts.map +1 -0
  24. package/dist/commonjs/interface-endpoint-defaults.js +27 -0
  25. package/dist/commonjs/interface-endpoint-defaults.js.map +1 -0
  26. package/dist/esm/index.d.ts +4 -0
  27. package/dist/esm/index.d.ts.map +1 -1
  28. package/dist/esm/index.js +3 -0
  29. package/dist/esm/index.js.map +1 -1
  30. package/dist/esm/interface-endpoint-alarm-config.d.ts +34 -0
  31. package/dist/esm/interface-endpoint-alarm-config.d.ts.map +1 -0
  32. package/dist/esm/interface-endpoint-alarm-config.js +2 -0
  33. package/dist/esm/interface-endpoint-alarm-config.js.map +1 -0
  34. package/dist/esm/interface-endpoint-alarm-defaults.d.ts +13 -0
  35. package/dist/esm/interface-endpoint-alarm-defaults.d.ts.map +1 -0
  36. package/dist/esm/interface-endpoint-alarm-defaults.js +25 -0
  37. package/dist/esm/interface-endpoint-alarm-defaults.js.map +1 -0
  38. package/dist/esm/interface-endpoint-alarms.d.ts +13 -0
  39. package/dist/esm/interface-endpoint-alarms.d.ts.map +1 -0
  40. package/dist/esm/interface-endpoint-alarms.js +55 -0
  41. package/dist/esm/interface-endpoint-alarms.js.map +1 -0
  42. package/dist/esm/interface-endpoint-builder.d.ts +135 -0
  43. package/dist/esm/interface-endpoint-builder.d.ts.map +1 -0
  44. package/dist/esm/interface-endpoint-builder.js +123 -0
  45. package/dist/esm/interface-endpoint-builder.js.map +1 -0
  46. package/dist/esm/interface-endpoint-defaults.d.ts +14 -0
  47. package/dist/esm/interface-endpoint-defaults.d.ts.map +1 -0
  48. package/dist/esm/interface-endpoint-defaults.js +24 -0
  49. package/dist/esm/interface-endpoint-defaults.js.map +1 -0
  50. package/package.json +16 -5
@@ -0,0 +1,123 @@
1
+ import { InterfaceVpcEndpoint, } from "aws-cdk-lib/aws-ec2";
2
+ import { COPY_STATE, resolve } from "@composurecdk/core";
3
+ import { taggedBuilder } from "@composurecdk/cloudformation";
4
+ import { AlarmDefinitionBuilder } from "@composurecdk/cloudwatch";
5
+ import { createSecurityGroupBuilder } from "./security-group-builder.js";
6
+ import { INTERFACE_ENDPOINT_DEFAULTS } from "./interface-endpoint-defaults.js";
7
+ import { createInterfaceEndpointAlarms } from "./interface-endpoint-alarms.js";
8
+ class InterfaceEndpointBuilder {
9
+ props = {};
10
+ #access = [];
11
+ #customAlarms = [];
12
+ #vpc;
13
+ #securityGroups;
14
+ /**
15
+ * Sets the VPC the endpoint is created in. Accepts a concrete {@link IVpc}
16
+ * or a {@link Ref} to a sibling {@link IVpcBuilder}.
17
+ */
18
+ vpc(vpc) {
19
+ this.#vpc = vpc;
20
+ return this;
21
+ }
22
+ /**
23
+ * Bring-your-own security groups. Each entry is a {@link Resolvable}, so it
24
+ * can be a concrete {@link ISecurityGroup} or a {@link Ref} to a sibling
25
+ * `SecurityGroupBuilder` — giving you full ingress/egress/port control. When
26
+ * set, the builder creates no security group of its own and
27
+ * {@link InterfaceEndpointBuilderResult.securityGroup} is `undefined`.
28
+ *
29
+ * Mutually exclusive with {@link allowDefaultPortFrom}.
30
+ */
31
+ securityGroups(securityGroups) {
32
+ this.#securityGroups = securityGroups;
33
+ return this;
34
+ }
35
+ /**
36
+ * Managed-SG shortcut: wires `peer` to the auto-created security group via
37
+ * CDK's `endpoint.connections.allowDefaultPortFrom(peer)` — opening ingress
38
+ * on the managed SG from `peer`'s SG **and** egress from `peer`'s SG to the
39
+ * managed SG, on the service's default port (443 for AWS services).
40
+ *
41
+ * Because this delegates to CDK connections, `peer` must be an
42
+ * {@link IConnectable} (e.g. a `SecurityGroup` or `Instance`), not a raw
43
+ * `IPeer` (e.g. `Peer.ipv4(...)`). For CIDR-based rules use BYO mode with
44
+ * an explicit `addIngressRule` on your own {@link SecurityGroupBuilder}.
45
+ *
46
+ * Mutually exclusive with {@link securityGroups}.
47
+ */
48
+ allowDefaultPortFrom(peer, description) {
49
+ this.#access.push({ peer, description });
50
+ return this;
51
+ }
52
+ /**
53
+ * Adds a custom CloudWatch alarm alongside the recommended ones. The
54
+ * callback receives an {@link AlarmDefinitionBuilder} typed to the
55
+ * `InterfaceVpcEndpoint` construct, giving access to the endpoint at
56
+ * build time for metric dimension wiring.
57
+ */
58
+ addAlarm(key, configure) {
59
+ this.#customAlarms.push(configure(new AlarmDefinitionBuilder(key)));
60
+ return this;
61
+ }
62
+ /** @internal — see ADR-0005. */
63
+ [COPY_STATE](target) {
64
+ target.#vpc = this.#vpc;
65
+ target.#securityGroups = this.#securityGroups ? [...this.#securityGroups] : undefined;
66
+ target.#access.push(...this.#access);
67
+ target.#customAlarms.push(...this.#customAlarms);
68
+ }
69
+ build(scope, id, context) {
70
+ const resolvedVpc = this.#vpc ? resolve(this.#vpc, context) : undefined;
71
+ if (!resolvedVpc) {
72
+ throw new Error(`InterfaceEndpointBuilder "${id}" requires a VPC. Call .vpc() with an IVpc or a Ref to one.`);
73
+ }
74
+ const { recommendedAlarms: alarmConfig, service, ...endpointProps } = this.props;
75
+ if (service === undefined) {
76
+ throw new Error(`InterfaceEndpointBuilder "${id}" requires a service. ` +
77
+ "Call .service() with an InterfaceVpcEndpointAwsService or a custom IInterfaceVpcEndpointService.");
78
+ }
79
+ const byo = this.#securityGroups;
80
+ if (byo !== undefined && this.#access.length > 0) {
81
+ throw new Error(`InterfaceEndpointBuilder "${id}": .allowDefaultPortFrom() applies only to the ` +
82
+ "auto-created security group and cannot be combined with .securityGroups() — " +
83
+ "add the ingress rule to your own SecurityGroupBuilder instead.");
84
+ }
85
+ let managedSecurityGroup;
86
+ let securityGroups;
87
+ if (byo !== undefined) {
88
+ securityGroups = byo.map((sg) => resolve(sg, context));
89
+ }
90
+ else {
91
+ managedSecurityGroup = createSecurityGroupBuilder()
92
+ .vpc(resolvedVpc)
93
+ .description(`Interface endpoint ${id}`)
94
+ .build(scope, `${id}Sg`).securityGroup;
95
+ securityGroups = [managedSecurityGroup];
96
+ }
97
+ const endpoint = new InterfaceVpcEndpoint(scope, id, {
98
+ ...INTERFACE_ENDPOINT_DEFAULTS,
99
+ ...endpointProps,
100
+ service,
101
+ vpc: resolvedVpc,
102
+ securityGroups,
103
+ // Always explicit: `open: true` would silently add a VPC-wide :443 rule.
104
+ open: false,
105
+ });
106
+ for (const rule of this.#access) {
107
+ endpoint.connections.allowDefaultPortFrom(resolve(rule.peer, context), rule.description);
108
+ }
109
+ const alarms = createInterfaceEndpointAlarms(scope, id, endpoint, alarmConfig, this.#customAlarms);
110
+ return { endpoint, securityGroup: managedSecurityGroup, alarms };
111
+ }
112
+ }
113
+ /**
114
+ * Creates a new {@link IInterfaceEndpointBuilder} for a single VPC interface
115
+ * endpoint. The returned builder exposes every
116
+ * {@link InterfaceEndpointBuilderProps} property as a fluent setter/getter,
117
+ * plus `.vpc()`, `.securityGroups()` (BYO), and `.allowDefaultPortFrom()`
118
+ * (managed-SG shortcut).
119
+ */
120
+ export function createInterfaceEndpointBuilder() {
121
+ return taggedBuilder(InterfaceEndpointBuilder);
122
+ }
123
+ //# sourceMappingURL=interface-endpoint-builder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interface-endpoint-builder.js","sourceRoot":"","sources":["../../src/interface-endpoint-builder.ts"],"names":[],"mappings":"AACA,OAAO,EACL,oBAAoB,GAMrB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,UAAU,EAAkB,OAAO,EAAmB,MAAM,oBAAoB,CAAC;AAC1F,OAAO,EAAuB,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAClF,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,0BAA0B,EAAE,MAAM,6BAA6B,CAAC;AACzE,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAE/E,OAAO,EAAE,6BAA6B,EAAE,MAAM,gCAAgC,CAAC;AA2F/E,MAAM,wBAAwB;IAC5B,KAAK,GAA2C,EAAE,CAAC;IAC1C,OAAO,GAAiB,EAAE,CAAC;IAC3B,aAAa,GAAmD,EAAE,CAAC;IAC5E,IAAI,CAAoB;IACxB,eAAe,CAAgC;IAE/C;;;OAGG;IACH,GAAG,CAAC,GAAqB;QACvB,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC;QAChB,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;;;;OAQG;IACH,cAAc,CAAC,cAA4C;QACzD,IAAI,CAAC,eAAe,GAAG,cAAc,CAAC;QACtC,OAA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C,CAAC;QAC3F,CAAC;QAED,MAAM,MAAM,GAAG,6BAA6B,CAC1C,KAAK,EACL,EAAE,EACF,QAAQ,EACR,WAAW,EACX,IAAI,CAAC,aAAa,CACnB,CAAC;QAEF,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,EAAE,CAAC;IACnE,CAAC;CACF;AAED;;;;;;GAMG;AACH,MAAM,UAAU,8BAA8B;IAC5C,OAAO,aAAa,CAClB,wBAAwB,CACzB,CAAC;AACJ,CAAC"}
@@ -0,0 +1,14 @@
1
+ import type { InterfaceVpcEndpointProps } from "aws-cdk-lib/aws-ec2";
2
+ /**
3
+ * Secure, AWS-recommended defaults applied to every interface endpoint built
4
+ * with {@link createInterfaceEndpointBuilder}. Each property can be
5
+ * individually overridden via the builder's fluent API.
6
+ *
7
+ * Note `open` is intentionally *not* here: the builder always sets it to
8
+ * `false` (see the builder's `build()`). Allowing it through would silently
9
+ * add a VPC-wide rule to the managed security group behind the caller's back;
10
+ * ingress is always explicit — via `.allowDefaultPortFrom()` (managed SG) or
11
+ * the BYO `SecurityGroupBuilder`.
12
+ */
13
+ export declare const INTERFACE_ENDPOINT_DEFAULTS: Partial<InterfaceVpcEndpointProps>;
14
+ //# sourceMappingURL=interface-endpoint-defaults.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interface-endpoint-defaults.d.ts","sourceRoot":"","sources":["../../src/interface-endpoint-defaults.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAErE;;;;;;;;;;GAUG;AACH,eAAO,MAAM,2BAA2B,EAAE,OAAO,CAAC,yBAAyB,CAW1E,CAAC"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Secure, AWS-recommended defaults applied to every interface endpoint built
3
+ * with {@link createInterfaceEndpointBuilder}. Each property can be
4
+ * individually overridden via the builder's fluent API.
5
+ *
6
+ * Note `open` is intentionally *not* here: the builder always sets it to
7
+ * `false` (see the builder's `build()`). Allowing it through would silently
8
+ * add a VPC-wide rule to the managed security group behind the caller's back;
9
+ * ingress is always explicit — via `.allowDefaultPortFrom()` (managed SG) or
10
+ * the BYO `SecurityGroupBuilder`.
11
+ */
12
+ export const INTERFACE_ENDPOINT_DEFAULTS = {
13
+ /**
14
+ * Private DNS enables `<service>.<region>.amazonaws.com` to resolve to the
15
+ * endpoint ENIs instead of the public service IP addresses, keeping traffic
16
+ * on the AWS network without requiring application-level changes. Disabled
17
+ * by default in raw CDK; always on here because every AWS-service use case
18
+ * requires it for transparent private access.
19
+ *
20
+ * @see https://docs.aws.amazon.com/wellarchitected/latest/security-pillar/sec_network_protection_private_connectivity.html
21
+ */
22
+ privateDnsEnabled: true,
23
+ };
24
+ //# sourceMappingURL=interface-endpoint-defaults.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interface-endpoint-defaults.js","sourceRoot":"","sources":["../../src/interface-endpoint-defaults.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAuC;IAC7E;;;;;;;;OAQG;IACH,iBAAiB,EAAE,IAAI;CACxB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@composurecdk/ec2",
3
- "version": "0.8.4",
3
+ "version": "0.8.6",
4
4
  "description": "Composable EC2 instance and VPC builders with well-architected defaults",
5
5
  "repository": {
6
6
  "type": "git",
@@ -20,7 +20,18 @@
20
20
  "test": "vitest run --passWithNoTests",
21
21
  "test:watch": "vitest"
22
22
  },
23
- "keywords": [],
23
+ "keywords": [
24
+ "aws",
25
+ "cdk",
26
+ "aws-cdk",
27
+ "infrastructure-as-code",
28
+ "iac",
29
+ "composurecdk",
30
+ "ec2",
31
+ "vpc",
32
+ "networking",
33
+ "compute"
34
+ ],
24
35
  "author": "Jason Duffett (https://github.com/laazyj)",
25
36
  "license": "MIT",
26
37
  "publishConfig": {
@@ -45,11 +56,11 @@
45
56
  "constructs": "^10.0.0"
46
57
  },
47
58
  "devDependencies": {
48
- "@types/node": "^25.9.1",
49
- "aws-cdk-lib": "^2.257.0",
59
+ "@types/node": "^25.9.3",
60
+ "aws-cdk-lib": "^2.258.1",
50
61
  "constructs": "^10.6.0",
51
62
  "typescript": "^6.0.2",
52
- "vitest": "^4.1.7"
63
+ "vitest": "^4.1.8"
53
64
  },
54
65
  "exports": {
55
66
  "./package.json": "./package.json",