@gradientedge/cdk-utils 8.149.0 → 8.150.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.
Files changed (21) hide show
  1. package/dist/src/lib/aws/construct/graphql-api-lambda-with-cache/main.js +6 -0
  2. package/dist/src/lib/aws/construct/graphql-api-lambda-with-cache/types.d.ts +1 -2
  3. package/dist/src/lib/aws/construct/rest-api-lambda-with-cache/main.js +6 -1
  4. package/dist/src/lib/aws/construct/rest-api-lambda-with-cache/types.d.ts +1 -2
  5. package/dist/src/lib/aws/services/virtual-private-cloud/index.d.ts +1 -0
  6. package/dist/src/lib/aws/services/virtual-private-cloud/index.js +1 -0
  7. package/dist/src/lib/aws/services/virtual-private-cloud/ipv6.d.ts +7 -0
  8. package/dist/src/lib/aws/services/virtual-private-cloud/ipv6.js +42 -0
  9. package/dist/src/lib/aws/services/virtual-private-cloud/main.d.ts +2 -1
  10. package/dist/src/lib/aws/services/virtual-private-cloud/main.js +15 -4
  11. package/dist/src/lib/aws/services/virtual-private-cloud/types.d.ts +4 -0
  12. package/dist/src/lib/aws/services/virtual-private-cloud/types.js +2 -0
  13. package/package.json +1 -1
  14. package/src/lib/aws/construct/graphql-api-lambda-with-cache/main.ts +5 -0
  15. package/src/lib/aws/construct/graphql-api-lambda-with-cache/types.ts +1 -2
  16. package/src/lib/aws/construct/rest-api-lambda-with-cache/main.ts +5 -1
  17. package/src/lib/aws/construct/rest-api-lambda-with-cache/types.ts +1 -2
  18. package/src/lib/aws/services/virtual-private-cloud/index.ts +1 -0
  19. package/src/lib/aws/services/virtual-private-cloud/ipv6.ts +58 -0
  20. package/src/lib/aws/services/virtual-private-cloud/main.ts +17 -5
  21. package/src/lib/aws/services/virtual-private-cloud/types.ts +5 -0
@@ -95,6 +95,12 @@ class GraphQLApiLambdaWithCache extends __1.GraphQLApiLambda {
95
95
  vpc: this.graphQLVpc,
96
96
  });
97
97
  this.graphQLSecurityGroup.addIngressRule(aws_ec2_1.Peer.anyIpv4(), aws_ec2_1.Port.allTraffic(), 'All Traffic');
98
+ if (this.props.graphQLVpc.isIPV6) {
99
+ this.graphQLSecurityGroup.addIngressRule(aws_ec2_1.Peer.anyIpv6(), aws_ec2_1.Port.allTraffic(), 'All Traffic');
100
+ }
101
+ else {
102
+ this.graphQLSecurityGroup.addIngressRule(aws_ec2_1.Peer.anyIpv4(), aws_ec2_1.Port.allTraffic(), 'All Traffic');
103
+ }
98
104
  utils.createCfnOutput(`${this.id}-security-group-id`, this, this.graphQLSecurityGroup.securityGroupId);
99
105
  }
100
106
  }
@@ -1,6 +1,5 @@
1
+ import { ReplicatedElastiCacheProps, VpcProps } from '../../services';
1
2
  import { GraphQlApiLambdaProps } from '../graphql-api-lambda';
2
- import { VpcProps } from 'aws-cdk-lib/aws-ec2';
3
- import { ReplicatedElastiCacheProps } from '../../services';
4
3
  /**
5
4
  * @deprecated Use RestApiLambdaWithCacheProps instead. This will be removed in a future release.
6
5
  */
@@ -70,7 +70,12 @@ class RestApiLambdaWithCache extends __1.RestApiLambda {
70
70
  securityGroupName: `${this.id}-security-group-${this.props.stage}`,
71
71
  vpc: this.restApivpc,
72
72
  });
73
- this.restApiSecurityGroup.addIngressRule(aws_ec2_1.Peer.anyIpv4(), aws_ec2_1.Port.allTraffic(), 'All Traffic');
73
+ if (this.props.restApiVpc.isIPV6) {
74
+ this.restApiSecurityGroup.addIngressRule(aws_ec2_1.Peer.anyIpv6(), aws_ec2_1.Port.allTraffic(), 'All Traffic');
75
+ }
76
+ else {
77
+ this.restApiSecurityGroup.addIngressRule(aws_ec2_1.Peer.anyIpv4(), aws_ec2_1.Port.allTraffic(), 'All Traffic');
78
+ }
74
79
  (0, utils_1.createCfnOutput)(`${this.id}-security-group-id`, this, this.restApiSecurityGroup.securityGroupId);
75
80
  }
76
81
  }
@@ -1,6 +1,5 @@
1
1
  import { RestApiLambdaProps } from '../rest-api-lambda';
2
- import { VpcProps } from 'aws-cdk-lib/aws-ec2';
3
- import { ReplicatedElastiCacheProps } from '../../services';
2
+ import { ReplicatedElastiCacheProps, VpcProps } from '../../services';
4
3
  /**
5
4
  */
6
5
  export interface RestApiLambdaWithCacheProps extends RestApiLambdaProps {
@@ -1 +1,2 @@
1
1
  export * from './main';
2
+ export * from './types';
@@ -15,3 +15,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./main"), exports);
18
+ __exportStar(require("./types"), exports);
@@ -0,0 +1,7 @@
1
+ import { Vpc } from 'aws-cdk-lib/aws-ec2';
2
+ import { CommonConstruct } from '../../common';
3
+ import { VpcProps } from './types';
4
+ export declare class Ipv6Vpc extends Vpc {
5
+ egressOnlyInternetGatewayId: string;
6
+ constructor(scope: CommonConstruct, id: string, props: VpcProps);
7
+ }
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Ipv6Vpc = void 0;
7
+ const aws_cdk_lib_1 = require("aws-cdk-lib");
8
+ const aws_ec2_1 = require("aws-cdk-lib/aws-ec2");
9
+ const lodash_1 = __importDefault(require("lodash"));
10
+ class Ipv6Vpc extends aws_ec2_1.Vpc {
11
+ egressOnlyInternetGatewayId;
12
+ constructor(scope, id, props) {
13
+ super(scope, id, props);
14
+ const cfnVpcCidrBlock = new aws_ec2_1.CfnVPCCidrBlock(this, `${id}-ipv6-cidr`, {
15
+ amazonProvidedIpv6CidrBlock: true,
16
+ vpcId: this.vpcId,
17
+ });
18
+ const subnetIpv6CidrBlocks = aws_cdk_lib_1.Fn.cidr(aws_cdk_lib_1.Fn.select(0, this.vpcIpv6CidrBlocks), 256, '64');
19
+ lodash_1.default.forEach([...this.publicSubnets, ...this.privateSubnets, ...this.isolatedSubnets], (subnet, index) => {
20
+ subnet.node.addDependency(cfnVpcCidrBlock);
21
+ const cfnSubnet = subnet.node.defaultChild;
22
+ cfnSubnet.ipv6CidrBlock = aws_cdk_lib_1.Fn.select(index, subnetIpv6CidrBlocks);
23
+ cfnSubnet.assignIpv6AddressOnCreation = true;
24
+ });
25
+ const addDefaultIpv6Routes = (subnets, gatewayId, routerType) => subnets.forEach(subnet => subnet.addRoute(`${id}-default-route`, {
26
+ destinationIpv6CidrBlock: '::/0',
27
+ enablesInternetConnectivity: true,
28
+ routerId: gatewayId,
29
+ routerType: routerType,
30
+ }));
31
+ if (this.internetGatewayId) {
32
+ addDefaultIpv6Routes(this.publicSubnets, this.internetGatewayId, aws_ec2_1.RouterType.GATEWAY);
33
+ }
34
+ if (lodash_1.default.isEmpty(this.privateSubnets)) {
35
+ return;
36
+ }
37
+ const egressIgw = new aws_ec2_1.CfnEgressOnlyInternetGateway(this, `${id}-eigw`, { vpcId: this.vpcId });
38
+ this.egressOnlyInternetGatewayId = egressIgw.ref;
39
+ addDefaultIpv6Routes(this.privateSubnets, egressIgw.ref, aws_ec2_1.RouterType.EGRESS_ONLY_INTERNET_GATEWAY);
40
+ }
41
+ }
42
+ exports.Ipv6Vpc = Ipv6Vpc;
@@ -1,5 +1,6 @@
1
- import { Vpc, VpcProps } from 'aws-cdk-lib/aws-ec2';
1
+ import { Vpc } from 'aws-cdk-lib/aws-ec2';
2
2
  import { CommonConstruct } from '../../common';
3
+ import { VpcProps } from './types';
3
4
  /**
4
5
  * @classdesc Provides operations on AWS VPC.
5
6
  * - A new instance of this class is injected into {@link CommonConstruct} constructor.
@@ -6,8 +6,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.VpcManager = void 0;
7
7
  const aws_cdk_lib_1 = require("aws-cdk-lib");
8
8
  const aws_ec2_1 = require("aws-cdk-lib/aws-ec2");
9
- const utils_1 = require("../../utils");
10
9
  const lodash_1 = __importDefault(require("lodash"));
10
+ const utils_1 = require("../../utils");
11
+ const ipv6_1 = require("./ipv6");
11
12
  /**
12
13
  */
13
14
  const CommonVpcIdentifier = 'CommonVpc';
@@ -37,9 +38,19 @@ class VpcManager {
37
38
  createVpc(id, scope, props) {
38
39
  if (!props)
39
40
  throw `Vpc props undefined for ${id}`;
40
- const vpc = new aws_ec2_1.Vpc(scope, `${id}`, {
41
- ...props,
42
- });
41
+ let vpc;
42
+ if (props.isIPV6) {
43
+ vpc = new ipv6_1.Ipv6Vpc(scope, `${id}`, {
44
+ ...props,
45
+ subnetConfiguration: [
46
+ { name: `${id}-public`, subnetType: aws_ec2_1.SubnetType.PUBLIC },
47
+ { name: `${id}-private`, subnetType: aws_ec2_1.SubnetType.PRIVATE_WITH_EGRESS },
48
+ ],
49
+ });
50
+ }
51
+ else {
52
+ vpc = new aws_ec2_1.Vpc(scope, `${id}`, props);
53
+ }
43
54
  (0, utils_1.createCfnOutput)(`${id}Id`, scope, vpc.vpcId);
44
55
  (0, utils_1.createCfnOutput)(`${id}PublicSubnetIds`, scope, lodash_1.default.map(vpc.publicSubnets, subnet => subnet.subnetId).toString());
45
56
  (0, utils_1.createCfnOutput)(`${id}PrivateSubnetIds`, scope, lodash_1.default.map(vpc.privateSubnets, subnet => subnet.subnetId).toString());
@@ -0,0 +1,4 @@
1
+ import * as ec2 from 'aws-cdk-lib/aws-ec2';
2
+ export interface VpcProps extends ec2.VpcProps {
3
+ isIPV6?: boolean;
4
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gradientedge/cdk-utils",
3
- "version": "8.149.0",
3
+ "version": "8.150.0",
4
4
  "description": "Utilities for AWS CDK provisioning",
5
5
  "main": "dist/index.js",
6
6
  "engines": {
@@ -79,6 +79,11 @@ export class GraphQLApiLambdaWithCache extends GraphQLApiLambda {
79
79
  })
80
80
 
81
81
  this.graphQLSecurityGroup.addIngressRule(Peer.anyIpv4(), Port.allTraffic(), 'All Traffic')
82
+ if (this.props.graphQLVpc.isIPV6) {
83
+ this.graphQLSecurityGroup.addIngressRule(Peer.anyIpv6(), Port.allTraffic(), 'All Traffic')
84
+ } else {
85
+ this.graphQLSecurityGroup.addIngressRule(Peer.anyIpv4(), Port.allTraffic(), 'All Traffic')
86
+ }
82
87
 
83
88
  utils.createCfnOutput(`${this.id}-security-group-id`, this, this.graphQLSecurityGroup.securityGroupId)
84
89
  }
@@ -1,6 +1,5 @@
1
+ import { ReplicatedElastiCacheProps, VpcProps } from '../../services'
1
2
  import { GraphQlApiLambdaProps } from '../graphql-api-lambda'
2
- import { VpcProps } from 'aws-cdk-lib/aws-ec2'
3
- import { ReplicatedElastiCacheProps } from '../../services'
4
3
 
5
4
  /**
6
5
  * @deprecated Use RestApiLambdaWithCacheProps instead. This will be removed in a future release.
@@ -77,7 +77,11 @@ export abstract class RestApiLambdaWithCache extends RestApiLambda {
77
77
  vpc: this.restApivpc,
78
78
  })
79
79
 
80
- this.restApiSecurityGroup.addIngressRule(Peer.anyIpv4(), Port.allTraffic(), 'All Traffic')
80
+ if (this.props.restApiVpc.isIPV6) {
81
+ this.restApiSecurityGroup.addIngressRule(Peer.anyIpv6(), Port.allTraffic(), 'All Traffic')
82
+ } else {
83
+ this.restApiSecurityGroup.addIngressRule(Peer.anyIpv4(), Port.allTraffic(), 'All Traffic')
84
+ }
81
85
 
82
86
  createCfnOutput(`${this.id}-security-group-id`, this, this.restApiSecurityGroup.securityGroupId)
83
87
  }
@@ -1,6 +1,5 @@
1
1
  import { RestApiLambdaProps } from '../rest-api-lambda'
2
- import { VpcProps } from 'aws-cdk-lib/aws-ec2'
3
- import { ReplicatedElastiCacheProps } from '../../services'
2
+ import { ReplicatedElastiCacheProps, VpcProps } from '../../services'
4
3
 
5
4
  /**
6
5
  */
@@ -1 +1,2 @@
1
1
  export * from './main'
2
+ export * from './types'
@@ -0,0 +1,58 @@
1
+ import { Fn } from 'aws-cdk-lib'
2
+ import {
3
+ CfnEgressOnlyInternetGateway,
4
+ CfnSubnet,
5
+ CfnVPCCidrBlock,
6
+ ISubnet,
7
+ RouterType,
8
+ Subnet,
9
+ Vpc,
10
+ } from 'aws-cdk-lib/aws-ec2'
11
+ import _ from 'lodash'
12
+ import { CommonConstruct } from '../../common'
13
+ import { VpcProps } from './types'
14
+
15
+ export class Ipv6Vpc extends Vpc {
16
+ public egressOnlyInternetGatewayId: string
17
+
18
+ constructor(scope: CommonConstruct, id: string, props: VpcProps) {
19
+ super(scope, id, props)
20
+
21
+ const cfnVpcCidrBlock = new CfnVPCCidrBlock(this, `${id}-ipv6-cidr`, {
22
+ amazonProvidedIpv6CidrBlock: true,
23
+ vpcId: this.vpcId,
24
+ })
25
+
26
+ const subnetIpv6CidrBlocks = Fn.cidr(Fn.select(0, this.vpcIpv6CidrBlocks), 256, '64')
27
+
28
+ _.forEach([...this.publicSubnets, ...this.privateSubnets, ...this.isolatedSubnets], (subnet, index) => {
29
+ subnet.node.addDependency(cfnVpcCidrBlock)
30
+ const cfnSubnet = subnet.node.defaultChild as CfnSubnet
31
+ cfnSubnet.ipv6CidrBlock = Fn.select(index, subnetIpv6CidrBlocks)
32
+ cfnSubnet.assignIpv6AddressOnCreation = true
33
+ })
34
+
35
+ const addDefaultIpv6Routes = (subnets: ISubnet[], gatewayId: string, routerType: RouterType) =>
36
+ subnets.forEach(subnet =>
37
+ (subnet as Subnet).addRoute(`${id}-default-route`, {
38
+ destinationIpv6CidrBlock: '::/0',
39
+ enablesInternetConnectivity: true,
40
+ routerId: gatewayId,
41
+ routerType: routerType,
42
+ })
43
+ )
44
+
45
+ if (this.internetGatewayId) {
46
+ addDefaultIpv6Routes(this.publicSubnets, this.internetGatewayId, RouterType.GATEWAY)
47
+ }
48
+
49
+ if (_.isEmpty(this.privateSubnets)) {
50
+ return
51
+ }
52
+
53
+ const egressIgw = new CfnEgressOnlyInternetGateway(this, `${id}-eigw`, { vpcId: this.vpcId })
54
+ this.egressOnlyInternetGatewayId = egressIgw.ref
55
+
56
+ addDefaultIpv6Routes(this.privateSubnets, egressIgw.ref, RouterType.EGRESS_ONLY_INTERNET_GATEWAY)
57
+ }
58
+ }
@@ -1,8 +1,10 @@
1
1
  import { Tags } from 'aws-cdk-lib'
2
- import { Vpc, VpcProps } from 'aws-cdk-lib/aws-ec2'
2
+ import { SubnetType, Vpc } from 'aws-cdk-lib/aws-ec2'
3
+ import _ from 'lodash'
3
4
  import { CommonConstruct } from '../../common'
4
5
  import { createCfnOutput } from '../../utils'
5
- import _ from 'lodash'
6
+ import { Ipv6Vpc } from './ipv6'
7
+ import { VpcProps } from './types'
6
8
 
7
9
  /**
8
10
  */
@@ -33,9 +35,19 @@ export class VpcManager {
33
35
  */
34
36
  public createVpc(id: string, scope: CommonConstruct, props: VpcProps) {
35
37
  if (!props) throw `Vpc props undefined for ${id}`
36
- const vpc = new Vpc(scope, `${id}`, {
37
- ...props,
38
- })
38
+
39
+ let vpc
40
+ if (props.isIPV6) {
41
+ vpc = new Ipv6Vpc(scope, `${id}`, {
42
+ ...props,
43
+ subnetConfiguration: [
44
+ { name: `${id}-public`, subnetType: SubnetType.PUBLIC },
45
+ { name: `${id}-private`, subnetType: SubnetType.PRIVATE_WITH_EGRESS },
46
+ ],
47
+ })
48
+ } else {
49
+ vpc = new Vpc(scope, `${id}`, props)
50
+ }
39
51
 
40
52
  createCfnOutput(`${id}Id`, scope, vpc.vpcId)
41
53
  createCfnOutput(`${id}PublicSubnetIds`, scope, _.map(vpc.publicSubnets, subnet => subnet.subnetId).toString())
@@ -0,0 +1,5 @@
1
+ import * as ec2 from 'aws-cdk-lib/aws-ec2'
2
+
3
+ export interface VpcProps extends ec2.VpcProps {
4
+ isIPV6?: boolean
5
+ }