feat(lambda): support EFS file system configs (#2053)

* feat(lambda): support EFS file system configs

* fix(lambda): prevent stale and shared EFS mounts

* fix(lambda): isolate warm pools by version

* test(dynamodb): retain Quarkus port for cleanup

* fix(lambda): scope warm pool invalidation by environment

---------

Co-authored-by: Alexander Banna <abanna@users.noreply.github.com>
This commit is contained in:
Alex BannaandAlexander Banna authored and GitHub committed 2026-08-12 16:12:39 -04:00
1 parent ea74b979ae
commit e1f389f61b
18 files changed
+991 -46

No files matched your search

@@ -882,6 +882,144 @@ class CloudFormationIntegrationTest {
""".formatted(functionName);
}
@Test
void updateStack_lambdaFileSystemConfigUpdatesInPlace() {
String stackName = "cfn-lambda-efs-config-stack";
String functionName = "cfn-lambda-efs-config-func";
String accessPointArn =
"arn:aws:elasticfilesystem:us-east-1:000000000000:access-point/fsap-0123456789abcdef0";
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "CreateStack")
.formParam("StackName", stackName)
.formParam("TemplateBody", lambdaFileSystemTemplate(functionName, accessPointArn, true))
.when()
.post("/")
.then()
.statusCode(200);
given()
.when()
.get("/2015-03-31/functions/" + functionName)
.then()
.statusCode(200)
.body("Configuration.FileSystemConfigs[0].Arn", equalTo(accessPointArn))
.body("Configuration.FileSystemConfigs[0].LocalMountPath", equalTo("/mnt/shared"));
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "UpdateStack")
.formParam("StackName", stackName)
.formParam("TemplateBody", lambdaFileSystemTemplate(functionName, accessPointArn, false))
.when()
.post("/")
.then()
.statusCode(200);
String resourceXml = given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "DescribeStackResources")
.formParam("StackName", stackName)
.when()
.post("/")
.then()
.statusCode(200)
.extract().asString();
assertThat(firstPhysicalResourceId(resourceXml), equalTo(functionName));
given()
.when()
.get("/2015-03-31/functions/" + functionName)
.then()
.statusCode(200)
.body("Configuration.FileSystemConfigs", nullValue());
}
@Test
void createStack_lambdaFileSystemConfigsMustBeAList() {
String stackName = "cfn-lambda-invalid-efs-config-stack";
String template = """
{
"Resources": {
"MyFunction": {
"Type": "AWS::Lambda::Function",
"Properties": {
"FunctionName": "cfn-lambda-invalid-efs-config",
"Runtime": "nodejs20.x",
"Handler": "index.handler",
"Role": "arn:aws:iam::000000000000:role/cfn-test-lambda-role",
"Code": {
"ZipFile": "exports.handler = async () => ({ statusCode: 200 });"
},
"VpcConfig": {
"SubnetIds": ["subnet-12345678"],
"SecurityGroupIds": ["sg-12345678"]
},
"FileSystemConfigs": {
"Arn": "arn:aws:elasticfilesystem:us-east-1:000000000000:access-point/fsap-0123456789abcdef0",
"LocalMountPath": "/mnt/shared"
}
}
}
}
}
""";
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "CreateStack")
.formParam("StackName", stackName)
.formParam("TemplateBody", template)
.when()
.post("/")
.then()
.statusCode(200);
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "DescribeStackEvents")
.formParam("StackName", stackName)
.when()
.post("/")
.then()
.statusCode(200)
.body(containsString("ROLLBACK_COMPLETE"))
.body(containsString("FileSystemConfigs must be a list"));
}
private static String lambdaFileSystemTemplate(String functionName, String accessPointArn,
boolean includeFileSystem) {
String fileSystemConfig = includeFileSystem
? """
,"FileSystemConfigs": [{
"Arn": "%s",
"LocalMountPath": "/mnt/shared"
}]
""".formatted(accessPointArn)
: "";
return """
{
"Resources": {
"MyFunction": {
"Type": "AWS::Lambda::Function",
"Properties": {
"FunctionName": "%s",
"Runtime": "nodejs20.x",
"Handler": "index.handler",
"Role": "arn:aws:iam::000000000000:role/cfn-test-lambda-role",
"VpcConfig": {
"SubnetIds": ["subnet-0123456789abcdef0"],
"SecurityGroupIds": ["sg-0123456789abcdef0"]
}
%s
}
}
}
}
""".formatted(functionName, fileSystemConfig);
}
@Test
void createStack_kmsKeyWithOverrideTagUsesPinnedId() {
String template = """
@@ -136,6 +136,46 @@ class SamTransformProcessorTest {
assertTrue(lambdaProps.path("Runtime").isMissingNode());
}
@Test
void expandSamTemplate_functionWithFileSystemConfig() throws Exception {
JsonNode template = objectMapper.readTree("""
{
"Transform": "AWS::Serverless-2016-10-31",
"Resources": {
"MyFunc": {
"Type": "AWS::Serverless::Function",
"Properties": {
"Handler": "index.handler",
"Runtime": "nodejs20.x",
"InlineCode": "exports.handler = async () => ({});",
"VpcConfig": {
"SubnetIds": ["subnet-0123456789abcdef0"],
"SecurityGroupIds": ["sg-0123456789abcdef0"]
},
"FileSystemConfigs": [{
"Arn": "arn:aws:elasticfilesystem:us-east-1:000000000000:access-point/fsap-0123456789abcdef0",
"LocalMountPath": "/mnt/shared"
}]
}
}
}
}
""");
JsonNode lambdaProps = processor.expandSamTemplate(template)
.path("Resources").path("MyFunc").path("Properties");
assertEquals("subnet-0123456789abcdef0",
lambdaProps.path("VpcConfig").path("SubnetIds").get(0).asText());
assertEquals("sg-0123456789abcdef0",
lambdaProps.path("VpcConfig").path("SecurityGroupIds").get(0).asText());
assertEquals("arn:aws:elasticfilesystem:us-east-1:000000000000:"
+ "access-point/fsap-0123456789abcdef0",
lambdaProps.path("FileSystemConfigs").get(0).path("Arn").asText());
assertEquals("/mnt/shared",
lambdaProps.path("FileSystemConfigs").get(0).path("LocalMountPath").asText());
}
@Test
void expandSamTemplate_functionWithImageConfig() throws Exception {
// ImageConfig (EntryPoint/Command/WorkingDirectory overrides for a container-image
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.RestAssured;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.MethodOrderer;
@@ -28,6 +29,7 @@ class DynamoDbProjectionIntegrationTest {
private static final String CT = "application/x-amz-json-1.0";
private static final String TABLE = "ProjectionBugTable";
private static int testPort;
@BeforeAll
static void configureRestAssured() {
@@ -37,6 +39,7 @@ class DynamoDbProjectionIntegrationTest {
@Test
@Order(1)
void createTable() {
testPort = RestAssured.port;
given()
.header("X-Amz-Target", "DynamoDB_20120810.CreateTable")
.contentType(CT)
@@ -169,8 +172,8 @@ class DynamoDbProjectionIntegrationTest {
@AfterAll
static void cleanup() {
try {
given()
given()
.port(testPort)
.header("X-Amz-Target", "DynamoDB_20120810.DeleteTable")
.contentType(CT)
.body("""
@@ -180,7 +183,6 @@ class DynamoDbProjectionIntegrationTest {
.post("/")
.then()
.statusCode(200);
} catch (Exception ignored) {}
}
/**
@@ -4,6 +4,7 @@ import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
import io.github.hectorvent.floci.services.lambda.model.LambdaFileSystemConfig;
import io.github.hectorvent.floci.services.lambda.model.LambdaFunction;
import io.github.hectorvent.floci.services.lambda.zip.CodeStore;
import io.github.hectorvent.floci.services.lambda.zip.ZipExtractor;
@@ -49,6 +50,12 @@ class LambdaServiceTest {
));
}
private static Map<String, Object> vpcConfig() {
return Map.of(
"SubnetIds", List.of("subnet-0123456789abcdef0"),
"SecurityGroupIds", List.of("sg-0123456789abcdef0"));
}
@Test
void createFunctionSucceeds() {
LambdaFunction fn = service.createFunction(REGION, baseRequest("my-function"));
@@ -64,6 +71,151 @@ class LambdaServiceTest {
assertNotNull(fn.getRevisionId());
}
@Test
void createAndUpdateFunctionFileSystemConfig() {
Map<String, Object> request = baseRequest("efs-function");
request.put("VpcConfig", vpcConfig());
request.put("FileSystemConfigs", List.of(Map.of(
"Arn", "arn:aws:elasticfilesystem:us-east-1:000000000000:access-point/fsap-0123456789abcdef0",
"LocalMountPath", "/mnt/shared")));
LambdaFunction created = service.createFunction(REGION, request);
assertEquals(1, created.getFileSystemConfigs().size());
assertEquals("arn:aws:elasticfilesystem:us-east-1:000000000000:access-point/fsap-0123456789abcdef0",
created.getFileSystemConfigs().getFirst().getArn());
assertEquals("/mnt/shared", created.getFileSystemConfigs().getFirst().getLocalMountPath());
LambdaFunction updated = service.updateFunctionConfiguration(REGION, "efs-function",
Map.of("FileSystemConfigs", List.of()));
assertTrue(updated.getFileSystemConfigs().isEmpty());
}
@Test
void publishedVersionKeepsFileSystemConfigSnapshot() {
Map<String, Object> request = baseRequest("versioned-efs-function");
request.put("VpcConfig", vpcConfig());
request.put("FileSystemConfigs", List.of(Map.of(
"Arn", "arn:aws:elasticfilesystem:us-east-1:000000000000:access-point/fsap-0123456789abcdef0",
"LocalMountPath", "/mnt/shared")));
service.createFunction(REGION, request);
LambdaFunction version = service.publishVersion(REGION, "versioned-efs-function", null);
service.updateFunctionConfiguration(REGION, "versioned-efs-function",
Map.of(
"FileSystemConfigs", List.of(),
"VpcConfig", Map.of(
"SubnetIds", List.of("subnet-updated"),
"SecurityGroupIds", List.of("sg-updated"))));
assertEquals(vpcConfig(), version.getVpcConfig());
assertEquals(1, version.getFileSystemConfigs().size());
LambdaFileSystemConfig fileSystem = version.getFileSystemConfigs().getFirst();
assertEquals("arn:aws:elasticfilesystem:us-east-1:000000000000:access-point/fsap-0123456789abcdef0",
fileSystem.getArn());
assertEquals("/mnt/shared", fileSystem.getLocalMountPath());
}
@Test
void createFunctionRejectsInvalidFileSystemMountPath() {
Map<String, Object> request = baseRequest("invalid-efs-function");
request.put("FileSystemConfigs", List.of(Map.of(
"Arn", "arn:aws:elasticfilesystem:us-east-1:000000000000:access-point/fsap-0123456789abcdef0",
"LocalMountPath", "/tmp/shared")));
AwsException error = assertThrows(AwsException.class,
() -> service.createFunction(REGION, request));
assertEquals("InvalidParameterValueException", error.getErrorCode());
}
@Test
void createFunctionRejectsInvalidFileSystemAccessPointArn() {
Map<String, Object> request = baseRequest("invalid-efs-arn-function");
request.put("FileSystemConfigs", List.of(Map.of(
"Arn", "arn:aws:elasticfilesystem:us-east-1:000000000000:file-system/fs-0123456789abcdef0",
"LocalMountPath", "/mnt/shared")));
AwsException error = assertThrows(AwsException.class,
() -> service.createFunction(REGION, request));
assertEquals("InvalidParameterValueException", error.getErrorCode());
}
@Test
void createFunctionRejectsMoreThanOneFileSystemConfig() {
Map<String, Object> request = baseRequest("too-many-efs-function");
request.put("FileSystemConfigs", List.of(
Map.of(
"Arn", "arn:aws:elasticfilesystem:us-east-1:000000000000:access-point/fsap-0123456789abcdef0",
"LocalMountPath", "/mnt/shared"),
Map.of(
"Arn", "arn:aws:elasticfilesystem:us-east-1:000000000000:access-point/fsap-0123456789abcdef1",
"LocalMountPath", "/mnt/other")));
AwsException error = assertThrows(AwsException.class,
() -> service.createFunction(REGION, request));
assertEquals("InvalidParameterValueException", error.getErrorCode());
}
@Test
void createFunctionRejectsUnsupportedS3FilesAccessPointArn() {
Map<String, Object> request = baseRequest("s3-files-function");
String arn = "arn:aws:s3files:us-east-1:000000000000:"
+ "file-system/fs-0123456789abcdef0/access-point/fsap-0123456789abcdef0";
request.put("FileSystemConfigs", List.of(Map.of(
"Arn", arn,
"LocalMountPath", "/mnt/shared")));
AwsException error = assertThrows(AwsException.class,
() -> service.createFunction(REGION, request));
assertEquals("InvalidParameterValueException", error.getErrorCode());
}
@Test
void createFunctionRejectsFileSystemConfigWithoutVpcConfig() {
Map<String, Object> request = baseRequest("efs-without-vpc-function");
request.put("FileSystemConfigs", List.of(Map.of(
"Arn", "arn:aws:elasticfilesystem:us-east-1:000000000000:access-point/fsap-0123456789abcdef0",
"LocalMountPath", "/mnt/shared")));
AwsException error = assertThrows(AwsException.class,
() -> service.createFunction(REGION, request));
assertEquals("InvalidParameterValueException", error.getErrorCode());
}
@Test
void updateFunctionAcceptsVpcAndFileSystemConfigTogether() {
service.createFunction(REGION, baseRequest("update-efs-function"));
LambdaFunction updated = service.updateFunctionConfiguration(REGION, "update-efs-function",
Map.of(
"VpcConfig", vpcConfig(),
"FileSystemConfigs", List.of(Map.of(
"Arn", "arn:aws:elasticfilesystem:us-east-1:000000000000:"
+ "access-point/fsap-0123456789abcdef0",
"LocalMountPath", "/mnt/shared"))));
assertEquals(1, updated.getFileSystemConfigs().size());
assertEquals(vpcConfig(), updated.getVpcConfig());
}
@Test
void updateFunctionRejectsRemovingVpcWhileFileSystemConfigRemains() {
Map<String, Object> request = baseRequest("update-efs-vpc-function");
request.put("VpcConfig", vpcConfig());
request.put("FileSystemConfigs", List.of(Map.of(
"Arn", "arn:aws:elasticfilesystem:us-east-1:000000000000:access-point/fsap-0123456789abcdef0",
"LocalMountPath", "/mnt/shared")));
service.createFunction(REGION, request);
AwsException error = assertThrows(AwsException.class,
() -> service.updateFunctionConfiguration(REGION, "update-efs-vpc-function",
Map.of("VpcConfig", Map.of(
"SubnetIds", List.of(),
"SecurityGroupIds", List.of()))));
assertEquals("InvalidParameterValueException", error.getErrorCode());
assertEquals(vpcConfig(), service.getFunction(REGION, "update-efs-vpc-function").getVpcConfig());
}
@Test
void createFunctionFailsWhenMissingFunctionName() {
Map<String, Object> req = baseRequest("x");
@@ -11,9 +11,16 @@ import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertNotSame;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.lenient;
import static org.mockito.Mockito.mock;
@@ -233,6 +240,82 @@ class WarmPoolTest {
pool.shutdown();
}
@Test
void versionsUseSeparateWarmPools() {
WarmPool pool = buildPool();
pool.init();
LambdaFunction latest = mock(LambdaFunction.class);
LambdaFunction version = mock(LambdaFunction.class);
when(latest.getFunctionName()).thenReturn("versioned-fn");
when(version.getFunctionName()).thenReturn("versioned-fn");
when(latest.getFunctionArn())
.thenReturn("arn:aws:lambda:us-east-1:000000000000:function:versioned-fn");
when(version.getFunctionArn())
.thenReturn("arn:aws:lambda:us-east-1:000000000000:function:versioned-fn:1");
ContainerHandle latestHandle = new ContainerHandle(
"cid-latest", "versioned-fn", null, ContainerState.WARM);
ContainerHandle versionHandle = new ContainerHandle(
"cid-version", "versioned-fn", null, ContainerState.WARM);
when(containerLauncher.launch(any())).thenReturn(latestHandle, versionHandle);
when(containerLauncher.isAlive(latestHandle)).thenReturn(true);
when(containerLauncher.isAlive(versionHandle)).thenReturn(true);
pool.release(pool.acquire(latest));
ContainerHandle firstVersion = pool.acquire(version);
assertSame(versionHandle, firstVersion);
verify(containerLauncher, times(2)).launch(any());
pool.release(firstVersion);
ContainerHandle reacquiredLatest = pool.acquire(latest);
ContainerHandle reacquiredVersion = pool.acquire(version);
assertSame(latestHandle, reacquiredLatest);
assertSame(versionHandle, reacquiredVersion);
verify(containerLauncher, times(2)).launch(any());
pool.release(reacquiredLatest);
pool.release(reacquiredVersion);
pool.shutdown();
}
@Test
void drainingLatestPreservesPublishedVersionPool() {
WarmPool pool = buildPool();
pool.init();
LambdaFunction latest = mock(LambdaFunction.class);
LambdaFunction version = mock(LambdaFunction.class);
when(latest.getFunctionName()).thenReturn("versioned-drain-fn");
when(version.getFunctionName()).thenReturn("versioned-drain-fn");
when(latest.getFunctionArn())
.thenReturn("arn:aws:lambda:us-east-1:000000000000:function:versioned-drain-fn");
when(version.getFunctionArn())
.thenReturn("arn:aws:lambda:us-east-1:000000000000:function:versioned-drain-fn:1");
ContainerHandle latestHandle = new ContainerHandle(
"cid-drain-latest", "versioned-drain-fn", null, ContainerState.WARM);
ContainerHandle versionHandle = new ContainerHandle(
"cid-drain-version", "versioned-drain-fn", null, ContainerState.WARM);
ContainerHandle refreshedLatest = new ContainerHandle(
"cid-drain-latest-fresh", "versioned-drain-fn", null, ContainerState.WARM);
when(containerLauncher.launch(any())).thenReturn(latestHandle, versionHandle, refreshedLatest);
when(containerLauncher.isAlive(versionHandle)).thenReturn(true);
pool.release(pool.acquire(latest));
pool.release(pool.acquire(version));
pool.drainEnvironment(latest);
verify(containerLauncher).stop(latestHandle);
verify(containerLauncher, never()).stop(versionHandle);
assertSame(versionHandle, pool.acquire(version));
assertSame(refreshedLatest, pool.acquire(latest));
verify(containerLauncher, times(3)).launch(any());
pool.shutdown();
}
@Test
void acquire_discardsDeadPooledHandleAndColdStarts() {
WarmPool pool = buildPool();
@@ -298,4 +381,74 @@ class WarmPoolTest {
pool.shutdown();
}
@Test
void releaseAfterDrainStopsStaleHandleAndColdStarts() {
WarmPool pool = buildPool();
pool.init();
LambdaFunction fn = mock(LambdaFunction.class);
when(fn.getFunctionName()).thenReturn("updated-fn");
ContainerHandle stale = new ContainerHandle(
"cid-stale", "updated-fn", null, ContainerState.WARM);
ContainerHandle fresh = new ContainerHandle(
"cid-fresh", "updated-fn", null, ContainerState.WARM);
when(containerLauncher.launch(any())).thenReturn(stale, fresh);
ContainerHandle acquired = pool.acquire(fn);
pool.drainFunction("updated-fn");
pool.release(acquired);
verify(containerLauncher).stop(stale);
assertSame(fresh, pool.acquire(fn));
verify(containerLauncher, times(2)).launch(any());
pool.shutdown();
}
@Test
void launchCrossingDrainIsNeverReturnedToPool() throws Exception {
WarmPool pool = buildPool();
pool.init();
LambdaFunction fn = mock(LambdaFunction.class);
when(fn.getFunctionName()).thenReturn("racing-fn");
ContainerHandle stale = new ContainerHandle(
"cid-racing-stale", "racing-fn", null, ContainerState.WARM);
ContainerHandle fresh = new ContainerHandle(
"cid-racing-fresh", "racing-fn", null, ContainerState.WARM);
CountDownLatch launchStarted = new CountDownLatch(1);
CountDownLatch finishLaunch = new CountDownLatch(1);
when(containerLauncher.launch(any()))
.thenAnswer(invocation -> {
launchStarted.countDown();
assertTrue(finishLaunch.await(5, TimeUnit.SECONDS));
return stale;
})
.thenReturn(fresh);
ExecutorService executor = Executors.newSingleThreadExecutor();
try {
Future<ContainerHandle> acquisition = executor.submit(() -> pool.acquire(fn));
assertTrue(launchStarted.await(5, TimeUnit.SECONDS));
pool.drainFunction("racing-fn");
finishLaunch.countDown();
ContainerHandle acquired = acquisition.get(5, TimeUnit.SECONDS);
pool.release(acquired);
verify(containerLauncher).stop(stale);
ContainerHandle postDrain = pool.acquire(fn);
assertSame(fresh, postDrain);
when(containerLauncher.isAlive(fresh)).thenReturn(true);
pool.release(postDrain);
assertSame(fresh, pool.acquire(fn));
verify(containerLauncher, times(2)).launch(any());
} finally {
finishLaunch.countDown();
executor.shutdownNow();
pool.shutdown();
}
}
}
@@ -10,6 +10,7 @@ import io.github.hectorvent.floci.core.common.docker.ContainerSpec;
import io.github.hectorvent.floci.core.common.docker.DockerHostResolver;
import io.github.hectorvent.floci.core.common.docker.LaunchedContainerAwsEnv;
import io.github.hectorvent.floci.services.ecr.registry.EcrRegistryManager;
import io.github.hectorvent.floci.services.lambda.model.LambdaFileSystemConfig;
import io.github.hectorvent.floci.services.lambda.model.LambdaFunction;
import io.github.hectorvent.floci.services.lambda.runtime.RuntimeApiServer;
import io.github.hectorvent.floci.services.lambda.runtime.RuntimeApiServerFactory;
@@ -45,6 +46,7 @@ import java.nio.file.Path;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.OptionalInt;
import java.util.concurrent.atomic.AtomicBoolean;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -85,6 +87,8 @@ class ContainerLauncherTest {
EmulatorConfig.ServicesConfig services = mock(EmulatorConfig.ServicesConfig.class);
EmulatorConfig.LambdaServiceConfig lambda = mock(EmulatorConfig.LambdaServiceConfig.class);
EmulatorConfig.DockerConfig docker = mock(EmulatorConfig.DockerConfig.class);
EmulatorConfig.StorageConfig storage = mock(EmulatorConfig.StorageConfig.class);
EmulatorConfig.EfsSharingConfig efs = mock(EmulatorConfig.EfsSharingConfig.class);
when(config.services()).thenReturn(services);
when(services.lambda()).thenReturn(lambda);
@@ -100,6 +104,14 @@ class ContainerLauncherTest {
lenient().when(tls.enabled()).thenReturn(false);
lenient().when(config.defaultRegion()).thenReturn("us-east-1");
lenient().when(config.hostname()).thenReturn(Optional.empty());
lenient().when(config.storage()).thenReturn(storage);
lenient().when(storage.efs()).thenReturn(efs);
lenient().when(efs.ownerUid()).thenReturn(OptionalInt.empty());
lenient().when(efs.ownerGid()).thenReturn(OptionalInt.empty());
lenient().when(efs.rootPermissions()).thenReturn(Optional.empty());
lenient().when(efs.initImage()).thenReturn("busybox:stable");
lenient().when(efs.mountUser()).thenReturn(Optional.empty());
lenient().when(efs.mountGroupAdd()).thenReturn(OptionalInt.empty());
when(embeddedDnsServer.getServerIp()).thenReturn(Optional.empty());
@@ -209,6 +221,35 @@ class ContainerLauncherTest {
"small code should be copied directly into /var/task");
}
@Test
void launchFunction_mountsConfiguredFileSystemVolume() throws Exception {
Path codePath = Files.createDirectory(tempDir.resolve("efs-code"));
LambdaFunction fn = new LambdaFunction();
fn.setFunctionName("efs-fn");
fn.setFunctionArn("arn:aws:lambda:us-east-1:000000000000:function:efs-fn");
fn.setRuntime("nodejs20.x");
fn.setHandler("index.handler");
fn.setCodeLocalPath(codePath.toString());
fn.setFileSystemConfigs(List.of(new LambdaFileSystemConfig(
"arn:aws:elasticfilesystem:us-east-1:000000000000:access-point/fsap-0123456789abcdef0",
"/mnt/shared")));
launcher.launch(fn);
String expectedVolumeName = "floci-efs-fsap-0123456789abcdef0-"
+ "9d6eafd2aec94d4518a004f005725b4b3c673c1506436bb7368cfd5450fc0810";
verify(lifecycleManager).ensureSharedVolume(expectedVolumeName,
OptionalInt.empty(), OptionalInt.empty(), Optional.empty(), "busybox:stable");
Mount mount = captureRealContainerSpec().mounts().stream()
.filter(candidate -> "/mnt/shared".equals(candidate.getTarget()))
.findFirst()
.orElseThrow();
assertEquals(MountType.VOLUME, mount.getType());
assertEquals(expectedVolumeName, mount.getSource());
assertTrue(!Boolean.TRUE.equals(mount.getReadOnly()));
}
@Test
void launchFunction_createsBeforeCopyAndStartsAfter() throws Exception {
Path codePath = Files.createDirectory(tempDir.resolve("code"));
@@ -100,6 +100,33 @@ class ContainerLauncherVolumeNamingTest {
"a later lastModified must produce a different volume name");
}
@Test
void efsVolumeNameIncludesStableHashOfCompleteArn() {
String arn = "arn:aws:elasticfilesystem:us-east-1:000000000000:"
+ "access-point/fsap-0123456789abcdef0";
String volumeName = ContainerLauncher.efsVolumeName(arn);
assertEquals("floci-efs-fsap-0123456789abcdef0-"
+ "9d6eafd2aec94d4518a004f005725b4b3c673c1506436bb7368cfd5450fc0810",
volumeName);
assertEquals(volumeName, ContainerLauncher.efsVolumeName(arn));
assertTrue(DOCKER_VOLUME_NAME.matcher(volumeName).matches(),
"EFS volume name must be Docker-safe, was: " + volumeName);
}
@Test
void efsVolumeNameDistinguishesSameResourceIdAcrossArns() {
String eastArn = "arn:aws:elasticfilesystem:us-east-1:000000000000:"
+ "access-point/fsap-0123456789abcdef0";
String westArn = "arn:aws:elasticfilesystem:us-west-2:111111111111:"
+ "access-point/fsap-0123456789abcdef0";
assertNotEquals(ContainerLauncher.efsVolumeName(eastArn),
ContainerLauncher.efsVolumeName(westArn),
"the complete ARN must participate in volume identity");
}
@TempDir
Path tempDir;