Skip to content

Commit bef27ad

Browse files
Merge pull request #1556 from guardian/jb/one-cdk-directory
Move to use only one central cdk directory
2 parents 8d8764f + a56df28 commit bef27ad

23 files changed

Lines changed: 5317 additions & 8142 deletions

.github/dependabot.yml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,6 @@ updates:
99
- dependency-name: "aws-cdk"
1010
- dependency-name: "aws-cdk-lib"
1111
- dependency-name: "constructs"
12-
13-
- package-ecosystem: npm
14-
directory: "/notificationworkerlambda/cdk"
15-
schedule:
16-
interval: "monthly"
17-
# The version of AWS CDK libraries must match those from @guardian/cdk.
18-
ignore:
19-
- dependency-name: "aws-cdk"
20-
- dependency-name: "aws-cdk-lib"
21-
- dependency-name: "constructs"
2212

2313
- package-ecosystem: "github-actions"
2414
directory: "/"

.github/workflows/cdk-test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: cdk test
22

33
defaults:
44
run:
5-
working-directory: notificationworkerlambda/cdk
5+
working-directory: cdk
66

77
on:
88
pull_request:
@@ -25,7 +25,7 @@ jobs:
2525
with:
2626
node-version-file: ".nvmrc"
2727
cache: "yarn"
28-
cache-dependency-path: notificationworkerlambda/cdk/yarn.lock
28+
cache-dependency-path: cdk/yarn.lock
2929

3030
- name: Install
3131
run: yarn install --frozen-lockfile

.github/workflows/notification-worker-lambdas.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ jobs:
7575
BUILD_NUMBER: ${{ github.run_number }}
7676

7777
- name: CDK synth (worker lambda cdk directory)
78-
working-directory: notificationworkerlambda/cdk
78+
working-directory: cdk
7979
run: |
8080
yarn install
8181
yarn test
@@ -101,8 +101,8 @@ jobs:
101101
mobile-notifications-harvester-cfn:
102102
- notificationworkerlambda/harvester-cfn.yaml
103103
mobile-notifications-workers-cfn:
104-
- notificationworkerlambda/cdk/cdk.out/SenderWorkerStack-CODE.template.json
105-
- notificationworkerlambda/cdk/cdk.out/SenderWorkerStack-PROD.template.json
104+
- cdk/cdk.out/SenderWorkerStack-CODE.template.json
105+
- cdk/cdk.out/SenderWorkerStack-PROD.template.json
106106
mobile-notifications-topic-counter-cfn:
107107
- notificationworkerlambda/topic-counter-cfn.yaml
108108
mobile-notifications-registration-cleaning-worker-cfn:

notificationworkerlambda/cdk/.editorconfig renamed to cdk/.editorconfig

File renamed without changes.

cdk/README.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,86 @@
33
This directory defines the components to be deployed to AWS.
44

55
See [`package.json`](./package.json) for a list of available scripts.
6+
7+
## Notification Lambda CDK
8+
9+
This directory contains the CDK for the Cloudformation that describes the notification lambda architecture.
10+
11+
The `cdk.json` file tells the CDK Toolkit how to execute your app.
12+
13+
### Scope
14+
15+
Currently this defines the notification sender lambdas because there are 5 of
16+
these with almost identical configurations.
17+
18+
### Useful commands
19+
20+
* `npm run build` compile typescript to js
21+
* `npm run watch` watch for changes and compile
22+
* `npm run test` perform the jest unit tests
23+
* `cdk deploy` deploy this stack to your default AWS account/region
24+
* `cdk diff` compare deployed stack with current state
25+
* `cdk synth` emits the synthesized CloudFormation template
26+
27+
##- Stack dependencies
28+
29+
It's important to note that there is an [Exported
30+
Value](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-stack-exports.html)
31+
which is exported from this stack and consumed by the Harvester stack. This is
32+
because Harvester needs to know the ARNs of the SQS queues that are created here
33+
for each notification sender.
34+
35+
The off-shoot of this is that AWS will prevent you from making a change to this
36+
list of ARNs while it is being consumed by the other stack.
37+
38+
Note that this is only a problem *in the very rare case* of when you are making
39+
a change which actually affects this list of ARNs — e.g. adding a new
40+
lambda or removing an old one — any other changes should be fine.
41+
42+
If you are making such a change, the deployment will fail (harmlessly, as it
43+
will just be rolled back).
44+
45+
#### Deploying if you change the list of SQS queues
46+
47+
In that case, what you should do is, copy the currently exported value (either
48+
via the console or using the following snippet, replacing `CODE` with the
49+
correct stage of course):
50+
51+
``` shell
52+
$ aws cloudformation list-exports | jq -r '.Exports | map(select(.Name == "NotificationSenderWorkerQueueArns-CODE")) | .[0].Value'
53+
```
54+
55+
and then insert this into the harvester cloudformation as a literal value
56+
instead of the import. The simplest way to do this is just to edit the YAML file
57+
and upload it. The diff would look something like this:
58+
59+
``` shell
60+
diff --git a/notificationworkerlambda/harvester-cfn.yaml b/notificationworkerlambda/harvester-cfn.yaml
61+
index 3e4fcbf1..e83c63fa 100644
62+
--- a/notificationworkerlambda/harvester-cfn.yaml
63+
+++ b/notificationworkerlambda/harvester-cfn.yaml
64+
@@ -110,10 +110,11 @@ Resources:
65+
Statement:
66+
Effect: Allow
67+
Action: sqs:*
68+
- Resource: !Split
69+
- - ","
70+
- - !ImportValue
71+
- 'Fn::Sub': 'NotificationSenderWorkerQueueArns-${Stage}'
72+
+ Resource: "arn:aws:sqs:eu-west-1:[...]"
73+
- PolicyName: VPC
74+
PolicyDocument:
75+
Statement:
76+
```
77+
78+
After that, the following command should indicate that this value is no longer
79+
imported, and then you can freely make any neccessary changes:
80+
81+
``` shell
82+
$ aws cloudformation list-imports --export-name='NotificationSenderWorkerQueueArns-CODE'
83+
An error occurred (ValidationError) when calling the ListImports operation: Export 'NotificationSenderWorkerQueueArns-CODE' is not imported by any stack.
84+
```
85+
86+
After the project has been redeployed with riff-raff, the import should be
87+
automatically put back in place.
88+

cdk/bin/cdk.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { GuStackProps } from '@guardian/cdk/lib/constructs/core';
33
import { App } from 'aws-cdk-lib';
44
import { Registration } from '../lib/registration';
55
import { RegistrationsDbProxy } from '../lib/registrations-db-proxy';
6+
import { SenderWorkerStack } from '../lib/senderworker';
67
import { SloMonitoring } from '../lib/slo-monitoring';
78

89
const app = new App();
@@ -53,3 +54,14 @@ new SloMonitoring(app, 'SloMonitor-PROD', {
5354
stack: 'mobile-notifications',
5455
stage: 'PROD',
5556
});
57+
58+
new SenderWorkerStack(app, 'SenderWorkerStack-CODE', {
59+
stack: 'mobile-notifications-workers',
60+
stage: 'CODE',
61+
cloudFormationStackName: 'notification-sender-workers-cdk-CODE'
62+
});
63+
64+
new SenderWorkerStack(app, 'SenderWorkerStack-PROD', {
65+
stack: 'mobile-notifications-workers',
66+
stage: 'PROD',
67+
});

0 commit comments

Comments
 (0)