fix(lambda): preserve each MicroVM version build specification (#8600)

Each MicroVM image version now records the build inputs it was created with (code artifact URI, base image ARN and version, build role) as an immutable BuildSpec. GetMicrovmImageVersion and ListMicrovmImageVersions read that snapshot instead of the image's latest inputs, so an update no longer rewrites what older versions report.

Versions stored before this change have no snapshot and fall back to their image's last known inputs; the docs note that their original inputs cannot be recovered.

Closes #7312
This commit is contained in:
galsuchetzky-act authored and GitHub committed 2026-11-16 12:04:42 -04:00
1 parent 975632df5c
commit 06a5ce4219
5 files changed
+151 -7

No files matched your search

+7
View File
@@ -5,6 +5,13 @@
Two AWS service models, not one. `Lambda Microvms` (apiVersion 2025-09-09) carries MicroVM images, versions, builds and MicroVMs. `Lambda Core` (apiVersion 2026-04-30) carries VPC egress network connectors under the `/2026-04-04/` prefix. Both sign as `lambda`, so both are served under Floci's existing lambda service and are enabled by it. Tagging rides the classic `/2017-03-31/tags/` routes.
Image versions retain the code artifact URI, base image ARN and version, and build
role used when they were built. Updating an image changes the latest image inputs
without changing the inputs returned by GetMicrovmImageVersion or ListMicrovmImageVersions
for an older version. Stored versions written before build inputs were snapshotted
remain readable using their parent image's last known inputs; their original build
inputs cannot be reconstructed.
## Supported Actions
### Images, versions and builds
@@ -9,6 +9,7 @@ import io.floci.aws.core.common.AwsArnUtils;
import io.floci.aws.core.common.AwsException;
import io.floci.aws.core.common.EpochSeconds;
import io.floci.aws.core.common.RegionResolver;
import io.floci.aws.services.lambdamicrovms.LambdaMicrovmsService.BuildSpec;
import io.floci.aws.services.lambdamicrovms.LambdaMicrovmsService.Microvm;
import io.floci.aws.services.lambdamicrovms.LambdaMicrovmsService.MicrovmBuild;
import io.floci.aws.services.lambdamicrovms.LambdaMicrovmsService.MicrovmImage;
@@ -399,9 +400,8 @@ public class LambdaMicrovmsController {
}
private ObjectNode versionNode(MicrovmImage image, MicrovmImageVersion version) {
// A version response repeats the parent image's whole build spec. The
// data is all on the image, which this method already receives; it was
// simply never written out.
// Older records have no snapshot, so only their parent's last known inputs remain available.
BuildSpec buildSpec = version.buildSpec != null ? version.buildSpec : BuildSpec.from(image);
ObjectNode node = objectMapper.createObjectNode();
node.put("imageArn", image.imageArn);
node.put("imageVersion", version.imageVersion);
@@ -409,10 +409,10 @@ public class LambdaMicrovmsController {
node.put("status", version.status);
node.put("createdAt", EpochSeconds.fromInstant(version.createdAt));
node.put("updatedAt", EpochSeconds.fromInstant(image.updatedAt));
node.put("baseImageArn", image.baseImageArn);
node.put("baseImageVersion", image.baseImageVersion);
node.put("buildRoleArn", image.buildRoleArn);
node.putObject("codeArtifact").put("uri", image.codeArtifactUri);
node.put("baseImageArn", buildSpec.baseImageArn());
node.put("baseImageVersion", buildSpec.baseImageVersion());
node.put("buildRoleArn", buildSpec.buildRoleArn());
node.putObject("codeArtifact").put("uri", buildSpec.codeArtifactUri());
// A version's description is its own and nothing sets it. It stays null
// even once the parent image has one, which is why it cannot simply be
// read off the image.
@@ -130,6 +130,13 @@ public class LambdaMicrovmsService implements ResourceProvider {
}
}
@RegisterForReflection
public record BuildSpec(String baseImageArn, String baseImageVersion, String buildRoleArn, String codeArtifactUri) {
static BuildSpec from(MicrovmImage image) {
return new BuildSpec(image.baseImageArn, image.baseImageVersion, image.buildRoleArn, image.codeArtifactUri);
}
}
@RegisterForReflection
public static final class MicrovmImage {
public String name;
@@ -155,6 +162,7 @@ public class LambdaMicrovmsService implements ResourceProvider {
public String status;
public Instant createdAt;
public final List<MicrovmBuild> builds = new ArrayList<>();
public BuildSpec buildSpec;
public RuntimeSettings runtimeSettings;
}
@@ -223,6 +231,7 @@ public class LambdaMicrovmsService implements ResourceProvider {
version.state = "SUCCESSFUL";
version.status = "ACTIVE";
version.createdAt = Instant.now();
version.buildSpec = BuildSpec.from(image);
version.runtimeSettings = image.runtimeSettings;
// A version is built once per Graviton generation the service targets,
// newest first. Recorded live: two builds per version, not one.
@@ -0,0 +1,67 @@
package io.floci.aws.services.lambdamicrovms;
import io.floci.aws.testing.PartitionCleanup;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.response.ValidatableResponse;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import java.util.UUID;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.equalTo;
@QuarkusTest
class LambdaMicrovmImageVersionBuildSpecIntegrationTest {
private static final String IMAGES = "/2025-09-09/microvm-images";
@RegisterExtension
final PartitionCleanup cleanup = new PartitionCleanup();
@Test
void getKeepsEachVersionsBuildInputsAfterAnUpdate() {
String name = createAndUpdate();
assertBuildSpec(given().when().get(IMAGES + "/" + name + "/versions/1.0")
.then().statusCode(200), "", "original", "1.0");
assertBuildSpec(given().when().get(IMAGES + "/" + name + "/versions/2.0")
.then().statusCode(200), "", "replacement", "2.0");
}
@Test
void listKeepsEachVersionsBuildInputsAfterAnUpdate() {
String name = createAndUpdate();
ValidatableResponse listed = given().when().get(IMAGES + "/" + name + "/versions")
.then().statusCode(200).body("items.size()", equalTo(2));
assertBuildSpec(listed, "items[0].", "original", "1.0");
assertBuildSpec(listed, "items[1].", "replacement", "2.0");
}
private String createAndUpdate() {
String name = "version-build-spec-" + UUID.randomUUID();
given().contentType("application/json").body("{\"name\":\"" + name + "\"," + fields("original", "1.0") + "}")
.when().post(IMAGES).then().statusCode(201);
cleanup.register(() -> given().when().delete(IMAGES + "/" + name).then().statusCode(200));
ValidatableResponse updated = given().contentType("application/json")
.body("{" + fields("replacement", "2.0") + "}")
.when().put(IMAGES + "/" + name).then().statusCode(200);
assertBuildSpec(updated, "", "replacement", "2.0");
given().when().get(IMAGES + "/" + name).then().statusCode(200)
.body("latestActiveImageVersion", equalTo("2.0"));
return name;
}
private static String fields(String label, String version) {
return "\"baseImageArn\":\"arn:aws:lambda:us-east-1:aws:microvm-image:" + label + "\","
+ "\"baseImageVersion\":\"" + version + "\","
+ "\"buildRoleArn\":\"arn:aws:iam::000000000000:role/" + label + "\","
+ "\"codeArtifact\":{\"uri\":\"s3://artifacts/" + label + ".zip\"}";
}
private static void assertBuildSpec(ValidatableResponse response, String prefix, String label, String version) {
response.body(prefix + "baseImageArn", equalTo("arn:aws:lambda:us-east-1:aws:microvm-image:" + label))
.body(prefix + "baseImageVersion", equalTo(version))
.body(prefix + "buildRoleArn", equalTo("arn:aws:iam::000000000000:role/" + label))
.body(prefix + "codeArtifact.uri", equalTo("s3://artifacts/" + label + ".zip"));
}
}
@@ -13,11 +13,13 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -95,6 +97,65 @@ class LambdaMicrovmsServicePersistenceTest {
assertEquals(image.runtimeSettings, image.versions.get(1).runtimeSettings);
}
@Test
void buildInputsRemainVersionSpecificAfterReload() {
createAndUpdateVersionedImage();
LambdaMicrovmsService reloaded = process();
assertBuildInputs(versionResponse(reloaded, "1.0"), "original", "1.0");
assertBuildInputs(versionResponse(reloaded, "2.0"), "replacement", "2.0");
assertEquals("s3://artifacts/replacement.zip", reloaded.getImage(REGION, "versioned-image").codeArtifactUri);
}
@Test
void legacyVersionsUseLastKnownInputsWithoutRewritingStorage() throws IOException {
createAndUpdateVersionedImage();
Path file = storageDir.resolve("lambda-microvm-images.json");
ObjectMapper mapper = new ObjectMapper();
JsonNode stored = mapper.readTree(file.toFile());
for (JsonNode versions : stored.findValues("versions")) {
for (JsonNode version : versions) {
((ObjectNode) version).remove("buildSpec");
}
}
mapper.writeValue(file.toFile(), stored);
String beforeRead = Files.readString(file);
JsonNode response = versionResponse(process(), "1.0");
assertEquals("1.0", response.path("imageVersion").asText());
assertBuildInputs(response, "replacement", "2.0");
assertEquals(beforeRead, Files.readString(file));
}
private void createAndUpdateVersionedImage() {
LambdaMicrovmsService service = process();
service.createImage(REGION, ACCOUNT_ID, "versioned-image",
"arn:aws:lambda:us-east-1:aws:microvm-image:original",
"arn:aws:iam::000000000000:role/original", "s3://artifacts/original.zip", null,
"1.0", LambdaMicrovmsService.RuntimeSettings.defaults(), Map.of());
service.updateImage(REGION, "versioned-image",
"arn:aws:lambda:us-east-1:aws:microvm-image:replacement",
"arn:aws:iam::000000000000:role/replacement", "s3://artifacts/replacement.zip", null,
"2.0", LambdaMicrovmsService.RuntimeSettings.defaults());
}
private static JsonNode versionResponse(LambdaMicrovmsService service, String version) {
RegionResolver resolver = mock(RegionResolver.class);
when(resolver.resolveRegion(null)).thenReturn(REGION);
LambdaMicrovmsController controller = new LambdaMicrovmsController(service, resolver, new ObjectMapper());
return (JsonNode) controller.getVersion(null, "versioned-image", version).getEntity();
}
private static void assertBuildInputs(JsonNode response, String label, String baseVersion) {
assertAll(
() -> assertEquals("arn:aws:lambda:us-east-1:aws:microvm-image:" + label,
response.path("baseImageArn").asText()),
() -> assertEquals(baseVersion, response.path("baseImageVersion").asText()),
() -> assertEquals("arn:aws:iam::000000000000:role/" + label,
response.path("buildRoleArn").asText()),
() -> assertEquals("s3://artifacts/" + label + ".zip", response.path("codeArtifact").path("uri").asText()));
}
@Test
void anInPlaceUpdateReachesTheBackend() {
// updateImage mutates the stored image rather than replacing it, so without an explicit