Light, fluffy, and always free - The AWS Local Emulator alternative
fic: env var for base lambda overwrite (#189)
John Coyne52d53f9a69af
diff --git a/README.md b/README.mdindex 61ce8bd243..f20f8ef977 100644--- a/README.md+++ b/README.md@@ -11,7 +11,7 @@<a href="https://github.com/hectorvent/floci/stargazers"><img src="https://img.shields.io/github/stars/hectorvent/floci?style=flat" alt="GitHub Stars"></a><a href="https://github.com/hectorvent/floci/graphs/contributors"><img src="https://img.shields.io/github/contributors/hectorvent/floci" alt="GitHub Contributors"></a><a href="https://join.slack.com/t/floci/shared_invite/zt-3tjn02s3q-A00kEjJ1cZxsg_imTfy6Cw"><img src="https://img.shields.io/badge/Slack-Join%20the%20community-4A154B?logo=slack&logoColor=white" alt="Join Floci on Slack"></a>-+</p><p align="center">@@ -232,6 +232,7 @@ All settings are overridable via environment variables (`FLOCI_` prefix).| `FLOCI_HOSTNAME` | *(unset)* | Override hostname in response URLs (for Docker Compose) || `FLOCI_STORAGE_MODE` | `memory` | `memory` · `persistent` · `hybrid` · `wal` || `FLOCI_STORAGE_PERSISTENT_PATH` | `./data` | Data directory |+| `FLOCI_ECR_BASE_URI` | `public.ecr.aws` | AWS ECR Base URI to pull container images (e.g. Lambda) |→ Full reference: [configuration docs](https://hectorvent.dev/floci/configuration/application-yml/)→ Per-service storage overrides: [storage docs](https://hectorvent.dev/floci/configuration/storage/#per-service-storage-overrides)@@ -267,4 +268,4 @@ Without this, SQS returns `http://localhost:4566/...` in QueueUrl responses, whi## License-MIT — use it however you want.+MIT — use it however you want.\ No newline at end of filediff --git a/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java b/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.javaindex f3e8de4e42..ba5dc65330 100644--- a/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java+++ b/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java@@ -41,6 +41,9 @@ public interface EmulatorConfig {@WithDefault("512")int maxRequestSize();+ @WithDefault("public.ecr.aws")+ String ecrBaseUri();+StorageConfig storage();AuthConfig auth();diff --git a/src/main/java/io/github/hectorvent/floci/services/lambda/launcher/ImageResolver.java b/src/main/java/io/github/hectorvent/floci/services/lambda/launcher/ImageResolver.javaindex 5f7e1cfc83..57ce97e925 100644--- a/src/main/java/io/github/hectorvent/floci/services/lambda/launcher/ImageResolver.java+++ b/src/main/java/io/github/hectorvent/floci/services/lambda/launcher/ImageResolver.java@@ -1,5 +1,6 @@package io.github.hectorvent.floci.services.lambda.launcher;+import io.github.hectorvent.floci.config.EmulatorConfig;import io.github.hectorvent.floci.core.common.AwsException;import jakarta.enterprise.context.ApplicationScoped;@@ -13,23 +14,29 @@ import java.util.Map;public class ImageResolver {private static final Map<String, String> RUNTIME_TO_IMAGE = Map.ofEntries(- Map.entry("java21", "public.ecr.aws/lambda/java:21"),- Map.entry("java17", "public.ecr.aws/lambda/java:17"),- Map.entry("java11", "public.ecr.aws/lambda/java:11"),- Map.entry("python3.13", "public.ecr.aws/lambda/python:3.13"),- Map.entry("python3.12", "public.ecr.aws/lambda/python:3.12"),- Map.entry("python3.11", "public.ecr.aws/lambda/python:3.11"),- Map.entry("python3.10", "public.ecr.aws/lambda/python:3.10"),- Map.entry("python3.9", "public.ecr.aws/lambda/python:3.9"),- Map.entry("nodejs22.x", "public.ecr.aws/lambda/nodejs:22"),- Map.entry("nodejs20.x", "public.ecr.aws/lambda/nodejs:20"),- Map.entry("nodejs18.x", "public.ecr.aws/lambda/nodejs:18"),- Map.entry("ruby3.3", "public.ecr.aws/lambda/ruby:3.3"),- Map.entry("ruby3.2", "public.ecr.aws/lambda/ruby:3.2"),- Map.entry("provided.al2023", "public.ecr.aws/lambda/provided:al2023"),- Map.entry("provided.al2", "public.ecr.aws/lambda/provided:al2")+ Map.entry("java21", "java:21"),+ Map.entry("java17", "java:17"),+ Map.entry("java11", "java:11"),+ Map.entry("python3.13", "python:3.13"),+ Map.entry("python3.12", "python:3.12"),+ Map.entry("python3.11", "python:3.11"),+ Map.entry("python3.10", "python:3.10"),+ Map.entry("python3.9", "python:3.9"),+ Map.entry("nodejs22.x", "nodejs:22"),+ Map.entry("nodejs20.x", "nodejs:20"),+ Map.entry("nodejs18.x", "nodejs:18"),+ Map.entry("ruby3.3", "ruby:3.3"),+ Map.entry("ruby3.2", "ruby:3.2"),+ Map.entry("provided.al2023", "provided:al2023"),+ Map.entry("provided.al2", "provided:al2"));+ private final String baseUri;++ public ImageResolver(EmulatorConfig config) {+ this.baseUri = config.ecrBaseUri();+ }+public String resolve(String runtime) {if (runtime == null || runtime.isBlank()) {throw new AwsException("InvalidParameterValueException", "Runtime is required", 400);@@ -43,6 +50,6 @@ public class ImageResolver {throw new AwsException("InvalidParameterValueException","The runtime parameter " + runtime + " is not supported.", 400);}- return image;+ return baseUri + "/lambda/" + image;}}diff --git a/src/test/java/io/github/hectorvent/floci/services/lambda/launcher/ImageResolverTest.java b/src/test/java/io/github/hectorvent/floci/services/lambda/launcher/ImageResolverTest.javaindex d0a02dcbe0..1039557e1d 100644--- a/src/test/java/io/github/hectorvent/floci/services/lambda/launcher/ImageResolverTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/lambda/launcher/ImageResolverTest.java@@ -1,15 +1,23 @@package io.github.hectorvent.floci.services.lambda.launcher;+import io.github.hectorvent.floci.config.EmulatorConfig;import io.github.hectorvent.floci.core.common.AwsException;import org.junit.jupiter.api.Test;import org.junit.jupiter.params.ParameterizedTest;import org.junit.jupiter.params.provider.CsvSource;import static org.junit.jupiter.api.Assertions.*;+import static org.mockito.Mockito.*;class ImageResolverTest {- private final ImageResolver resolver = new ImageResolver();+ private final EmulatorConfig config = mock(EmulatorConfig.class);+ private final ImageResolver resolver;++ ImageResolverTest() {+ when(config.ecrBaseUri()).thenReturn("public.ecr.aws");+ this.resolver = new ImageResolver(config);+ }@ParameterizedTest@CsvSource({@@ -33,6 +41,56 @@ class ImageResolverTest {assertEquals(expectedImage, resolver.resolve(runtime));}+ @ParameterizedTest+ @CsvSource({+ "java21, my.custom.host/lambda/java:21",+ "java17, my.custom.host/lambda/java:17",+ "java11, my.custom.host/lambda/java:11",+ "python3.13, my.custom.host/lambda/python:3.13",+ "python3.12, my.custom.host/lambda/python:3.12",+ "python3.11, my.custom.host/lambda/python:3.11",+ "python3.10, my.custom.host/lambda/python:3.10",+ "python3.9, my.custom.host/lambda/python:3.9",+ "nodejs22.x, my.custom.host/lambda/nodejs:22",+ "nodejs20.x, my.custom.host/lambda/nodejs:20",+ "nodejs18.x, my.custom.host/lambda/nodejs:18",+ "ruby3.3, my.custom.host/lambda/ruby:3.3",+ "ruby3.2, my.custom.host/lambda/ruby:3.2",+ "provided.al2023, my.custom.host/lambda/provided:al2023",+ "provided.al2, my.custom.host/lambda/provided:al2"+ })+ void resolvesKnownRuntimesWithHostOverride(String runtime, String expectedImage) {+ EmulatorConfig customConfig = mock(EmulatorConfig.class);+ when(customConfig.ecrBaseUri()).thenReturn("my.custom.host");+ ImageResolver customResolver = new ImageResolver(customConfig);+ assertEquals(expectedImage, customResolver.resolve(runtime));+ }++ @ParameterizedTest+ @CsvSource({+ "java21, my.custom.host/path/lambda/java:21",+ "java17, my.custom.host/path/lambda/java:17",+ "java11, my.custom.host/path/lambda/java:11",+ "python3.13, my.custom.host/path/lambda/python:3.13",+ "python3.12, my.custom.host/path/lambda/python:3.12",+ "python3.11, my.custom.host/path/lambda/python:3.11",+ "python3.10, my.custom.host/path/lambda/python:3.10",+ "python3.9, my.custom.host/path/lambda/python:3.9",+ "nodejs22.x, my.custom.host/path/lambda/nodejs:22",+ "nodejs20.x, my.custom.host/path/lambda/nodejs:20",+ "nodejs18.x, my.custom.host/path/lambda/nodejs:18",+ "ruby3.3, my.custom.host/path/lambda/ruby:3.3",+ "ruby3.2, my.custom.host/path/lambda/ruby:3.2",+ "provided.al2023, my.custom.host/path/lambda/provided:al2023",+ "provided.al2, my.custom.host/path/lambda/provided:al2"+ })+ void resolvesKnownRuntimesWithHostAndPathOverride(String runtime, String expectedImage) {+ EmulatorConfig customConfig = mock(EmulatorConfig.class);+ when(customConfig.ecrBaseUri()).thenReturn("my.custom.host/path");+ ImageResolver customResolver = new ImageResolver(customConfig);+ assertEquals(expectedImage, customResolver.resolve(runtime));+ }+@Testvoid passesThroughCustomImageWithSlash() {String customImage = "123456789.dkr.ecr.us-east-1.amazonaws.com/my-function:latest";