Commit e4bb09a
authored
Fix: lambda-deploy update path now verifies the execution role exists (#676)
### Problem
The `lambda-deploy` plugin's **update** path never verifies that the
function's execution role still exists. Lambda validates the execution
role lazily — only at *invoke* time, not when a function is created or
updated — so a redeploy against a function whose role was deleted (for
example by a previous `lambda-deploy --delete`, which removes both the
function and its role) succeeds silently. The function is left pointing
at a non-existent role and fails at invoke time with:
```
An error occurred (AccessDeniedException) when calling the Invoke operation:
The role defined for the function cannot be assumed by Lambda.
```
The role was only ever resolved/created on the **create** path, so once
the auto-managed role went missing there was no way to recover via
redeploy, and no diagnostic pointing at the cause.
### Fix
- On the **update** path, verify the function's configured execution
role still exists in IAM **before** updating the code. If it is gone,
stop the deployment with a clear error that names the function and role
and suggests the recovery action (delete + redeploy so the role is
recreated).
- The existence check now reuses the `GetFunction` response already
fetched to determine create-vs-update, so the verification adds **no
extra `GetFunction` call** — `functionExists(...) -> Bool` became
`existingFunctionConfiguration(...) -> FunctionConfiguration?` and the
configuration is carried downstream.
- New helpers: `roleName(fromARN:)` (extracts the role name from an
execution-role ARN, handling nested paths and partitions) and
`verifyExecutionRoleExists(...)` (maps IAM `NoSuchEntity` to the
actionable `executionRoleMissing` error).
### Tests
Added a property-test suite covering `roleName(fromARN:)` — valid ARNs
including service-role/nested paths and the `aws-us-gov` partition, plus
malformed/empty ARNs that must return `nil`.
All `AWSLambdaPluginHelperTests` pass (75 tests); the
`AWSLambdaPluginHelper` target builds clean on Swift 6.4.1 parent ecc20f0 commit e4bb09a
2 files changed
Lines changed: 126 additions & 11 deletions
File tree
- Sources/AWSLambdaPluginHelper/lambda-deploy
- Tests/AWSLambdaPluginHelperTests
Lines changed: 96 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
60 | | - | |
61 | | - | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
62 | 66 | | |
63 | 67 | | |
64 | | - | |
| 68 | + | |
65 | 69 | | |
66 | | - | |
| 70 | + | |
67 | 71 | | |
68 | | - | |
69 | | - | |
| 72 | + | |
70 | 73 | | |
71 | 74 | | |
72 | 75 | | |
73 | 76 | | |
74 | 77 | | |
75 | 78 | | |
76 | | - | |
| 79 | + | |
77 | 80 | | |
78 | 81 | | |
79 | 82 | | |
| |||
656 | 659 | | |
657 | 660 | | |
658 | 661 | | |
659 | | - | |
| 662 | + | |
| 663 | + | |
660 | 664 | | |
661 | | - | |
662 | | - | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
663 | 670 | | |
664 | 671 | | |
665 | | - | |
| 672 | + | |
666 | 673 | | |
667 | 674 | | |
668 | 675 | | |
| |||
780 | 787 | | |
781 | 788 | | |
782 | 789 | | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
783 | 801 | | |
784 | 802 | | |
785 | 803 | | |
| |||
908 | 926 | | |
909 | 927 | | |
910 | 928 | | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
| 947 | + | |
| 948 | + | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
911 | 985 | | |
912 | 986 | | |
913 | 987 | | |
| |||
1296 | 1370 | | |
1297 | 1371 | | |
1298 | 1372 | | |
| 1373 | + | |
1299 | 1374 | | |
1300 | 1375 | | |
1301 | 1376 | | |
| |||
1312 | 1387 | | |
1313 | 1388 | | |
1314 | 1389 | | |
| 1390 | + | |
| 1391 | + | |
| 1392 | + | |
| 1393 | + | |
| 1394 | + | |
| 1395 | + | |
| 1396 | + | |
| 1397 | + | |
| 1398 | + | |
| 1399 | + | |
1315 | 1400 | | |
1316 | 1401 | | |
1317 | 1402 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
627 | 627 | | |
628 | 628 | | |
629 | 629 | | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
0 commit comments