Commit 0c41aa8
authored
fix: support Amazon Linux 2023 for NAT instance (#81)
## Summary
CDK's `NatInstanceProviderV2` uses the `route` command in its default
user data, which requires the `net-tools` package. However, Amazon Linux
2023 (the default AMI for `NatInstanceProviderV2`) doesn't have
`net-tools` pre-installed, causing NAT instances to fail silently.
## Problem
The default user data in CDK contains:
```bash
sudo /sbin/iptables -t nat -A POSTROUTING -o $(route | awk '/^default/{print $NF}') -j MASQUERADE
```
This fails on AL2023 because the `route` command is not available.
## Solution
This change provides custom user data that uses `ip route` instead of
`route` to determine the default network interface:
```bash
IFACE=$(ip route show default | awk '{print $5}')
/sbin/iptables -t nat -A POSTROUTING -o $IFACE -j MASQUERADE
```
## Reference
- CDK source code:
https://github.com/aws/aws-cdk/blob/main/packages/aws-cdk-lib/aws-ec2/lib/nat.ts
## Testing
- Deployed the stack with the fix and verified NAT instance works
correctly
- Application accessible via CloudFront (returns 307 redirect to sign-in
page as expected)1 parent f00fa21 commit 0c41aa8
File tree
3 files changed
+32
-11
lines changed- cdk
- lib
- test/__snapshots__
3 files changed
+32
-11
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
59 | 77 | | |
60 | 78 | | |
61 | 79 | | |
62 | 80 | | |
63 | 81 | | |
64 | 82 | | |
| 83 | + | |
65 | 84 | | |
66 | 85 | | |
67 | 86 | | |
| |||
Lines changed: 6 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2712 | 2712 | | |
2713 | 2713 | | |
2714 | 2714 | | |
2715 | | - | |
| 2715 | + | |
2716 | 2716 | | |
2717 | 2717 | | |
2718 | 2718 | | |
2719 | | - | |
2720 | | - | |
2721 | | - | |
2722 | | - | |
| 2719 | + | |
| 2720 | + | |
| 2721 | + | |
| 2722 | + | |
| 2723 | + | |
2723 | 2724 | | |
2724 | 2725 | | |
2725 | 2726 | | |
| |||
Lines changed: 6 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2544 | 2544 | | |
2545 | 2545 | | |
2546 | 2546 | | |
2547 | | - | |
| 2547 | + | |
2548 | 2548 | | |
2549 | 2549 | | |
2550 | 2550 | | |
2551 | | - | |
2552 | | - | |
2553 | | - | |
2554 | | - | |
| 2551 | + | |
| 2552 | + | |
| 2553 | + | |
| 2554 | + | |
| 2555 | + | |
2555 | 2556 | | |
2556 | 2557 | | |
2557 | 2558 | | |
| |||
0 commit comments