Files
floci/compatibility-tests/sdk-test-awscli/test/lambda-microvms.bats
T
lex00 40e8aad55a feat(lambdamicrovms): AWS Lambda MicroVMs service module and its CloudFormation types (#2079)
* feat(lambdamicrovms): AWS Lambda MicroVMs service module

Adds the Lambda MicroVMs control plane, a service AWS took GA on 2026-06-22:
MicroVM images with a version and build lifecycle, the managed base-image
catalog, MicroVM CRUD, and VPC egress network connectors.

Two service models rather than one. Lambda Microvms (apiVersion 2025-09-09)
carries images and MicroVMs under /2025-09-09; Lambda Core (2026-04-30)
carries network connectors under /2026-04-04. Both sign as lambda, so their
requests arrive under the existing lambda claim in ResolvedServiceCatalog and
route by path. Neither prefix collides with anything LambdaController serves,
and both are enabled by the lambda service rather than adding a toggle.
Tagging rides the classic /2017-03-31/tags/ routes, so LambdaTagController
learns the MicroVM ARN forms.

Resources are stored per account and region. Floci resolves a per-request
account in AccountContextFilter and these ARNs carry it, so region-only
storage would let two accounts sharing a region read and mutate each other's
images, MicroVMs and connectors.

Wire shapes come from the vendored service models and, where the models are
silent or disagree with the service, from responses recorded against live
AWS. Several members the models mark optional are enforced in practice — a
connector needs ClientToken, OperatorRole, NetworkProtocol and
AssociatedComputeResourceTypes despite all four being optional in Smithy — and
several resources are returned in a different projection per operation: an
image in four shapes, a connector in four, with only the list summaries
carrying Type.

Builds converge instantly rather than on a timer, the usual emulator trade.
Where that would otherwise produce an inconsistent body it is handled
explicitly: a create or update reports the transitional state and does not
name the version it is minting as active, because a client reading otherwise
would launch a MicroVM off a version that does not exist yet.

Auth tokens, the per-VM endpoint, and the idle and suspend timers are
deliberately out of scope here; they belong to a full-fidelity MicroVMs
emulator rather than to CloudFormation provisioning.

Verified against a suite of responses recorded from live AWS
(https://github.com/INTENTIUS/m80): 26 checks over the image, MicroVM and
connector lifecycles, 0 failures.

* feat(cloudformation): provision AWS::Lambda::MicrovmImage and AWS::Lambda::NetworkConnector

Registers a CfnResourceProvisioner for the two MicroVM CloudFormation types
against the LambdaMicrovmsService added alongside, so a template declaring
either provisions and deletes rather than being skipped.

Uses the CloudFormationResourceRegistry interface rather than the switch in
CloudFormationResourceProvisioner, following SqsCfnProvisioner.

* test(lambdamicrovms): AWS CLI compatibility coverage for images, MicroVMs and connectors

* fix(lambdamicrovms): wire service state through StorageFactory

Images, MicroVMs and connectors were held in plain in-memory maps, so in
persistent mode a restarted Floci lost them while the CloudFormation stacks that
created them survived. Those stacks then referenced resources that no longer
existed and DeleteStack failed on the 404.

The three stores are now StorageBackedMap over StorageFactory backends, keyed
region/id. MicroVMs are delivered as part of the lambda service, so they share
its storage key and therefore its configured mode and flush interval rather than
declaring their own. The account half of the key is dropped from the service and
left to the backend, which prefixes and strips the same account the
RegionResolver returns, so region and account isolation are unchanged.

StorageBackedMap only marks the backend dirty on put and remove, so every path
that mutated a stored object in place now writes it back: image update, version
status, version delete, rebuild, MicroVM settle and terminate, connector settle
and update, and both tag paths.

* style(core): import the lambda microvms controllers in the service catalog

* fix(lambdamicrovms): register the persisted types for reflection

Moving images, microvms and connectors into StorageBackedMap made their model
classes persisted types, and PersistedModelReflectionTest fails on any that lack
@RegisterForReflection because native-image persistence cannot rebuild them on
restart.
2026-08-10 23:10:48 -05:00

257 lines
8.6 KiB
Bash

#!/usr/bin/env bats
# Lambda MicroVMs integration tests
#
# Two AWS service models sit behind these commands: `lambda-microvms` (images
# and MicroVMs) and `lambda-core` (network connectors). Both sign as lambda.
setup() {
load 'test_helper/common-setup'
IMAGE_NAME=""
MICROVM_ID=""
CONNECTOR_ID=""
BASE_IMAGE_ARN="arn:aws:lambda:us-east-1:aws:microvm-image:al2023-1"
BUILD_ROLE_ARN="arn:aws:iam::000000000000:role/microvm-build"
}
teardown() {
if [ -n "$MICROVM_ID" ]; then
aws_cmd lambda-microvms terminate-microvm --microvm-identifier "$MICROVM_ID" >/dev/null 2>&1 || true
fi
if [ -n "$IMAGE_NAME" ]; then
aws_cmd lambda-microvms delete-microvm-image --image-identifier "$IMAGE_NAME" >/dev/null 2>&1 || true
fi
if [ -n "$CONNECTOR_ID" ]; then
aws_cmd lambda-core delete-network-connector --id "$CONNECTOR_ID" >/dev/null 2>&1 || true
fi
}
create_image() {
local name="$1"
aws_cmd lambda-microvms create-microvm-image \
--name "$name" \
--base-image-arn "$BASE_IMAGE_ARN" \
--build-role-arn "$BUILD_ROLE_ARN" \
--code-artifact "uri=s3://bucket/code.zip"
}
# ============================================
# Image lifecycle
# ============================================
@test "MicroVMs: create image" {
IMAGE_NAME=$(unique_name "cli-img")
run create_image "$IMAGE_NAME"
assert_success
name=$(json_get "$output" '.name')
state=$(json_get "$output" '.state')
version=$(json_get "$output" '.imageVersion')
arn=$(json_get "$output" '.imageArn')
[ "$name" = "$IMAGE_NAME" ]
[ "$state" = "CREATING" ]
[ "$version" = "1.0" ]
[[ "$arn" =~ ^arn:aws:lambda: ]]
}
@test "MicroVMs: image settles to CREATED with an active version" {
IMAGE_NAME=$(unique_name "cli-img")
create_image "$IMAGE_NAME" >/dev/null
run aws_cmd lambda-microvms get-microvm-image --image-identifier "$IMAGE_NAME"
assert_success
state=$(json_get "$output" '.state')
latest=$(json_get "$output" '.latestActiveImageVersion')
[ "$state" = "CREATED" ]
[ "$latest" = "1.0" ]
}
@test "MicroVMs: list images includes the created image" {
IMAGE_NAME=$(unique_name "cli-img")
create_image "$IMAGE_NAME" >/dev/null
run aws_cmd lambda-microvms list-microvm-images
assert_success
assert_output --partial "$IMAGE_NAME"
}
@test "MicroVMs: version and build converge to SUCCESSFUL" {
IMAGE_NAME=$(unique_name "cli-img")
create_image "$IMAGE_NAME" >/dev/null
run aws_cmd lambda-microvms list-microvm-image-builds \
--image-identifier "$IMAGE_NAME" --image-version 1.0
assert_success
build_id=$(json_get "$output" '.items[0].buildId')
build_state=$(json_get "$output" '.items[0].buildState')
[ "$build_state" = "SUCCESSFUL" ]
[ -n "$build_id" ]
run aws_cmd lambda-microvms get-microvm-image-build \
--image-identifier "$IMAGE_NAME" --image-version 1.0 --build-id "$build_id"
assert_success
arch=$(json_get "$output" '.architecture')
[ "$arch" = "ARM_64" ]
run aws_cmd lambda-microvms get-microvm-image-version \
--image-identifier "$IMAGE_NAME" --image-version 1.0
assert_success
status=$(json_get "$output" '.status')
[ "$status" = "ACTIVE" ]
}
@test "MicroVMs: invalid image name is rejected" {
run create_image "bad name!"
assert_failure
assert_output --partial "ValidationException"
}
@test "MicroVMs: get a nonexistent image returns not found" {
run aws_cmd lambda-microvms get-microvm-image --image-identifier "cli-no-such-image"
assert_failure
assert_output --partial "ResourceNotFound"
}
@test "MicroVMs: managed catalog lists a base image" {
run aws_cmd lambda-microvms list-managed-microvm-images
assert_success
arn=$(json_get "$output" '.items[0].imageArn')
[ -n "$arn" ]
}
# ============================================
# MicroVM lifecycle
# ============================================
@test "MicroVMs: run a MicroVM and read it back running" {
IMAGE_NAME=$(unique_name "cli-img")
create_image "$IMAGE_NAME" >/dev/null
run aws_cmd lambda-microvms run-microvm --image-identifier "$IMAGE_NAME"
assert_success
MICROVM_ID=$(json_get "$output" '.microvmId')
state=$(json_get "$output" '.state')
duration=$(json_get "$output" '.maximumDurationInSeconds')
[[ "$MICROVM_ID" =~ ^microvm- ]]
[ "$state" = "PENDING" ]
[ "$duration" = "28800" ]
run aws_cmd lambda-microvms get-microvm --microvm-identifier "$MICROVM_ID"
assert_success
state=$(json_get "$output" '.state')
[ "$state" = "RUNNING" ]
}
@test "MicroVMs: run against a missing image returns not found" {
run aws_cmd lambda-microvms run-microvm --image-identifier "cli-no-such-image"
assert_failure
assert_output --partial "ResourceNotFound"
}
@test "MicroVMs: an image with a running MicroVM refuses delete" {
IMAGE_NAME=$(unique_name "cli-img")
create_image "$IMAGE_NAME" >/dev/null
out=$(aws_cmd lambda-microvms run-microvm --image-identifier "$IMAGE_NAME")
MICROVM_ID=$(json_get "$out" '.microvmId')
run aws_cmd lambda-microvms delete-microvm-image --image-identifier "$IMAGE_NAME"
assert_failure
assert_output --partial "running microvms"
}
@test "MicroVMs: terminate is idempotent only once" {
IMAGE_NAME=$(unique_name "cli-img")
create_image "$IMAGE_NAME" >/dev/null
out=$(aws_cmd lambda-microvms run-microvm --image-identifier "$IMAGE_NAME")
microvm_id=$(json_get "$out" '.microvmId')
run aws_cmd lambda-microvms terminate-microvm --microvm-identifier "$microvm_id"
assert_success
run aws_cmd lambda-microvms get-microvm --microvm-identifier "$microvm_id"
assert_success
state=$(json_get "$output" '.state')
[ "$state" = "TERMINATED" ]
# Terminal-state mutations are a ValidationException, not a second success.
run aws_cmd lambda-microvms terminate-microvm --microvm-identifier "$microvm_id"
assert_failure
assert_output --partial "state cannot be changed"
}
# ============================================
# Tagging
# ============================================
@test "MicroVMs: tag, read and untag an image ARN" {
IMAGE_NAME=$(unique_name "cli-img")
out=$(create_image "$IMAGE_NAME")
image_arn=$(json_get "$out" '.imageArn')
run aws_cmd lambda-microvms tag-resource --resource "$image_arn" --tags team=conformance
assert_success
run aws_cmd lambda-microvms list-tags --resource "$image_arn"
assert_success
team=$(json_get "$output" '.Tags.team')
[ "$team" = "conformance" ]
run aws_cmd lambda-microvms untag-resource --resource "$image_arn" --tag-keys team
assert_success
run aws_cmd lambda-microvms list-tags --resource "$image_arn"
assert_success
team=$(json_get "$output" '.Tags.team')
[ "$team" = "null" ] || [ -z "$team" ]
}
# ============================================
# Network connectors (lambda-core)
# ============================================
@test "MicroVMs: network connector lifecycle" {
name=$(unique_name "cli-conn")
run aws_cmd lambda-core create-network-connector \
--name "$name" \
--operator-role "arn:aws:iam::000000000000:role/microvm-connector-operator" \
--configuration "VpcEgressConfiguration={AssociatedComputeResourceTypes=MicroVm,NetworkProtocol=IPv4,SubnetIds=subnet-0000000000000cli1,SecurityGroupIds=sg-0000000000000cli1}"
assert_success
CONNECTOR_ID=$(json_get "$output" '.Id')
state=$(json_get "$output" '.State')
[ -n "$CONNECTOR_ID" ]
[ "$state" = "PENDING" ]
run aws_cmd lambda-core get-network-connector --id "$CONNECTOR_ID"
assert_success
state=$(json_get "$output" '.State')
got_name=$(json_get "$output" '.Name')
[ "$state" = "ACTIVE" ]
[ "$got_name" = "$name" ]
run aws_cmd lambda-core list-network-connectors
assert_success
assert_output --partial "$CONNECTOR_ID"
run aws_cmd lambda-core delete-network-connector --id "$CONNECTOR_ID"
assert_success
CONNECTOR_ID=""
}
@test "MicroVMs: get a nonexistent connector returns not found" {
run aws_cmd lambda-core get-network-connector --id "nc-00000000000000cli"
assert_failure
assert_output --partial "ResourceNotFound"
}
# ============================================
# Region isolation
# ============================================
@test "MicroVMs: an image created in one region is not visible in another" {
IMAGE_NAME=$(unique_name "cli-img")
create_image "$IMAGE_NAME" >/dev/null
run aws --endpoint-url "$FLOCI_ENDPOINT" --region eu-west-1 --output json \
lambda-microvms get-microvm-image --image-identifier "$IMAGE_NAME" 2>&1
assert_failure
assert_output --partial "ResourceNotFound"
}