fix(lambda): invoke the version or alias that a qualified function reference names (#4231)

* fix(lambda): invoke the version or alias an event source mapping names

An event source mapping created with a qualified FunctionName, such as
my-fn:1 or my-fn:prod, always invoked $LATEST. The SQS, Kinesis and
DynamoDB Streams pollers now read the qualifier from the mapping's function
ARN. They invoke that version, or the version the alias points to.

* fix(sns): invoke the version or alias a Lambda subscription names

A Lambda subscription to a qualified ARN, such as my-fn:PROD, always invoked
$LATEST because the qualifier was cut off before the invoke. The full
endpoint ARN now goes to the Lambda invoke, which resolves the qualifier.

* fix(s3): invoke the version or alias a Lambda notification names

A bucket notification to a qualified function ARN, such as my-fn:PROD,
always invoked $LATEST because the qualifier was cut off before the invoke.
The qualifier now stays on the function reference passed to Lambda.

* fix(pipes): invoke the version or alias a Lambda target or enrichment names

A pipe whose target or enrichment is a qualified function ARN, such as
my-fn:PROD, always invoked $LATEST because the qualifier was cut off before
the invoke. The qualifier now stays on the function reference passed to
Lambda.

* fix(stepfunctions): invoke the version or alias a Lambda task names

A Lambda task whose Resource or FunctionName is qualified, such as my-fn:1 or
my-fn:PROD, always invoked $LATEST because the qualifier was cut off before
the function lookup. The task now invokes that version, or the version the
alias points to.

* test(lambda): run an SQS event source mapping on an alias through a real function

The alias points to version 1, which succeeds. $LATEST throws. The message
leaves the queue only when the mapping invokes the alias version.

* fix(lambda): resolve a qualified function in one place

LambdaService, the event source mapping pollers and the Step Functions
executor each had their own copy of the qualifier rule. The rule now lives in
LambdaTargetResolver, which all of them use. Mappings and Step Functions
tasks on an alias with AdditionalVersionWeights now follow the weights, as
a direct invoke already did.

* test(lambda): drop the Docker SQS alias mapping test

It starts a real function and waits on the queue on every CI run with
Docker. LambdaServiceTest and the poller unit tests already cover a mapping
on an alias through the shared resolver.
This commit is contained in:
TATSUNO “Taz” Yasuhiro authored and GitHub committed 2026-09-24 07:24:32 -04:00
1 parent 196d1586da
commit 6d95dfe3e1
17 files changed
+487 -216

No files matched your search

@@ -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(
@@ -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();
@@ -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,
@@ -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();
@@ -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
@@ -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(
@@ -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<String, MessageAttributeValue> 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);
@@ -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");