@ndlib/ndlib-cdk2 1.0.39 → 1.0.40

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
@@ -307,38 +307,6 @@ new PipelineS3Sync(this, 'S3SyncProd', {
307
307
  })
308
308
  ```
309
309
 
310
- ## Source Watcher
311
-
312
- The SourceWatcher construct creates necessary resources to monitor a GitHub repository for changes. Based on the changes that are made, one or more pipelines may be invoked according to the configuration. This is similar to how CodePipelines can have a Webhook on the source action, except that it allows for _conditional_ triggering depending on where the changes reside within the repo. Therefore, if multiple pipelines share a repo, a change to files which only impact one do not have to trigger the unmodified pipeline.
313
-
314
- Example:
315
-
316
- ```typescript
317
- import { Stack }from 'aws-cdk-lib'
318
- import { SourceWatcher } from '@ndlib/ndlib-cdk2'
319
-
320
- const stack = new Stack()
321
- new SourceWatcher(stack, 'TestProject', {
322
- triggers: [
323
- {
324
- triggerPatterns: ['my/test/**/pattern.js', 'example/*.*'],
325
- pipelineStackName: 'pipeline-a',
326
- },
327
- {
328
- triggerPatterns: ['src/anotherExample.ts'],
329
- pipelineStackName: 'pipeline-b',
330
- },
331
- ],
332
- targetRepo: 'ndlib/myRepo',
333
- targetBranch: 'main',
334
- gitTokenPath: '/all/github/ndlib-git',
335
- webhookResourceStackName: 'github-webhook-custom-resource-prod',
336
- })
337
- ```
338
-
339
- NOTE: `webhookResourceStackName` refers to a stack which will manage contains the backend for a CustomResource webhook. Prior to using this construct, an instance of [ndlib/aws-github-webhook](https://github.com/ndlib/aws-github-webhook) should be deployed to the AWS account. One stack can be used for any number of SourceWatcher constructs.
340
-
341
-
342
310
  ## EC2 server with access rules
343
311
 
344
312
  The EC2withDatabase construct builds an EC2 server. The basic concept is to build the server with security group access to, possibly, several AWS RDS database servers. The server is built within an existing VPC. Parameters allow for AMI ID, instance type, root disk storage, networking, and security group rules for the server upon build. The server is created with the OS only; further configuration will need to be performed, often using ansible.
package/lib/https-alb.js CHANGED
@@ -30,12 +30,6 @@ class HttpsAlb extends aws_cdk_lib_1.aws_elasticloadbalancingv2.ApplicationLoadB
30
30
  sslPolicy: aws_cdk_lib_1.aws_elasticloadbalancingv2.SslPolicy.TLS13_RES,
31
31
  });
32
32
  this.defaultListener.addAction('Default404', { action: aws_cdk_lib_1.aws_elasticloadbalancingv2.ListenerAction.fixedResponse(404) });
33
- // Adding an output of the dns name for convenience when looking at this
34
- // in the console/cli.
35
- new aws_cdk_lib_1.CfnOutput(scope, 'PublicLoadBalancerDNSName', {
36
- description: 'The DNS name of the load balancer',
37
- value: this.loadBalancerDnsName,
38
- });
39
33
  }
40
34
  addHttpRedirect() {
41
35
  // Add a listener to redirect http to https
package/lib/index.d.ts CHANGED
@@ -15,5 +15,4 @@ export * from './slack-pipeline-status-notifications';
15
15
  export * from './slos/alarms';
16
16
  export * from './slos/alarms-dashboard';
17
17
  export * from './slos/performance-dashboard';
18
- export * from './source-watcher';
19
18
  export * from './stack-tags';
package/lib/index.js CHANGED
@@ -31,5 +31,4 @@ __exportStar(require("./slack-pipeline-status-notifications"), exports);
31
31
  __exportStar(require("./slos/alarms"), exports);
32
32
  __exportStar(require("./slos/alarms-dashboard"), exports);
33
33
  __exportStar(require("./slos/performance-dashboard"), exports);
34
- __exportStar(require("./source-watcher"), exports);
35
34
  __exportStar(require("./stack-tags"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ndlib/ndlib-cdk2",
3
- "version": "1.0.39",
3
+ "version": "1.0.40",
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",
@@ -40,35 +40,32 @@
40
40
  "aws-cdk-lib": "^2.206.0"
41
41
  },
42
42
  "devDependencies": {
43
- "@types/jest": "^29.5.14",
44
- "@types/node": "^24.0.11",
45
- "@typescript-eslint/eslint-plugin": "^8.36.0",
46
- "@typescript-eslint/parser": "^8.36.0",
43
+ "@types/jest": "^30.0.0",
44
+ "@types/node": "^24.5.2",
45
+ "@typescript-eslint/eslint-plugin": "^8.44.1",
46
+ "@typescript-eslint/parser": "^8.44.1",
47
47
  "auto-changelog": "^2.5.0",
48
48
  "aws-sdk-client-mock": "^4.1.0",
49
- "eslint": "^9.30.1",
49
+ "eslint": "^9.36.0",
50
50
  "eslint-plugin-import": "^2.32.0",
51
51
  "eslint-plugin-jest": "^29.0.1",
52
- "eslint-plugin-n": "^17.21.0",
52
+ "eslint-plugin-n": "^17.23.1",
53
53
  "eslint-plugin-node": "^11.1.0",
54
54
  "eslint-plugin-promise": "^7.2.1",
55
- "jest": "^29.7.0",
56
- "jest-mock": "^30.0.2",
55
+ "jest": "^30.1.3",
56
+ "jest-mock": "^30.0.5",
57
57
  "prettier": "^3.6.2",
58
- "ts-jest": "^29.4.0",
58
+ "ts-jest": "^29.4.4",
59
59
  "tsc-watch": "^7.1.1",
60
- "typescript": "^5.8.3"
60
+ "typescript": "^5.9.2"
61
61
  },
62
62
  "files": [
63
63
  "lib/**/*"
64
64
  ],
65
65
  "dependencies": {
66
- "aws-cdk-lib": "^2.206.0",
66
+ "aws-cdk-lib": "^2.216.0",
67
67
  "constructs": "^10.4.2"
68
68
  },
69
- "workspaces": [
70
- "src/internal-lambdas/sourceWatcherLambda/src"
71
- ],
72
69
  "engines": {
73
70
  "node": ">=22.0.0"
74
71
  }
@@ -1,50 +0,0 @@
1
- import { aws_apigateway, aws_lambda } from 'aws-cdk-lib';
2
- import { Construct } from 'constructs';
3
- export interface IPipelineTrigger {
4
- /**
5
- * List of file system glob patterns. If a commit changes any matching file, pipeline will be triggered.
6
- */
7
- readonly triggerPatterns: string[];
8
- /**
9
- * Name of the pipeline stack. Informs the lambda which pipeline to trigger when a matching change occurs.
10
- */
11
- readonly pipelineStackName: string;
12
- }
13
- export interface ISourceWatcherProps {
14
- /**
15
- * Used to configure the SourceWatcher with a file patterns and the appropriate pipelines that they should trigger.
16
- */
17
- readonly triggers: IPipelineTrigger[];
18
- /**
19
- * Name of repository to watch for changes. (Ex: "owner/my-repo-name")
20
- */
21
- readonly targetRepo: string;
22
- /**
23
- * Branch to watch for changes on. All other branches will be ignored and WON'T trigger pipeline execution.
24
- */
25
- readonly targetBranch: string;
26
- /**
27
- * SecretsManager path to secret with credentials for accessing the GitHub repo.
28
- */
29
- readonly gitTokenPath: string;
30
- /**
31
- * Stack name for aws-github-webhook. Needed in order to create a webhook on targetRepo.
32
- */
33
- readonly webhookResourceStackName?: string;
34
- readonly webhookResourceArnParameterPath?: string;
35
- }
36
- export declare class SourceWatcher extends Construct {
37
- /**
38
- * The Lambda Function which handles a GitHub event payload and triggers a pipeline.
39
- */
40
- readonly lambdaFunction: aws_lambda.Function;
41
- /**
42
- * API which routes requests to the lambdaFunction.
43
- */
44
- readonly api: aws_apigateway.LambdaRestApi;
45
- /**
46
- * Reference which will resolve to the ID of the webhook created on the GitHub repo.
47
- */
48
- readonly webhookId: string;
49
- constructor(scope: Construct, id: string, props: ISourceWatcherProps);
50
- }
@@ -1,95 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SourceWatcher = void 0;
4
- const aws_cdk_lib_1 = require("aws-cdk-lib");
5
- const constructs_1 = require("constructs");
6
- const aws_ssm_1 = require("aws-cdk-lib/aws-ssm");
7
- const path = require("path");
8
- class SourceWatcher extends constructs_1.Construct {
9
- constructor(scope, id, props) {
10
- super(scope, id);
11
- const stack = aws_cdk_lib_1.Stack.of(this);
12
- // Each trigger will create a StringList parameter in SSM. This way the lambda can get a dynamic list based on
13
- // the infrastructure instead of hardcoding in the lambda itself.
14
- const triggersSsmPath = `/all/stacks/${stack.stackName}/triggers`;
15
- props.triggers.forEach(trigger => {
16
- new aws_cdk_lib_1.aws_ssm.StringListParameter(this, `TriggerParam_${trigger.pipelineStackName}`, {
17
- parameterName: `${triggersSsmPath}/${trigger.pipelineStackName}`,
18
- description: 'Glob patterns for file paths in the infrastructure repo which will trigger the pipeline.',
19
- stringListValue: trigger.triggerPatterns,
20
- });
21
- });
22
- // Get the secret which is used to validate the signature of the event payload
23
- const webhookSecret = aws_cdk_lib_1.SecretValue.secretsManager(props.gitTokenPath, { jsonField: 'webhook-secret' });
24
- this.lambdaFunction = new aws_cdk_lib_1.aws_lambda.Function(this, 'SourceWatcherLambda', {
25
- code: aws_cdk_lib_1.aws_lambda.Code.fromAsset(path.join(__dirname, './internal-lambdas/sourceWatcherLambda/src')),
26
- description: 'Checks if git push changed certain files and triggers pipeline(s) accordingly.',
27
- handler: 'index.handler',
28
- runtime: aws_cdk_lib_1.aws_lambda.Runtime.NODEJS_22_X,
29
- timeout: aws_cdk_lib_1.Duration.minutes(1),
30
- environment: {
31
- WEBHOOK_SECRET: webhookSecret.toString(),
32
- TRIGGER_PARAMS_PATH: triggersSsmPath,
33
- GIT_REPO: props.targetRepo,
34
- GIT_BRANCH: props.targetBranch,
35
- },
36
- });
37
- // Allow lambda to read params we created specifying the trigger metadata.
38
- this.lambdaFunction.addToRolePolicy(new aws_cdk_lib_1.aws_iam.PolicyStatement({
39
- resources: [
40
- aws_cdk_lib_1.Fn.sub('arn:aws:ssm:${AWS::Region}:${AWS::AccountId}:parameter' + triggersSsmPath + '/*'),
41
- ].concat(props.triggers.map(trigger => aws_cdk_lib_1.Fn.sub('arn:aws:ssm:${AWS::Region}:${AWS::AccountId}:parameter/all/stacks/' +
42
- trigger.pipelineStackName +
43
- '/pipeline-name'))),
44
- actions: ['ssm:GetParameter', 'ssm:GetParameters'],
45
- }));
46
- this.lambdaFunction.addToRolePolicy(new aws_cdk_lib_1.aws_iam.PolicyStatement({
47
- resources: [aws_cdk_lib_1.Fn.sub('arn:aws:ssm:${AWS::Region}:${AWS::AccountId}:parameter' + triggersSsmPath)],
48
- actions: ['ssm:GetParametersByPath'],
49
- }));
50
- this.lambdaFunction.addToRolePolicy(new aws_cdk_lib_1.aws_iam.PolicyStatement({
51
- resources: ['*'],
52
- actions: ['codepipeline:StartPipelineExecution'],
53
- }));
54
- // The API gateway will serve an endpoint which we can hit in a github webhook to trigger the lambda
55
- this.api = new aws_cdk_lib_1.aws_apigateway.LambdaRestApi(this, 'SourceWatcherApi', {
56
- handler: this.lambdaFunction,
57
- proxy: true,
58
- });
59
- // Added the following code to get the WebhookLambdaArn from either a parameter store path or a stack name. (Used to be only from stack name)
60
- let githubWebhookLambdaArn = '';
61
- if (props.webhookResourceArnParameterPath) {
62
- githubWebhookLambdaArn = aws_ssm_1.StringParameter.valueForStringParameter(this, props.webhookResourceArnParameterPath);
63
- }
64
- if (!githubWebhookLambdaArn && props.webhookResourceStackName) {
65
- githubWebhookLambdaArn = aws_cdk_lib_1.Fn.importValue(`${props.webhookResourceStackName}:LambdaArn`);
66
- }
67
- if (!githubWebhookLambdaArn) {
68
- throw new Error('You must provide a webhookResourceArnParameterPath or webhookResourceStackName to create a GitHub webhook.');
69
- }
70
- // Finally, create the Webhook on GitHub to route push events to the API!
71
- const webhookLambda = aws_cdk_lib_1.aws_lambda.Function.fromFunctionAttributes(this, 'GithubWebhookLambda', {
72
- functionArn: githubWebhookLambdaArn,
73
- skipPermissions: true,
74
- });
75
- const resourceProvider = new aws_cdk_lib_1.custom_resources.Provider(this, 'WebhookProvider', {
76
- onEventHandler: webhookLambda,
77
- logRetention: aws_cdk_lib_1.aws_logs.RetentionDays.ONE_WEEK,
78
- });
79
- const webhook = new aws_cdk_lib_1.CustomResource(this, 'GithubWebhook', {
80
- resourceType: 'Custom::GitHubWebhook',
81
- serviceToken: resourceProvider.serviceToken,
82
- properties: {
83
- Repo: props.targetRepo,
84
- Events: 'push',
85
- Endpoint: this.api.url,
86
- },
87
- });
88
- this.webhookId = webhook.getAtt('WebhookId').toString();
89
- new aws_cdk_lib_1.CfnOutput(this, 'WebhookId', {
90
- description: 'ID used by provider (GitHub) to identify the webhook.',
91
- value: this.webhookId,
92
- });
93
- }
94
- }
95
- exports.SourceWatcher = SourceWatcher;