fix(lambda): carry the owning account into published version snapshots (#2041)

PublishVersion builds its snapshot field by field and left accountId unset, so
every published version reported a null owning account while $LATEST reported
the real one for the same function. Consumers that key off the account then have
to re-derive it from the function ARN or fall back to a default: codeObjectKey
substitutes 000000000000 for a null account, and anything keying IAM state on
the function account has nothing to key on.

Copy accountId alongside the other snapshot fields so a version carries the same
owning account as the function it was published from. The account was never
lost, the version ARN already embeds it, it just was not on the model.

Fixes #2040
This commit is contained in:
TiM authored and GitHub committed 2026-08-01 15:31:29 -05:00
1 parent aadc93e306
commit f4e8bd8edf
2 files changed
+16

No files matched your search

@@ -928,6 +928,7 @@ public class LambdaService {
functionName = fn.getFunctionName();
int version = nextVersionNumber(region + "::" + functionName);
LambdaFunction snapshot = new LambdaFunction();
snapshot.setAccountId(fn.getAccountId());
snapshot.setFunctionName(fn.getFunctionName());
snapshot.setVersion(String.valueOf(version));
snapshot.setFunctionArn(fn.getFunctionArn().replace(":$LATEST", "") + ":" + version);
@@ -241,6 +241,21 @@ class LambdaServiceTest {
return Base64.getEncoder().encodeToString(baos.toByteArray());
}
@Test
void publishVersionCarriesTheOwningAccount() {
service.createFunction(REGION, baseRequest("account-versioned-fn"));
LambdaFunction version = service.publishVersion(REGION, "account-versioned-fn", null);
// A version snapshot is built field by field, so anything reading accountId off it (the
// deployment-package key, execution-role session ownership) otherwise has to re-derive the
// account from the ARN or fall back to the default account.
assertEquals("000000000000", version.getAccountId());
assertEquals(
service.getFunction(REGION, "account-versioned-fn").getAccountId(),
version.getAccountId());
}
@Test
void createFunctionWithSubdirectoryHandler() throws Exception {
Map<String, Object> req = new java.util.HashMap<>(Map.of(