@ndlib/ndlib-cdk2 1.0.5 → 1.0.7

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/README.md CHANGED
@@ -382,7 +382,9 @@ new EC2withDatabase (app, 'StackName', {
382
382
  keyName: "libnd",
383
383
  privateIpAddress: "IPAddress",
384
384
  publicSubnetIds: [ "ValidSubnet in VPC" ],
385
- volumeSize: 50,
385
+ domainName: "Local domain name",
386
+ cnameList: [ Array of cnames/additional IPs to be added ],
387
+ volumeSize: Number (in GB),
386
388
  vpcId: "Valid VPC ID",
387
389
  sg_ingress_db: 'Security Group of database for access',
388
390
  sg_ingress_db_port: PortNumber,
@@ -19,6 +19,8 @@ export interface ServiceStackProps extends StackProps {
19
19
  readonly sg_ingress_rules: IIngress_Rule[];
20
20
  readonly sg_ingress_db: string;
21
21
  readonly sg_ingress_db_port: number;
22
+ readonly domainName: string;
23
+ readonly CnameList: string[];
22
24
  }
23
25
  export declare class EC2withDatabase extends Stack {
24
26
  constructor(scope: Construct, id: string, props: ServiceStackProps);
@@ -2,6 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.EC2withDatabase = void 0;
4
4
  const aws_cdk_lib_1 = require("aws-cdk-lib");
5
+ const aws_cdk_lib_2 = require("aws-cdk-lib");
6
+ const ssm = require("aws-cdk-lib/aws-ssm");
7
+ const aws_route53_1 = require("aws-cdk-lib/aws-route53");
5
8
  class EC2withDatabase extends aws_cdk_lib_1.Stack {
6
9
  constructor(scope, id, props) {
7
10
  super(scope, id, props);
@@ -16,7 +19,7 @@ class EC2withDatabase extends aws_cdk_lib_1.Stack {
16
19
  'us-east-1': props.amiId,
17
20
  });
18
21
  // Need to look up the role name and then get the ARN value
19
- const basic_role = aws_cdk_lib_1.aws_ssm.StringParameter.valueFromLookup(this, '/esu/ec2/basic_role_name');
22
+ const basic_role = ssm.StringParameter.valueFromLookup(this, '/esu/ec2/basic_role_name');
20
23
  const roleName = `arn:aws:iam::${this.account}:${basic_role}`;
21
24
  const ec2role = aws_cdk_lib_1.aws_iam.Role.fromRoleArn(this, 'Role', roleName);
22
25
  // Create a security group for this specific server using rules passed in
@@ -33,7 +36,7 @@ class EC2withDatabase extends aws_cdk_lib_1.Stack {
33
36
  ec2SecurityGroup.addIngressRule(aws_cdk_lib_1.aws_ec2.Peer.ipv4(rule.ipv4), aws_cdk_lib_1.aws_ec2.Port.tcp(rule.port), rule.description);
34
37
  });
35
38
  // With all of the information gathered, as well as values passed in, create the server
36
- new aws_cdk_lib_1.aws_ec2.Instance(this, 'ec2-server', {
39
+ const ec2_server = new aws_cdk_lib_1.aws_ec2.Instance(this, 'ec2-server', {
37
40
  blockDevices: [{
38
41
  deviceName: '/dev/xvda',
39
42
  volume: {
@@ -51,6 +54,50 @@ class EC2withDatabase extends aws_cdk_lib_1.Stack {
51
54
  instanceName: props.instanceName,
52
55
  privateIpAddress: props.privateIpAddress,
53
56
  });
57
+ const IPAddr = new aws_cdk_lib_1.aws_ec2.CfnEIP(this, 'Ip');
58
+ new aws_cdk_lib_1.aws_ec2.CfnEIPAssociation(this, 'Ec2Association', {
59
+ eip: IPAddr.ref,
60
+ instanceId: ec2_server.instanceId,
61
+ });
62
+ // Create DNS for libnd.nd.edu connection
63
+ const privateZoneId = ssm.StringParameter.fromStringParameterAttributes(this, 'PrivateZoneId', {
64
+ parameterName: `/all/dns/${props.keyName}/private/zoneId`,
65
+ }).stringValue;
66
+ new aws_route53_1.ARecord(this, 'PrivateARec', {
67
+ target: aws_route53_1.RecordTarget.fromIpAddresses(props.privateIpAddress),
68
+ recordName: props.instanceName,
69
+ zone: aws_route53_1.HostedZone.fromHostedZoneAttributes(this, 'PrivateHostedZone', {
70
+ hostedZoneId: privateZoneId,
71
+ zoneName: `${props.keyName}.nd.edu`,
72
+ }),
73
+ ttl: aws_cdk_lib_2.Duration.minutes(5),
74
+ });
75
+ // Create both Public and Private A records for library.nd.edu
76
+ for (const direction of ['public', 'private']) {
77
+ const hostedZoneId = ssm.StringParameter.fromStringParameterAttributes(this, `${direction}HostedZoneId`, {
78
+ parameterName: `/all/dns/${props.domainName}/${direction}/zoneId`,
79
+ }).stringValue;
80
+ new aws_route53_1.ARecord(this, `${direction}ServiceARec`, {
81
+ target: aws_route53_1.RecordTarget.fromIpAddresses(IPAddr.ref),
82
+ recordName: props.instanceName,
83
+ zone: aws_route53_1.HostedZone.fromHostedZoneAttributes(this, `${direction}ImportedHostedZone`, {
84
+ hostedZoneId: hostedZoneId,
85
+ zoneName: props.domainName,
86
+ }),
87
+ ttl: aws_cdk_lib_2.Duration.minutes(5),
88
+ });
89
+ props.CnameList.forEach(cname => {
90
+ new aws_route53_1.ARecord(this, `${direction}${cname}`, {
91
+ target: aws_route53_1.RecordTarget.fromIpAddresses(IPAddr.ref),
92
+ recordName: cname,
93
+ zone: aws_route53_1.HostedZone.fromHostedZoneAttributes(this, `${direction}${cname}HostedZone`, {
94
+ hostedZoneId: hostedZoneId,
95
+ zoneName: props.domainName,
96
+ }),
97
+ ttl: aws_cdk_lib_2.Duration.minutes(5),
98
+ });
99
+ });
100
+ }
54
101
  }
55
102
  }
56
103
  exports.EC2withDatabase = EC2withDatabase;
@@ -20,10 +20,10 @@ export interface IStaticHostProps {
20
20
  */
21
21
  readonly createDns?: boolean;
22
22
  /**
23
- * Hosted zone ids for the route53 record. Is required if createDns is true.
23
+ * Hosted zone types (used to retrieve hosted zone ids) for the route53 record(s). Is required if createDns is true.
24
24
  * This is now an array to accommodate both a public hosted zone id and a private hosted zone id
25
25
  */
26
- readonly hostedZoneIds?: string[];
26
+ readonly hostedZoneTypes?: string[];
27
27
  /**
28
28
  * Root page to be served.
29
29
  */
@@ -3,25 +3,20 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.StaticHost = void 0;
4
4
  const aws_cdk_lib_1 = require("aws-cdk-lib");
5
5
  const constructs_1 = require("constructs");
6
- const crypto_1 = require("crypto");
6
+ const aws_ssm_1 = require("aws-cdk-lib/aws-ssm");
7
7
  class StaticHost extends constructs_1.Construct {
8
8
  constructor(scope, id, props) {
9
9
  var _a;
10
10
  super(scope, id);
11
11
  this.inProps = props;
12
- // removed .validate() and replaced with this error to enforce hostedZondId when createDNS is true
13
- // if (this.inProps.createDns && !this.inProps.hostedZoneIds) {
14
- // Annotations.of(this).addError('hostedZoneIds is required when createDns is true')
15
- // throw new Error('hostedZoneIds is required when createDns is true')
16
- // }
17
12
  if (this.inProps.createDns) {
18
- if (!this.inProps.hostedZoneIds) {
19
- aws_cdk_lib_1.Annotations.of(this).addError('hostedZoneIds is required when createDns is true');
20
- throw new Error('hostedZoneIds is required when createDns is true');
13
+ if (!this.inProps.hostedZoneTypes) {
14
+ aws_cdk_lib_1.Annotations.of(this).addError('hostedZoneTypes is required when createDns is true');
15
+ throw new Error('hostedZoneTypes is required when createDns is true');
21
16
  }
22
- if (this.inProps.hostedZoneIds.length == 0) {
23
- aws_cdk_lib_1.Annotations.of(this).addError('hostedZoneIds is required when createDns is true, and must contain at least one hostedZoneId');
24
- throw new Error('hostedZoneIds is required when createDns is true, and must contain at least one hostedZoneId');
17
+ if (this.inProps.hostedZoneTypes.length == 0) {
18
+ aws_cdk_lib_1.Annotations.of(this).addError('hostedZoneTypes is required when createDns is true, and must contain at least one hostedZoneId');
19
+ throw new Error('hostedZoneTypes is required when createDns is true, and must contain at least one hostedZoneId');
25
20
  }
26
21
  }
27
22
  const stack = aws_cdk_lib_1.Stack.of(this);
@@ -115,19 +110,22 @@ class StaticHost extends constructs_1.Construct {
115
110
  viewerProtocolPolicy: aws_cdk_lib_1.aws_cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
116
111
  });
117
112
  // Create DNS record (conditionally)
118
- if (props.createDns && props.hostedZoneIds && props.hostedZoneIds.length > 0) {
119
- for (const hostedZoneId of props.hostedZoneIds) {
120
- const id = (0, crypto_1.randomUUID)();
121
- new aws_cdk_lib_1.aws_route53.CnameRecord(this, `ServiceCNAME${id}`, {
122
- recordName: this.hostname,
123
- comment: this.hostname,
124
- domainName: this.cloudfront.distributionDomainName,
125
- zone: aws_cdk_lib_1.aws_route53.HostedZone.fromHostedZoneAttributes(this, `ImportedHostedZone${id}`, {
126
- hostedZoneId: hostedZoneId,
127
- zoneName: props.domainName,
128
- }),
129
- ttl: aws_cdk_lib_1.Duration.minutes(15),
130
- });
113
+ if (props.createDns && props.hostedZoneTypes && props.hostedZoneTypes.length > 0) {
114
+ for (const hostedZoneType of ['public', 'private']) {
115
+ if (props.hostedZoneTypes.includes(hostedZoneType)) {
116
+ const hostedZoneIdPath = `/all/dns/${props.domainName}/${hostedZoneType}/zoneId`;
117
+ const hostedZoneId = aws_ssm_1.StringParameter.valueForStringParameter(this, hostedZoneIdPath);
118
+ new aws_cdk_lib_1.aws_route53.CnameRecord(this, `ServiceCNAME${hostedZoneType}`, {
119
+ recordName: this.hostname,
120
+ comment: this.hostname,
121
+ domainName: this.cloudfront.distributionDomainName,
122
+ zone: aws_cdk_lib_1.aws_route53.HostedZone.fromHostedZoneAttributes(this, `ImportedHostedZone${hostedZoneType}`, {
123
+ hostedZoneId: hostedZoneId,
124
+ zoneName: props.domainName,
125
+ }),
126
+ ttl: aws_cdk_lib_1.Duration.minutes(15),
127
+ });
128
+ }
131
129
  }
132
130
  }
133
131
  this.bucketNameParam = new aws_cdk_lib_1.aws_ssm.StringParameter(this, 'BucketParameter', {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ndlib/ndlib-cdk2",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "description": "Reusable CDK2 modules used within Hesburgh Libraries of Notre Dame",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -37,41 +37,40 @@
37
37
  },
38
38
  "homepage": "https://github.com/ndlib/ndlib-cdk2#readme",
39
39
  "peerDependencies": {
40
- "aws-cdk-lib": "^2.24.1",
41
- "constructs": "^10.1.12"
40
+ "aws-cdk-lib": "^2.41.0"
42
41
  },
43
42
  "devDependencies": {
44
- "@types/jest": "^27.5.1",
45
- "@types/node": "^17.0.35",
46
- "@typescript-eslint/eslint-plugin": "^5.25.0",
47
- "@typescript-eslint/parser": "^5.25.0",
48
- "aws-sdk": "^2.1140.0",
49
- "aws-sdk-client-mock": "^0.6.2",
50
- "eslint": "^8.15.0",
43
+ "@types/jest": "^29.0.2",
44
+ "@types/node": "^18.7.18",
45
+ "@typescript-eslint/eslint-plugin": "^5.37.0",
46
+ "@typescript-eslint/parser": "^5.37.0",
47
+ "aws-sdk": "^2.1215.0",
48
+ "aws-sdk-client-mock": "^2.0.0",
49
+ "eslint": "^8.23.1",
51
50
  "eslint-config-standard": "^17.0.0",
52
51
  "eslint-plugin-import": "^2.26.0",
53
- "eslint-plugin-jest": "^26.2.2",
54
- "eslint-plugin-n": "^15.2.0",
52
+ "eslint-plugin-jest": "^27.0.4",
53
+ "eslint-plugin-n": "^15.2.5",
55
54
  "eslint-plugin-node": "^11.1.0",
56
- "eslint-plugin-promise": "^6.0.0",
55
+ "eslint-plugin-promise": "^6.0.1",
57
56
  "eslint-plugin-standard": "^5.0.0",
58
57
  "github-changes": "^2.0.3",
59
- "jest": "^28.1.0",
60
- "prettier": "^2.6.2",
58
+ "jest": "^29.0.3",
59
+ "prettier": "^2.7.1",
61
60
  "subpackage": "^1.1.0",
62
- "ts-jest": "^28.0.2",
61
+ "ts-jest": "^29.0.1",
63
62
  "tsc-watch": "^5.0.3",
64
- "typescript": "^4.6.4"
63
+ "typescript": "^4.8.3"
65
64
  },
66
65
  "files": [
67
66
  "lib/**/*"
68
67
  ],
69
68
  "dependencies": {
70
- "@aws-cdk/aws-appsync-alpha": "^2.24.1-alpha.0",
71
- "aws-cdk-lib": "^2.24.1",
72
- "constructs": "^10.1.12",
73
- "jest-mock": "^28.1.0",
74
- "node-fetch": "^3.2.4"
69
+ "@aws-cdk/aws-appsync-alpha": "^2.41.0-alpha.0",
70
+ "aws-cdk-lib": "^2.41.0",
71
+ "constructs": "^10.1.102",
72
+ "jest-mock": "^29.0.3",
73
+ "node-fetch": "^3.2.10"
75
74
  },
76
75
  "subPackages": [
77
76
  "src/internal-lambdas/sourceWatcherLambda/src"
package/lib/.DS_Store DELETED
Binary file
Binary file
Binary file
Binary file
Binary file