Skip to content

armgit / floci

Public Imported from GitHub
0

Light, fluffy, and always free - The AWS Local Emulator alternative

fix(lambda): reject provisioned concurrency for SnapStart versions (#6433)

Andre Kurait01b388eca9e7
diff --git a/docs/services/lambda.md b/docs/services/lambda.md
index b459a20bfa..3d58055c5e 100644
--- a/docs/services/lambda.md
+++ b/docs/services/lambda.md
@@ -454,6 +454,12 @@ rejects one outright with `InvalidParameterValueException: Invalid layer version
## Provisioned concurrency
+Published versions with `SnapStart.ApplyOn=PublishedVersions` reject provisioned concurrency
+with `ResourceConflictException`, including through an alias. A configured alias cannot
+retarget to such a version. Eligibility uses the published snapshot, so changing `$LATEST`
+does not change older versions. Get and Delete retain their normal configuration lookup
+behavior, and unconfigured aliases can still point to SnapStart versions.
+
Put, Get and Delete use `/2019-09-30/functions/{FunctionName}/provisioned-concurrency`
with a required `Qualifier` query parameter. Put accepts a positive integer
`ProvisionedConcurrentExecutions` and returns HTTP 202 with `IN_PROGRESS`. An existing
diff --git a/src/main/java/io/github/hectorvent/floci/services/lambda/ProvisionedConcurrencyPool.java b/src/main/java/io/github/hectorvent/floci/services/lambda/ProvisionedConcurrencyPool.java
index 556bbcb6d4..984047a58d 100644
--- a/src/main/java/io/github/hectorvent/floci/services/lambda/ProvisionedConcurrencyPool.java
+++ b/src/main/java/io/github/hectorvent/floci/services/lambda/ProvisionedConcurrencyPool.java
@@ -496,6 +496,10 @@ public class ProvisionedConcurrencyPool implements Resettable {
}
private static void validateSupportedTarget(LambdaFunction fn) {
+ if ("PublishedVersions".equals(fn.getSnapStartApplyOn())) {
+ throw new AwsException("ResourceConflictException", "The operation cannot be performed at this time. "
+ + "Provisioned Concurrency is not supported for SnapStart enabled functions", 409);
+ }
if (fn.isHotReload() || fn.isDurable()) {
throw invalid("Provisioned concurrency is not supported for hot-reload or durable functions");
}
diff --git a/src/test/java/io/github/hectorvent/floci/services/lambda/ProvisionedConcurrencyPoolTest.java b/src/test/java/io/github/hectorvent/floci/services/lambda/ProvisionedConcurrencyPoolTest.java
index 97b2ac2e70..8afa6d1bc8 100644
--- a/src/test/java/io/github/hectorvent/floci/services/lambda/ProvisionedConcurrencyPoolTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/lambda/ProvisionedConcurrencyPoolTest.java
@@ -102,6 +102,70 @@ class ProvisionedConcurrencyPoolTest {
return pool.put(REGION, "example", "live", count, ACCOUNT);
}
+ @ParameterizedTest
+ @CsvSource({"1, None", "live, None", "1, PublishedVersions", "live, PublishedVersions"})
+ void snapStartEligibilityUsesThePublishedSnapshot(String qualifier, String latestApplyOn) {
+ version.setSnapStartApplyOn("PublishedVersions");
+ functions.getForAccount(ACCOUNT, REGION, "example").orElseThrow().setSnapStartApplyOn(latestApplyOn);
+
+ AwsException error = assertThrows(AwsException.class,
+ () -> pool.put(REGION, "example", qualifier, 1, ACCOUNT));
+
+ assertSnapStartConflict(error);
+ assertTrue(storage.scanAllAccounts().isEmpty());
+ assertEquals("ProvisionedConcurrencyConfigNotFoundException",
+ assertThrows(AwsException.class, () -> pool.get(REGION, "example", qualifier, ACCOUNT)).getErrorCode());
+ assertDoesNotThrow(() -> pool.delete(REGION, "example", qualifier, ACCOUNT));
+ }
+
+ @ParameterizedTest
+ @ValueSource(strings = {"1", "live"})
+ void latestSnapStartDoesNotDisqualifyAnOlderVersion(String qualifier) {
+ functions.getForAccount(ACCOUNT, REGION, "example").orElseThrow().setSnapStartApplyOn("PublishedVersions");
+
+ assertEquals(1, pool.put(REGION, "example", qualifier, 1, ACCOUNT).requested());
+ assertEquals(1, pool.put(REGION, "example", qualifier, 1, ACCOUNT).requested());
+ }
+
+ @Test
+ void provisionedAliasCannotRetargetToASnapStartVersion() {
+ function(ACCOUNT, REGION, "2").setSnapStartApplyOn("PublishedVersions");
+ put(1);
+
+ assertSnapStartConflict(assertThrows(AwsException.class,
+ () -> pool.validateAliasUpdate(version, "live", "2")));
+ assertEquals("1", storage.scanAllAccounts().getFirst().version());
+ assertEquals(1, get().requested());
+ assertDoesNotThrow(() -> pool.validateAliasUpdate(version, "live", null));
+ assertDoesNotThrow(() -> pool.validateAliasUpdate(version, "unconfigured", "2"));
+ pool.delete(REGION, "example", "live", ACCOUNT);
+ assertDoesNotThrow(() -> pool.validateAliasUpdate(version, "live", "2"));
+ }
+
+ @Test
+ void aliasSnapStartValidationUsesTheFunctionOwnerAndRegion() {
+ function(ACCOUNT, REGION, "2");
+ String owner = "222222222222";
+ String region = "eu-west-1";
+ LambdaFunction foreign = function(owner, region, "$LATEST");
+ function(owner, region, "1");
+ function(owner, region, "2").setSnapStartApplyOn("PublishedVersions");
+ alias(owner, region, "live", "1", Map.of());
+ pool.put(region, "example", "live", 1, owner);
+
+ assertSnapStartConflict(assertThrows(AwsException.class,
+ () -> pool.validateAliasUpdate(foreign, "live", "2")));
+ put(1);
+ assertDoesNotThrow(() -> pool.validateAliasUpdate(version, "live", "2"));
+ }
+
+ private static void assertSnapStartConflict(AwsException error) {
+ assertEquals("ResourceConflictException", error.getErrorCode());
+ assertEquals(409, error.getHttpStatus());
+ assertEquals("The operation cannot be performed at this time. "
+ + "Provisioned Concurrency is not supported for SnapStart enabled functions", error.getMessage());
+ }
+
@ParameterizedTest
@ValueSource(strings = {"example", "absent"})
void unpublishedVersionErrorsDependOnTheOperation(String name) {