Commit d860feb
fix(ami-housekeeper): don't delete referenced AMIs in default config (#4623)
In 472cc5f the default config was
migrated to use SSM for AMI lookup. A parameter is created which stores
a reference to the AMI. By default, this parameter is called
`${var.ssm_paths.root}/${var.ssm_paths.config}/ami_id`.
The housekeeper is a process that looks for AMIs which can be deleted
because they're no longer used. It does this in a couple of ways:
1. Check the launch template for the AMI ID.
2. Check the SSM parameter.
3. Apply a threshold to not delete AMIs that are too new, according to
the config.
The problem is that we were looking for SSM parameters like this:
```typescript
const ssmParams = await ssmClient.send(
new DescribeParametersCommand({
ParameterFilters: [
{
Key: "Name",
Values: ["ami-id"],
Option: "Contains",
},
],
}),
);
```
i.e. we were looking for parameters which contain the hardcoded string
`ami-id`. This is different to the new default of `ami_id`. So we
weren't considering the right AMIs to be in use.
What would be a better approach would be to reference the values
dynamically. This means resolving from the template, and handling the
passed-in options, if there are any. We're documenting that we support
wildcards, so also support that here too.
The default value in the launch template became `resolve:ssm:<id or
AMI>`, so we need to make sure to ask EC2 to resolve for us when looking
up the template. In that way we get the actual AMI ID rather than the
alias.
This can be a bit challenging to understand, so the comments are
improved.
Comprehensive tests are added to try to ensure this all works as
expected.
Closes: #4571
---------
Co-authored-by: Niek Palm <niek.palm@philips.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Niek Palm <npalm@users.noreply.github.com>1 parent d3b5e27 commit d860feb
File tree
7 files changed
+640
-46
lines changed- examples/prebuilt
- images
- lambdas/functions/ami-housekeeper/src
- modules/ami-housekeeper/policies
7 files changed
+640
-46
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
10 | 22 | | |
11 | 23 | | |
12 | 24 | | |
| |||
92 | 104 | | |
93 | 105 | | |
94 | 106 | | |
| 107 | + | |
| 108 | + | |
95 | 109 | | |
96 | 110 | | |
97 | 111 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
3 | | - | |
| 2 | + | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | | - | |
36 | | - | |
37 | | - | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
38 | 41 | | |
39 | 42 | | |
40 | 43 | | |
| |||
56 | 59 | | |
57 | 60 | | |
58 | 61 | | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
59 | 100 | | |
60 | 101 | | |
61 | 102 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
10 | 24 | | |
11 | 25 | | |
12 | 26 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
0 commit comments