Files
floci/src/main/java
lex00 105a8eeb7e feat(cloudformation): provision AWS::Lambda::Permission and fix Version and Alias updates (#1997)
* feat(cloudformation): provision AWS::Lambda::Permission, Version, and Alias

Maps the three Lambda addressing resources onto the existing
LambdaService APIs: Permission -> addPermission (statement id = logical
id, SourceArn/SourceAccount carried), Version -> publishVersion (Ref =
version-qualified ARN, Version/FunctionArn attributes), Alias ->
createAlias (Ref = alias ARN).

Fixes #1996

* refactor(cloudformation): move Lambda addressing into a per-service provisioner

Moves AWS::Lambda::Permission, Version and Alias out of the
CloudFormationResourceProvisioner switch into LambdaAddressingCfnProvisioner,
following the SqsCfnProvisioner pattern. CloudFormationResourceProvisioner is
now byte-identical to main again.

The provisioner implements delete(), so the three resource types no longer
survive stack deletion. Physical ids double as delete handles: a Permission
stores <functionName>|<statementId>, a Version its version-qualified function
ARN, an Alias its alias ARN.

Also fixes two behaviors the switch arms did not cover:

- Alias RoutingConfig.AdditionalVersionWeights is now parsed and passed to
  LambdaService instead of being discarded.
- Stack updates no longer recreate these resources. A Permission replaces its
  previous statement rather than colliding on the duplicate Sid, a Version
  keeps the version it already published, and an Alias updates in place,
  deleting the old alias when a rename retargets it.

Adds LambdaService#deleteVersion (and the matching store method) so a single
published version can be removed without taking $LATEST with it.

* fix(lambda): a rejected permission replacement puts the previous statement back

A stack update re-provisions every resource, and AddPermission rejects a
duplicate Sid, so the provisioner removed the previous statement before adding
its replacement. When the replacement was then rejected the function was left
with neither: CloudFormation reported UPDATE_ROLLBACK_COMPLETE while every
service that could invoke the function before the update had lost access.

The statement is now captured before it is removed and put back if AddPermission
fails, with the restore failure attached as suppressed so the stack still
reports the original error. LambdaService gained restorePermissionStatement for
this, which takes the stored statement shape rather than an AddPermission
request so what goes back is exactly what came out.

* fix(cloudformation): narrow the provisioner to AWS::Lambda::Permission

upstream #1961 added LambdaVersionAliasCfnProvisioner, which claims
AWS::Lambda::Version and AWS::Lambda::Alias. This provisioner claimed the same
two, and the registry rejects a duplicate claim, so every stack rolled back with
"Duplicate CloudFormation provisioner for AWS::Lambda::Version".

Version and Alias provisioning is dropped here in favour of that one, which sets
the same physical id and attributes. What is left is AWS::Lambda::Permission,
which nothing else provisions.

Delete now tolerates a statement or function that is already gone, so a
DeleteStack retry does not fail a resource for work already done.

* fix(cloudformation): a stack update keeps its Lambda version and applies alias routing

Two gaps in LambdaVersionAliasCfnProvisioner, both reachable from a plain
UpdateStack.

provisionVersion called publishVersion unconditionally, so every update minted a
new version and repointed every Ref to it. Version resources are immutable in
CloudFormation, so the version this resource already published is kept while it
still exists, and a new one is published only when it is gone or the
FunctionName property moved to a different function.

RoutingConfig was not carried over, on the grounds that nothing emitted it. The
CloudFormation path does, so AdditionalVersionWeights is parsed and passed to
create and update. A template that declares no RoutingConfig clears the weights
rather than keeping them, which is why the existing alias test now expects an
empty map instead of null.
2026-08-14 20:41:12 -04:00
..