]}.
- *
- * Taking the segment after the last colon reads the qualifier as the function name, so a
- * subscription to {@code ...:function:order-processor:PROD} invoked a function called
- * {@code PROD} and the message went nowhere. Cut after {@code :function:} instead, matching
- * what S3 and Step Functions already do for the same ARN.
- */
- static String extractFunctionName(String functionArn) {
- if (functionArn == null) {
- return null;
- }
- int functionMarker = functionArn.indexOf(FUNCTION_MARKER);
- if (functionMarker < 0) {
- return functionArn;
- }
- String suffix = functionArn.substring(functionMarker + FUNCTION_MARKER.length());
- int qualifierSeparator = suffix.indexOf(':');
- return qualifierSeparator >= 0 ? suffix.substring(0, qualifierSeparator) : suffix;
- }
-
private static String extractRegionFromArn(String arn) {
return AwsArnUtils.regionOrDefault(arn, null);
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutor.java b/src/main/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutor.java
index 06d119eb7a..e61f75ef50 100644
--- a/src/main/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutor.java
+++ b/src/main/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutor.java
@@ -28,6 +28,7 @@ import io.github.hectorvent.floci.services.scheduler.model.Schedule;
import io.github.hectorvent.floci.services.scheduler.model.ScheduleRequest;
import io.github.hectorvent.floci.services.lambda.LambdaExecutorService;
import io.github.hectorvent.floci.services.lambda.LambdaFunctionStore;
+import io.github.hectorvent.floci.services.lambda.LambdaTargetResolver;
import io.github.hectorvent.floci.services.lambda.model.InvocationType;
import io.github.hectorvent.floci.services.lambda.model.InvokeResult;
import io.github.hectorvent.floci.services.lambda.model.LambdaFunction;
@@ -232,7 +233,7 @@ public class AslExecutor {
"warning");
private final LambdaExecutorService lambdaExecutor;
- private final LambdaFunctionStore functionStore;
+ private final LambdaTargetResolver targetResolver;
private final DynamoDbService dynamoDbService;
private final DynamoDbJsonHandler dynamoDbJsonHandler;
private final SqsJsonHandler sqsJsonHandler;
@@ -265,7 +266,7 @@ public class AslExecutor {
});
@Inject
- public AslExecutor(LambdaExecutorService lambdaExecutor, LambdaFunctionStore functionStore,
+ public AslExecutor(LambdaExecutorService lambdaExecutor, LambdaTargetResolver targetResolver,
DynamoDbService dynamoDbService, DynamoDbJsonHandler dynamoDbJsonHandler,
SqsJsonHandler sqsJsonHandler, SnsJsonHandler snsJsonHandler,
CloudFormationQueryHandler cloudFormationHandler,
@@ -276,7 +277,7 @@ public class AslExecutor {
ObjectMapper objectMapper, JsonataEvaluator jsonataEvaluator,
Instance sfnService, EmulatorConfig config, Vertx vertx,
CustomResourceLiveness customResourceLiveness) {
- this(lambdaExecutor, functionStore, dynamoDbService, dynamoDbJsonHandler,
+ this(lambdaExecutor, targetResolver, dynamoDbService, dynamoDbJsonHandler,
sqsJsonHandler, snsJsonHandler, cloudFormationHandler,
ec2Service, s3Service, ecsService, ecsJsonHandler,
eventBridgeHandler, schedulerService, schedulerController, rdsDataService,
@@ -284,7 +285,7 @@ public class AslExecutor {
Clock.systemUTC(), TimeUnit.NANOSECONDS::sleep, null);
}
- AslExecutor(LambdaExecutorService lambdaExecutor, LambdaFunctionStore functionStore,
+ AslExecutor(LambdaExecutorService lambdaExecutor, LambdaTargetResolver targetResolver,
DynamoDbService dynamoDbService, DynamoDbJsonHandler dynamoDbJsonHandler,
SqsJsonHandler sqsJsonHandler, SnsJsonHandler snsJsonHandler,
CloudFormationQueryHandler cloudFormationHandler,
@@ -298,7 +299,7 @@ public class AslExecutor {
Clock clock, Sleeper sleeper, Integer maxWaitSecondsOverride) {
this.customResourceLiveness = customResourceLiveness;
this.lambdaExecutor = lambdaExecutor;
- this.functionStore = functionStore;
+ this.targetResolver = targetResolver;
this.dynamoDbService = dynamoDbService;
this.dynamoDbJsonHandler = dynamoDbJsonHandler;
this.sqsJsonHandler = sqsJsonHandler;
@@ -346,7 +347,7 @@ public class AslExecutor {
Instance sfnService, EmulatorConfig config, Vertx vertx,
CustomResourceLiveness customResourceLiveness,
Clock clock, Sleeper sleeper, Integer maxWaitSecondsOverride) {
- this(lambdaExecutor, functionStore, dynamoDbService, dynamoDbJsonHandler,
+ this(lambdaExecutor, new LambdaTargetResolver(functionStore, null), dynamoDbService, dynamoDbJsonHandler,
sqsJsonHandler, snsJsonHandler, cloudFormationHandler, ec2Service, s3Service,
ecsService, ecsJsonHandler, eventBridgeHandler, schedulerService,
schedulerController, null, objectMapper, jsonataEvaluator, sfnService, config,
@@ -370,7 +371,7 @@ public class AslExecutor {
ObjectMapper objectMapper, JsonataEvaluator jsonataEvaluator,
Instance sfnService, EmulatorConfig config, Vertx vertx,
CustomResourceLiveness customResourceLiveness) {
- this(lambdaExecutor, functionStore, dynamoDbService, dynamoDbJsonHandler,
+ this(lambdaExecutor, new LambdaTargetResolver(functionStore, null), dynamoDbService, dynamoDbJsonHandler,
sqsJsonHandler, snsJsonHandler, cloudFormationHandler, ec2Service, s3Service,
ecsService, ecsJsonHandler, eventBridgeHandler, schedulerService,
schedulerController, null, objectMapper, jsonataEvaluator, sfnService, config,
@@ -978,7 +979,7 @@ public class AslExecutor {
* Extracts the Lambda function name from a reference that may be a bare name, a name with a
* version/alias qualifier (e.g. "name:$LATEST"), or a full/partial function ARN
* (e.g. "arn:aws:lambda:region:acct:function:name[:qualifier]"). The qualifier is dropped
- * because the function store is keyed by name. Taking the last ':'-segment is wrong for a
+ * here and read by {@link #extractLambdaQualifier}. Taking the last ':'-segment is wrong for a
* qualified ARN — it yields the qualifier (e.g. "$LATEST") instead of the function name.
*/
static String extractLambdaFunctionName(String ref) {
@@ -998,6 +999,27 @@ public class AslExecutor {
return fn;
}
+ static String extractLambdaQualifier(String ref) {
+ if (ref == null) {
+ return null;
+ }
+ int fi = ref.indexOf(":function:");
+ String fn = fi >= 0 ? ref.substring(fi + ":function:".length()) : ref;
+ int colon = fn.indexOf(':');
+ return colon >= 0 ? fn.substring(colon + 1) : null;
+ }
+
+ private LambdaFunction resolveLambdaFunction(String region, String name, String qualifier) {
+ try {
+ return targetResolver.resolveInvokeTarget(region, name, qualifier);
+ } catch (AwsException e) {
+ if ("ResourceNotFoundException".equals(e.getErrorCode())) {
+ return null;
+ }
+ throw e;
+ }
+ }
+
/**
* Reports that a pending custom resource is still making progress, if this payload belongs to
* one. The Step Functions Task path drives a CDK provider-framework waiter's {@code
@@ -1042,17 +1064,20 @@ public class AslExecutor {
long executionDeadlineNanos, JsonNode rawParameters) throws Exception {
// Support Lambda resources: direct ARN or optimized integration
String functionName = null;
+ String functionRef = null;
JsonNode lambdaPayload = input;
boolean optimizedLambdaInvoke = false;
if (resource.contains(":lambda:") && resource.contains(":function:")) {
// Direct Lambda ARN: arn:aws:lambda:region:account:function:name[:qualifier]
+ functionRef = resource;
functionName = extractLambdaFunctionName(resource);
} else if (resource.equals("arn:aws:states:::lambda:invoke")) {
// Optimized Lambda integration — function name and payload come from resolved input
optimizedLambdaInvoke = true;
String fnRef = input.path("FunctionName").asText(null);
if (fnRef != null) {
+ functionRef = fnRef;
functionName = extractLambdaFunctionName(fnRef);
}
JsonNode payload = input.path("Payload");
@@ -1064,7 +1089,7 @@ public class AslExecutor {
if (functionName != null) {
// Extract region from the state machine ARN: arn:aws:states:REGION:...
String region = extractRegionFromArn(sm.getStateMachineArn());
- LambdaFunction fn = functionStore.get(region, functionName).orElse(null);
+ LambdaFunction fn = resolveLambdaFunction(region, functionName, extractLambdaQualifier(functionRef));
if (fn == null) {
// A missing function is a task failure on AWS, so it must stay reachable for
// Retry and Catch instead of surfacing as States.Runtime.
diff --git a/src/test/java/io/github/hectorvent/floci/services/lambda/DynamoDbStreamsEventSourcePollerTest.java b/src/test/java/io/github/hectorvent/floci/services/lambda/DynamoDbStreamsEventSourcePollerTest.java
index 52d9d61fbd..abdcb1f7ef 100644
--- a/src/test/java/io/github/hectorvent/floci/services/lambda/DynamoDbStreamsEventSourcePollerTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/lambda/DynamoDbStreamsEventSourcePollerTest.java
@@ -18,6 +18,7 @@ import io.github.hectorvent.floci.services.iam.IamService;
import io.github.hectorvent.floci.services.lambda.model.EventSourceMapping;
import io.github.hectorvent.floci.services.lambda.model.InvocationType;
import io.github.hectorvent.floci.services.lambda.model.InvokeResult;
+import io.github.hectorvent.floci.services.lambda.model.LambdaAlias;
import io.github.hectorvent.floci.services.lambda.model.LambdaFunction;
import io.github.hectorvent.floci.services.pipes.PipesFilterMatcher;
import io.github.hectorvent.floci.services.s3.S3Service;
@@ -81,6 +82,7 @@ class DynamoDbStreamsEventSourcePollerTest {
private DynamoDbStreamService streamService;
private LambdaExecutorService executorService;
private LambdaFunctionStore functionStore;
+ private LambdaAliasStore aliasStore;
private EsmStore esmStore;
private EmulatorConfig config;
private PipesFilterMatcher filterMatcher;
@@ -106,6 +108,7 @@ class DynamoDbStreamsEventSourcePollerTest {
streamService = mock(DynamoDbStreamService.class);
executorService = mock(LambdaExecutorService.class);
functionStore = mock(LambdaFunctionStore.class);
+ aliasStore = mock(LambdaAliasStore.class);
esmStore = new EsmStore(new AccountAwareStorageBackend<>(new InMemoryStorage<>(), null, ACCOUNT_ID));
filterMatcher = new PipesFilterMatcher(OBJECT_MAPPER);
sqsService = mock(io.github.hectorvent.floci.services.sqs.SqsService.class);
@@ -115,7 +118,7 @@ class DynamoDbStreamsEventSourcePollerTest {
// A mocked Vertx makes setPeriodic a no-op, so startPolling registers no live timer and
// the tests drive pollAndInvoke deterministically.
poller = new DynamoDbStreamsEventSourcePoller(
- mock(Vertx.class), streamService, executorService, functionStore,
+ mock(Vertx.class), streamService, executorService, new LambdaTargetResolver(functionStore, aliasStore),
esmStore, OBJECT_MAPPER, config, filterMatcher, sqsService, snsService, s3Service, clock::get);
}
@@ -189,7 +192,7 @@ class DynamoDbStreamsEventSourcePollerTest {
private DynamoDbStreamsEventSourcePoller pollerWith(EsmStore store) {
return new DynamoDbStreamsEventSourcePoller(
- mock(Vertx.class), streamService, executorService, functionStore,
+ mock(Vertx.class), streamService, executorService, new LambdaTargetResolver(functionStore, aliasStore),
store, OBJECT_MAPPER, config, filterMatcher, sqsService, snsService, s3Service, clock::get);
}
@@ -275,6 +278,47 @@ class DynamoDbStreamsEventSourcePollerTest {
private static final String PATTERN =
"{\"eventName\":[\"INSERT\"],\"dynamodb\":{\"NewImage\":{\"status\":{\"S\":[\"active\"]}}}}";
+ @Test
+ void versionQualifiedMappingInvokesThatVersion() {
+ stubTrimHorizon(List.of(ddbRecord("s1", "INSERT", "{\"status\":{\"S\":\"active\"}}")));
+ LambdaFunction version1 = stubVersion("1");
+ when(executorService.invoke(any(), any(byte[].class), eq(InvocationType.RequestResponse)))
+ .thenReturn(new InvokeResult());
+ EventSourceMapping esm = filterEsm();
+ esm.setFunctionArn("arn:aws:lambda:us-east-1:" + ACCOUNT_ID + ":function:fn:1");
+
+ pollerWith(mock(EsmStore.class)).pollAndInvoke(esm);
+
+ verify(executorService, timeout(2000)).invoke(eq(version1), any(byte[].class), eq(InvocationType.RequestResponse));
+ }
+
+ @Test
+ void aliasQualifiedMappingInvokesTheAliasVersion() {
+ stubTrimHorizon(List.of(ddbRecord("s1", "INSERT", "{\"status\":{\"S\":\"active\"}}")));
+ LambdaFunction version2 = stubVersion("2");
+ LambdaAlias alias = new LambdaAlias();
+ alias.setName("live");
+ alias.setFunctionName("fn");
+ alias.setFunctionVersion("2");
+ when(aliasStore.getForAccount(ACCOUNT_ID, "us-east-1", "fn", "live")).thenReturn(Optional.of(alias));
+ when(executorService.invoke(any(), any(byte[].class), eq(InvocationType.RequestResponse)))
+ .thenReturn(new InvokeResult());
+ EventSourceMapping esm = filterEsm();
+ esm.setFunctionArn("arn:aws:lambda:us-east-1:" + ACCOUNT_ID + ":function:fn:live");
+
+ pollerWith(mock(EsmStore.class)).pollAndInvoke(esm);
+
+ verify(executorService, timeout(2000)).invoke(eq(version2), any(byte[].class), eq(InvocationType.RequestResponse));
+ }
+
+ private LambdaFunction stubVersion(String version) {
+ LambdaFunction fn = new LambdaFunction();
+ fn.setFunctionName("fn");
+ fn.setVersion(version);
+ when(functionStore.getForAccount(ACCOUNT_ID, "us-east-1", "fn", version)).thenReturn(Optional.of(fn));
+ return fn;
+ }
+
@Test
void filterDeliversMatchingRecordsAndCheckpointsNewestFetched() {
stubTrimHorizon(List.of(
diff --git a/src/test/java/io/github/hectorvent/floci/services/lambda/KinesisEventSourcePollerTest.java b/src/test/java/io/github/hectorvent/floci/services/lambda/KinesisEventSourcePollerTest.java
index 4480e0b3b2..35cdcebef4 100644
--- a/src/test/java/io/github/hectorvent/floci/services/lambda/KinesisEventSourcePollerTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/lambda/KinesisEventSourcePollerTest.java
@@ -11,6 +11,7 @@ import io.github.hectorvent.floci.services.kinesis.model.KinesisStream;
import io.github.hectorvent.floci.services.lambda.model.EventSourceMapping;
import io.github.hectorvent.floci.services.lambda.model.InvocationType;
import io.github.hectorvent.floci.services.lambda.model.InvokeResult;
+import io.github.hectorvent.floci.services.lambda.model.LambdaAlias;
import io.github.hectorvent.floci.services.lambda.model.LambdaFunction;
import io.github.hectorvent.floci.services.pipes.PipesFilterMatcher;
import io.vertx.core.Vertx;
@@ -61,6 +62,7 @@ class KinesisEventSourcePollerTest {
private KinesisService kinesisService;
private LambdaExecutorService executorService;
private LambdaFunctionStore functionStore;
+ private LambdaAliasStore aliasStore;
private EsmStore esmStore;
@BeforeEach
@@ -75,10 +77,11 @@ class KinesisEventSourcePollerTest {
kinesisService = mock(KinesisService.class);
executorService = mock(LambdaExecutorService.class);
functionStore = mock(LambdaFunctionStore.class);
+ aliasStore = mock(LambdaAliasStore.class);
esmStore = mock(EsmStore.class);
poller = new KinesisEventSourcePoller(mock(Vertx.class), kinesisService, executorService,
- functionStore, esmStore, config, MAPPER, new PipesFilterMatcher(MAPPER));
+ new LambdaTargetResolver(functionStore, aliasStore), esmStore, config, MAPPER, new PipesFilterMatcher(MAPPER));
}
private EventSourceMapping esm(String... patterns) {
@@ -160,6 +163,47 @@ class KinesisEventSourcePollerTest {
}
}
+ @Test
+ void versionQualifiedMappingInvokesThatVersion() {
+ stubFunction();
+ LambdaFunction version1 = stubVersion("1");
+ stubStreamWith(List.of(record("s1", "p1", "{}")));
+ when(executorService.invoke(any(), any(), eq(InvocationType.RequestResponse))).thenReturn(new InvokeResult());
+ EventSourceMapping esm = esm();
+ esm.setFunctionArn("arn:aws:lambda:" + REGION + ":" + ACCOUNT + ":function:fn:1");
+
+ poller.pollAndInvoke(esm);
+
+ verify(executorService, timeout(2000)).invoke(eq(version1), any(), eq(InvocationType.RequestResponse));
+ }
+
+ @Test
+ void aliasQualifiedMappingInvokesTheAliasVersion() {
+ stubFunction();
+ LambdaFunction version2 = stubVersion("2");
+ LambdaAlias alias = new LambdaAlias();
+ alias.setName("live");
+ alias.setFunctionName("fn");
+ alias.setFunctionVersion("2");
+ when(aliasStore.getForAccount(ACCOUNT, REGION, "fn", "live")).thenReturn(Optional.of(alias));
+ stubStreamWith(List.of(record("s1", "p1", "{}")));
+ when(executorService.invoke(any(), any(), eq(InvocationType.RequestResponse))).thenReturn(new InvokeResult());
+ EventSourceMapping esm = esm();
+ esm.setFunctionArn("arn:aws:lambda:" + REGION + ":" + ACCOUNT + ":function:fn:live");
+
+ poller.pollAndInvoke(esm);
+
+ verify(executorService, timeout(2000)).invoke(eq(version2), any(), eq(InvocationType.RequestResponse));
+ }
+
+ private LambdaFunction stubVersion(String version) {
+ LambdaFunction fn = new LambdaFunction();
+ fn.setFunctionName("fn");
+ fn.setVersion(version);
+ when(functionStore.getForAccount(ACCOUNT, REGION, "fn", version)).thenReturn(Optional.of(fn));
+ return fn;
+ }
+
@Test
void noFilterInvokesAllRecordsAndCheckpointsNewest() {
stubFunction();
diff --git a/src/test/java/io/github/hectorvent/floci/services/lambda/LambdaArnInvocationAccountTest.java b/src/test/java/io/github/hectorvent/floci/services/lambda/LambdaArnInvocationAccountTest.java
index 2c5924ff85..0ae08b667a 100644
--- a/src/test/java/io/github/hectorvent/floci/services/lambda/LambdaArnInvocationAccountTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/lambda/LambdaArnInvocationAccountTest.java
@@ -61,6 +61,7 @@ class LambdaArnInvocationAccountTest {
new RegionResolver(region, defaultAccount),
null,
null,
+ new LambdaTargetResolver(store, null),
null,
null,
null,
@@ -123,6 +124,7 @@ class LambdaArnInvocationAccountTest {
new RegionResolver(region, defaultAccount),
null,
aliasStore,
+ new LambdaTargetResolver(functionStore, aliasStore),
null,
null,
null,
@@ -263,6 +265,7 @@ class LambdaArnInvocationAccountTest {
new RegionResolver(region, defaultAccount),
null,
aliasStore,
+ new LambdaTargetResolver(functionStore, aliasStore),
null,
null,
null,
diff --git a/src/test/java/io/github/hectorvent/floci/services/lambda/SqsEventSourcePollerTest.java b/src/test/java/io/github/hectorvent/floci/services/lambda/SqsEventSourcePollerTest.java
index bfbe578d9d..b6a79423db 100644
--- a/src/test/java/io/github/hectorvent/floci/services/lambda/SqsEventSourcePollerTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/lambda/SqsEventSourcePollerTest.java
@@ -6,6 +6,7 @@ import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.services.lambda.model.EventSourceMapping;
import io.github.hectorvent.floci.services.lambda.model.InvocationType;
import io.github.hectorvent.floci.services.lambda.model.InvokeResult;
+import io.github.hectorvent.floci.services.lambda.model.LambdaAlias;
import io.github.hectorvent.floci.services.lambda.model.LambdaFunction;
import io.github.hectorvent.floci.services.pipes.PipesFilterMatcher;
import io.github.hectorvent.floci.services.sqs.SqsService;
@@ -41,6 +42,7 @@ class SqsEventSourcePollerTest {
private SqsService sqsService;
private LambdaExecutorService executorService;
private LambdaFunctionStore functionStore;
+ private LambdaAliasStore aliasStore;
@BeforeEach
void setUp() {
@@ -55,12 +57,13 @@ class SqsEventSourcePollerTest {
sqsService = mock(SqsService.class);
executorService = mock(LambdaExecutorService.class);
functionStore = mock(LambdaFunctionStore.class);
+ aliasStore = mock(LambdaAliasStore.class);
poller = new SqsEventSourcePoller(
mock(Vertx.class),
sqsService,
executorService,
- functionStore,
+ new LambdaTargetResolver(functionStore, aliasStore),
mock(EsmStore.class),
config,
OBJECT_MAPPER,
@@ -325,6 +328,52 @@ class SqsEventSourcePollerTest {
verify(sqsService, never()).deleteMessage(any(), any(), any());
}
+ @Test
+ void versionQualifiedMappingInvokesThatVersion() {
+ EventSourceMapping esm = esm();
+ esm.setFunctionArn("arn:aws:lambda:us-east-1:000000000000:function:throwfn:1");
+ stubThrowFn();
+ LambdaFunction version1 = new LambdaFunction();
+ version1.setFunctionName("throwfn");
+ version1.setVersion("1");
+ version1.setTimeout(10);
+ when(functionStore.getForAccount("000000000000", "us-east-1", "throwfn", "1"))
+ .thenReturn(Optional.of(version1));
+ stubReceive(esm, List.of(message("m1")));
+ when(executorService.invoke(any(LambdaFunction.class), any(byte[].class), eq(InvocationType.RequestResponse)))
+ .thenReturn(new InvokeResult());
+
+ poller.pollAndInvoke(esm);
+
+ verify(executorService, timeout(2000)).invoke(eq(version1), any(byte[].class), eq(InvocationType.RequestResponse));
+ }
+
+ @Test
+ void aliasQualifiedMappingInvokesTheAliasVersion() {
+ EventSourceMapping esm = esm();
+ esm.setFunctionArn("arn:aws:lambda:us-east-1:000000000000:function:throwfn:live");
+ stubThrowFn();
+ LambdaAlias alias = new LambdaAlias();
+ alias.setName("live");
+ alias.setFunctionName("throwfn");
+ alias.setFunctionVersion("2");
+ when(aliasStore.getForAccount("000000000000", "us-east-1", "throwfn", "live"))
+ .thenReturn(Optional.of(alias));
+ LambdaFunction version2 = new LambdaFunction();
+ version2.setFunctionName("throwfn");
+ version2.setVersion("2");
+ version2.setTimeout(10);
+ when(functionStore.getForAccount("000000000000", "us-east-1", "throwfn", "2"))
+ .thenReturn(Optional.of(version2));
+ stubReceive(esm, List.of(message("m1")));
+ when(executorService.invoke(any(LambdaFunction.class), any(byte[].class), eq(InvocationType.RequestResponse)))
+ .thenReturn(new InvokeResult());
+
+ poller.pollAndInvoke(esm);
+
+ verify(executorService, timeout(2000)).invoke(eq(version2), any(byte[].class), eq(InvocationType.RequestResponse));
+ }
+
@Test
void failedInvocationFallsBackToDefaultVisibilityWhenQueueHasNone() {
EventSourceMapping esm = esm();
diff --git a/src/test/java/io/github/hectorvent/floci/services/pipes/PipesTargetInvokerTest.java b/src/test/java/io/github/hectorvent/floci/services/pipes/PipesTargetInvokerTest.java
index 66ee3a4964..827050a554 100644
--- a/src/test/java/io/github/hectorvent/floci/services/pipes/PipesTargetInvokerTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/pipes/PipesTargetInvokerTest.java
@@ -102,6 +102,17 @@ class PipesTargetInvokerTest {
verify(sqsService).sendMessage(anyString(), eq(payload), eq(0), eq(region));
}
+ @Test
+ void invoke_keepsTheQualifierOfTheTargetFunctionArn() {
+ Pipe pipe = createPipe("arn:aws:lambda:us-east-1:000000000000:function:my-fn:PROD", null);
+ when(lambdaService.invoke(anyString(), anyString(), any(byte[].class), any(InvocationType.class)))
+ .thenReturn(new io.github.hectorvent.floci.services.lambda.model.InvokeResult(200, null, "{}".getBytes(), null, "req"));
+
+ invoker.invoke(pipe, "{}", "us-east-1");
+
+ verify(lambdaService).invoke(eq("us-east-1"), eq("my-fn:PROD"), any(byte[].class), eq(InvocationType.RequestResponse));
+ }
+
@Test
void invoke_throwsOnDeliveryFailure() {
Pipe pipe = createPipe("arn:aws:lambda:us-east-1:000000000000:function:my-fn", null);
@@ -275,15 +286,15 @@ class PipesTargetInvokerTest {
}
@Test
- void applyEnrichment_qualifiedArnResolvesFunctionName() {
+ void applyEnrichment_keepsTheQualifierOfTheFunctionArn() {
String region = "us-east-1";
- Pipe pipe = enrichmentPipe(region, "arn:aws:lambda:" + region + ":000000000000:function:enrich-fn:$LATEST");
- when(lambdaService.invoke(eq(region), eq("enrich-fn"), any(byte[].class), eq(InvocationType.RequestResponse)))
+ Pipe pipe = enrichmentPipe(region, "arn:aws:lambda:" + region + ":000000000000:function:enrich-fn:PROD");
+ when(lambdaService.invoke(eq(region), eq("enrich-fn:PROD"), any(byte[].class), eq(InvocationType.RequestResponse)))
.thenReturn(new io.github.hectorvent.floci.services.lambda.model.InvokeResult(200, null, "{}".getBytes(), null, "req"));
invoker.applyEnrichment(pipe, "[]", region);
- verify(lambdaService).invoke(eq(region), eq("enrich-fn"), any(byte[].class), eq(InvocationType.RequestResponse));
+ verify(lambdaService).invoke(eq(region), eq("enrich-fn:PROD"), any(byte[].class), eq(InvocationType.RequestResponse));
}
@Test
diff --git a/src/test/java/io/github/hectorvent/floci/services/s3/S3ServiceTest.java b/src/test/java/io/github/hectorvent/floci/services/s3/S3ServiceTest.java
index 45195af6d1..32cffc6765 100644
--- a/src/test/java/io/github/hectorvent/floci/services/s3/S3ServiceTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/s3/S3ServiceTest.java
@@ -618,6 +618,27 @@ class S3ServiceTest {
assertNull(lambdaInvoker.functionName);
}
+ @Test
+ void putObjectKeepsTheQualifierOfTheNotificationFunctionArn() {
+ RecordingLambdaInvoker lambdaInvoker = new RecordingLambdaInvoker();
+ RegionResolver regionResolver = new RegionResolver("us-east-1", "000000000000");
+
+ S3Service service = new S3Service(new InMemoryStorage<>(), new InMemoryStorage<>(), tempDir.resolve("notif-s3-alias"),
+ false, lambdaInvoker, regionResolver);
+ service.createBucket("test-bucket", "ap-northeast-1");
+ NotificationConfiguration config = new NotificationConfiguration();
+ config.getLambdaFunctionConfigurations().add(new LambdaNotification(
+ "lambda-notif",
+ "arn:aws:lambda:ap-northeast-1:000000000000:function:s3-notif-test:PROD",
+ List.of("s3:ObjectCreated:Put"),
+ List.of()));
+ service.putBucketNotificationConfiguration("test-bucket", config);
+
+ service.putObject("test-bucket", "a.json", "{}".getBytes(StandardCharsets.UTF_8), "application/json", null);
+
+ assertEquals("s3-notif-test:PROD", lambdaInvoker.functionName);
+ }
+
private static NotificationConfiguration lambdaNotificationConfig(String prefix, String suffix) {
NotificationConfiguration config = new NotificationConfiguration();
config.getLambdaFunctionConfigurations().add(new LambdaNotification(
diff --git a/src/test/java/io/github/hectorvent/floci/services/sns/SnsServiceTest.java b/src/test/java/io/github/hectorvent/floci/services/sns/SnsServiceTest.java
index 97641d2723..b647c1e66e 100644
--- a/src/test/java/io/github/hectorvent/floci/services/sns/SnsServiceTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/sns/SnsServiceTest.java
@@ -7,6 +7,8 @@ import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
import io.github.hectorvent.floci.services.firehose.FirehoseService;
import io.github.hectorvent.floci.services.firehose.model.Record;
+import io.github.hectorvent.floci.services.lambda.LambdaService;
+import io.github.hectorvent.floci.services.lambda.model.InvocationType;
import io.github.hectorvent.floci.services.sns.model.Subscription;
import io.github.hectorvent.floci.services.sns.model.Topic;
import io.github.hectorvent.floci.services.sqs.model.MessageAttributeValue;
@@ -614,37 +616,6 @@ class SnsServiceTest {
"arn:aws:sns:us-east-1:000000000000:ghost-topic", REGION));
}
-
- /**
- * A Lambda subscription endpoint may be a qualified ARN. Taking the segment after the last
- * colon read the alias as the function name, so a subscription to
- * {@code ...:function:order-processor:PROD} invoked a function called {@code PROD}: the
- * message was accepted, reported as published, and delivered nowhere.
- */
- @Test
- void extractFunctionNameIgnoresTheQualifier() {
- String base = "arn:aws:lambda:us-east-1:000000000000:function:order-processor";
-
- assertEquals("order-processor", SnsService.extractFunctionName(base));
- assertEquals("order-processor", SnsService.extractFunctionName(base + ":PROD"));
- assertEquals("order-processor", SnsService.extractFunctionName(base + ":42"));
- assertEquals("order-processor", SnsService.extractFunctionName(base + ":$LATEST"));
- }
-
- /** Other partitions carry the same resource grammar. */
- @Test
- void extractFunctionNameWorksInAnyPartition() {
- assertEquals("order-processor", SnsService.extractFunctionName(
- "arn:aws-us-gov:lambda:us-gov-west-1:000000000000:function:order-processor:PROD"));
- }
-
- /** A bare function name is a legal endpoint too and passes through unchanged. */
- @Test
- void extractFunctionNameLeavesABareNameAlone() {
- assertEquals("order-processor", SnsService.extractFunctionName("order-processor"));
- assertNull(SnsService.extractFunctionName(null));
- }
-
private static Map attr(String name, String value, String dataType) {
return Map.of(name, new MessageAttributeValue(value, dataType));
}
@@ -844,6 +815,25 @@ class SnsServiceTest {
assertFalse(snsService.matchesFilterPolicy(nested, body("{\"detail\":{\"b\":\"3\"}}"), null));
}
+ @Test
+ void publish_invokesTheQualifiedLambdaSubscriptionEndpoint() {
+ LambdaService lambdaService = mock(LambdaService.class);
+ SnsService service = new SnsService(
+ new InMemoryStorage<>(),
+ new InMemoryStorage<>(),
+ new RegionResolver(REGION, ACCOUNT),
+ null,
+ lambdaService
+ );
+ Topic topic = service.createTopic("lambda-topic", null, null, REGION);
+ String aliasArn = "arn:aws:lambda:us-east-1:000000000000:function:order-processor:PROD";
+ service.subscribe(topic.getTopicArn(), "lambda", aliasArn, REGION, Map.of());
+
+ service.publish(topic.getTopicArn(), null, "hello", null, REGION);
+
+ verify(lambdaService).invoke(eq(REGION), eq(aliasArn), any(byte[].class), eq(InvocationType.Event));
+ }
+
@Test
void publish_deliversToFirehoseSubscription_withJsonEnvelope() throws Exception {
FirehoseService firehoseService = mock(FirehoseService.class);
diff --git a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorLambdaInvokeResultTest.java b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorLambdaInvokeResultTest.java
index 357b15bac8..8bbb67082c 100644
--- a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorLambdaInvokeResultTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorLambdaInvokeResultTest.java
@@ -5,10 +5,13 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbJsonHandler;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbService;
+import io.github.hectorvent.floci.services.lambda.LambdaAliasStore;
import io.github.hectorvent.floci.services.lambda.LambdaExecutorService;
import io.github.hectorvent.floci.services.lambda.LambdaFunctionStore;
+import io.github.hectorvent.floci.services.lambda.LambdaTargetResolver;
import io.github.hectorvent.floci.services.lambda.model.InvocationType;
import io.github.hectorvent.floci.services.lambda.model.InvokeResult;
+import io.github.hectorvent.floci.services.lambda.model.LambdaAlias;
import io.github.hectorvent.floci.services.lambda.model.LambdaFunction;
import io.github.hectorvent.floci.services.s3.S3Service;
import io.github.hectorvent.floci.services.sns.SnsJsonHandler;
@@ -54,14 +57,18 @@ class AslExecutorLambdaInvokeResultTest {
private final ObjectMapper objectMapper = new ObjectMapper();
private AslExecutor executor;
+ private LambdaExecutorService lambdaExecutor;
+ private LambdaFunctionStore functionStore;
+ private LambdaAliasStore aliasStore;
@Inject
Vertx vertx;
@BeforeEach
void setUp() throws Exception {
- LambdaExecutorService lambdaExecutor = mock(LambdaExecutorService.class);
- LambdaFunctionStore functionStore = mock(LambdaFunctionStore.class);
+ lambdaExecutor = mock(LambdaExecutorService.class);
+ functionStore = mock(LambdaFunctionStore.class);
+ aliasStore = mock(LambdaAliasStore.class);
LambdaFunction function = new LambdaFunction();
function.setFunctionName(FUNCTION_NAME);
function.setFunctionArn(FUNCTION_ARN);
@@ -78,7 +85,7 @@ class AslExecutorLambdaInvokeResultTest {
executor = new AslExecutor(
lambdaExecutor,
- functionStore,
+ new LambdaTargetResolver(functionStore, aliasStore),
mock(DynamoDbService.class),
mock(DynamoDbJsonHandler.class),
mock(SqsJsonHandler.class), mock(SnsJsonHandler.class),
@@ -90,6 +97,7 @@ class AslExecutorLambdaInvokeResultTest {
mock(io.github.hectorvent.floci.services.eventbridge.EventBridgeHandler.class),
mock(io.github.hectorvent.floci.services.scheduler.SchedulerService.class),
mock(io.github.hectorvent.floci.services.scheduler.SchedulerController.class),
+ null,
objectMapper,
new JsonataEvaluator(objectMapper),
mock(Instance.class), mock(EmulatorConfig.class), vertx, null);
@@ -245,6 +253,68 @@ class AslExecutorLambdaInvokeResultTest {
assertEquals(1, output.path("echo").path("in").asInt());
}
+ @Test
+ void directVersionQualifiedArnInvokesThatVersion() throws Exception {
+ stubVersion("1", "V1");
+
+ Execution execution = run("""
+ {
+ "StartAt": "Call",
+ "States": {
+ "Call": {
+ "Type": "Task",
+ "Resource": "%s:1",
+ "End": true
+ }
+ }
+ }
+ """.formatted(FUNCTION_ARN));
+
+ assertEquals("SUCCEEDED", execution.getStatus());
+ assertEquals("V1", objectMapper.readTree(execution.getOutput()).path("marker").asText());
+ }
+
+ @Test
+ void optimizedInvokeWithAliasInvokesTheAliasVersion() throws Exception {
+ stubVersion("2", "V2");
+ LambdaAlias alias = new LambdaAlias();
+ alias.setName("live");
+ alias.setFunctionName(FUNCTION_NAME);
+ alias.setFunctionVersion("2");
+ when(aliasStore.get(REGION, FUNCTION_NAME, "live")).thenReturn(Optional.of(alias));
+
+ Execution execution = run("""
+ {
+ "StartAt": "Call",
+ "States": {
+ "Call": {
+ "Type": "Task",
+ "Resource": "arn:aws:states:::lambda:invoke",
+ "Parameters": {"FunctionName": "%s:live", "Payload": {}},
+ "End": true
+ }
+ }
+ }
+ """.formatted(FUNCTION_ARN));
+
+ assertEquals("SUCCEEDED", execution.getStatus());
+ JsonNode output = objectMapper.readTree(execution.getOutput());
+ assertEquals("V2", output.path("Payload").path("marker").asText());
+ assertEquals("2", output.path("ExecutedVersion").asText());
+ }
+
+ private void stubVersion(String version, String marker) throws Exception {
+ LambdaFunction function = new LambdaFunction();
+ function.setFunctionName(FUNCTION_NAME);
+ function.setFunctionArn(FUNCTION_ARN + ":" + version);
+ function.setVersion(version);
+ when(functionStore.get(REGION, FUNCTION_NAME, version)).thenReturn(Optional.of(function));
+ when(lambdaExecutor.invoke(eq(function), any(byte[].class), eq(InvocationType.RequestResponse)))
+ .thenReturn(new InvokeResult(200, null,
+ objectMapper.writeValueAsBytes(objectMapper.createObjectNode().put("marker", marker)),
+ null, "version-request"));
+ }
+
private Execution run(String definition) {
StateMachine stateMachine = new StateMachine();
stateMachine.setName("lambda-invoke-result");