Feat/lambda image config working directory (#673)

* feat(lambda): support ImageConfig.WorkingDirectory override

Propagate WorkingDirectory from the Lambda ImageConfig through the full
stack so container images that rely on a specific WORKDIR can be invoked
correctly, matching real AWS behavior.

- LambdaFunction: add imageConfigWorkingDirectory field + getter/setter
- LambdaService: parse WorkingDirectory on CreateFunction and
  UpdateFunctionConfiguration
- ContainerSpec: add workingDir record component
- ContainerBuilder: add withWorkingDir() fluent method
- ContainerLifecycleManager: pass workingDir to Docker via withWorkingDir()
- ContainerLauncher: apply workingDir when building the container spec
- LambdaController: serialize WorkingDirectory in ImageConfigResponse

* test(lambda): add tests for ImageConfig.WorkingDirectory

Unit tests (LambdaImageConfigTest):
- CreateFunction stores WorkingDirectory alongside Command/EntryPoint
- createFunction with all three fields together
- updateFunctionConfiguration updates and clears WorkingDirectory
- ContainerLauncher passes workingDir to ContainerSpec

Compat tests across all SDKs:
- awscli (lambda.bats): create/get/update WorkingDirectory round-trip
- Java SDK (LambdaFunctionConfigTest): ImageConfig.WorkingDirectory round-trip
- Python (test_lambda_function_config.py): TestImageConfigWorkingDirectory class
- Node (lambda.test.ts): create/update WorkingDirectory assertions
- Go (lambda_test.go): TestLambdaImageConfigWorkingDirectory subtests
- Rust (lambda_test.rs): full create/get/update round-trip
This commit is contained in:
Yorí authored and GitHub committed 2026-04-30 17:25:03 -05:00
1 parent 2dd748ee07
commit 8eeb2244a7
14 files changed
+494 -5

No files matched your search

@@ -69,6 +69,7 @@ public class ContainerBuilder {
private final List<String> env = new ArrayList<>();
private List<String> cmd;
private List<String> entrypoint;
private String workingDir;
private Long memoryBytes;
private final Map<Integer, Integer> portBindings = new HashMap<>();
private final List<Integer> exposedPorts = new ArrayList<>();
@@ -136,6 +137,14 @@ public class ContainerBuilder {
return this;
}
/**
* Sets the working directory inside the container (overrides image WORKDIR).
*/
public Builder withWorkingDir(String workingDir) {
this.workingDir = workingDir;
return this;
}
/**
* Sets the memory limit in megabytes.
*/
@@ -315,7 +324,8 @@ public class ContainerBuilder {
List.copyOf(extraHosts),
logConfig,
privileged,
List.copyOf(dnsServers)
List.copyOf(dnsServers),
workingDir
);
}
}
@@ -90,6 +90,9 @@ public class ContainerLifecycleManager {
if (spec.entrypoint() != null && !spec.entrypoint().isEmpty()) {
createCmd.withEntrypoint(spec.entrypoint());
}
if (spec.workingDir() != null && !spec.workingDir().isBlank()) {
createCmd.withWorkingDir(spec.workingDir());
}
if (spec.exposedPorts() != null && !spec.exposedPorts().isEmpty()) {
ExposedPort[] exposed = spec.exposedPorts().stream()
.map(ExposedPort::tcp)
@@ -26,6 +26,7 @@ import java.util.Map;
* @param logConfig Docker log driver configuration (null = daemon default)
* @param privileged Whether to run the container in privileged mode (required for k3s)
* @param dnsServers DNS server IPs to inject into the container (e.g. Floci's embedded DNS)
* @param workingDir Working directory inside the container (overrides image WORKDIR)
*/
public record ContainerSpec(
String image,
@@ -42,14 +43,15 @@ public record ContainerSpec(
List<String> extraHosts,
LogConfig logConfig,
boolean privileged,
List<String> dnsServers
List<String> dnsServers,
String workingDir
) {
/**
* Creates a minimal spec with just the image name.
* All other fields will be null or empty lists.
*/
public ContainerSpec(String image) {
this(image, null, List.of(), null, null, null, Map.of(), List.of(), null, List.of(), List.of(), List.of(), null, false, List.of());
this(image, null, List.of(), null, null, null, Map.of(), List.of(), null, List.of(), List.of(), List.of(), null, false, List.of(), null);
}
/**
@@ -539,6 +539,9 @@ public class LambdaController {
ArrayNode epNode = imageConfig.putArray("EntryPoint");
fn.getImageConfigEntryPoint().forEach(epNode::add);
}
if (fn.getImageConfigWorkingDirectory() != null && !fn.getImageConfigWorkingDirectory().isBlank()) {
imageConfig.put("WorkingDirectory", fn.getImageConfigWorkingDirectory());
}
}
node.put("LastModified", DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ")
.format(Instant.ofEpochMilli(fn.getLastModified()).atOffset(ZoneOffset.UTC)));
@@ -296,6 +296,9 @@ public class LambdaService {
if (imageConfig.get("EntryPoint") instanceof List<?> ep) {
fn.setImageConfigEntryPoint(ep.stream().map(Object::toString).toList());
}
if (imageConfig.get("WorkingDirectory") instanceof String wd) {
fn.setImageConfigWorkingDirectory(wd);
}
}
// Handle code deployment
@@ -509,6 +512,10 @@ public class LambdaService {
? ((List<?>) imageConfig.get("EntryPoint")).stream().map(Object::toString).toList() : null;
fn.setImageConfigEntryPoint(ep);
}
if (imageConfig.containsKey("WorkingDirectory")) {
fn.setImageConfigWorkingDirectory(
imageConfig.get("WorkingDirectory") instanceof String wd ? wd : null);
}
}
}
@@ -192,7 +192,7 @@ public class ContainerLauncher {
specBuilder.withBind(fn.getHotReloadHostPath(), TASK_DIR);
}
// For Image package type use ImageConfig.Command if set, otherwise fall back to Handler (Zip-style)
// For Image package type use ImageConfig.Command/EntryPoint/WorkingDirectory if set, otherwise fall back to Handler (Zip-style)
if ("Image".equals(fn.getPackageType())) {
if (fn.getImageConfigEntryPoint() != null && !fn.getImageConfigEntryPoint().isEmpty()) {
specBuilder.withEntrypoint(fn.getImageConfigEntryPoint());
@@ -200,6 +200,9 @@ public class ContainerLauncher {
if (fn.getImageConfigCommand() != null && !fn.getImageConfigCommand().isEmpty()) {
specBuilder.withCmd(fn.getImageConfigCommand());
}
if (fn.getImageConfigWorkingDirectory() != null && !fn.getImageConfigWorkingDirectory().isBlank()) {
specBuilder.withWorkingDir(fn.getImageConfigWorkingDirectory());
}
} else if (fn.getHandler() != null && !fn.getHandler().isBlank()) {
specBuilder.withCmd(fn.getHandler());
}
@@ -29,6 +29,7 @@ public class LambdaFunction {
private String imageUri;
private List<String> imageConfigCommand;
private List<String> imageConfigEntryPoint;
private String imageConfigWorkingDirectory;
private String codeLocalPath;
private String s3Bucket;
private String s3Key;
@@ -106,6 +107,9 @@ public class LambdaFunction {
public List<String> getImageConfigEntryPoint() { return imageConfigEntryPoint; }
public void setImageConfigEntryPoint(List<String> imageConfigEntryPoint) { this.imageConfigEntryPoint = imageConfigEntryPoint; }
public String getImageConfigWorkingDirectory() { return imageConfigWorkingDirectory; }
public void setImageConfigWorkingDirectory(String imageConfigWorkingDirectory) { this.imageConfigWorkingDirectory = imageConfigWorkingDirectory; }
public String getCodeLocalPath() { return codeLocalPath; }
public void setCodeLocalPath(String codeLocalPath) { this.codeLocalPath = codeLocalPath; }