|
3 | 3 | This directory defines the components to be deployed to AWS. |
4 | 4 |
|
5 | 5 | 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 | + |
0 commit comments