Skip to content

armgit / floci

Public Imported from GitHub
0

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

feat(lambda): add support for UpdateFunctionConfiguration AWS API (#472)

edwintian5f07c772373d
diff --git a/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaController.java b/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaController.java
index d055ec6156..0276c65b41 100644
--- a/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaController.java
+++ b/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaController.java
@@ -123,6 +123,26 @@ public class LambdaController {
return Response.ok(buildFunctionConfiguration(fn)).build();
}
+ // ──────────────────────────── UpdateFunctionConfiguration ────────────────────────────
+
+ @PUT
+ @Path("/functions/{functionName}/configuration")
+ public Response updateFunctionConfiguration(@Context HttpHeaders headers,
+ @PathParam("functionName") String functionName,
+ String body) {
+ String region = regionResolver.resolveRegion(headers);
+ try {
+ @SuppressWarnings("unchecked")
+ Map<String, Object> request = objectMapper.readValue(body, Map.class);
+ LambdaFunction fn = lambdaService.updateFunctionConfiguration(region, functionName, request);
+ return Response.ok(buildFunctionConfiguration(fn)).build();
+ } catch (AwsException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new AwsException("InvalidParameterValueException", e.getMessage(), 400);
+ }
+ }
+
// ──────────────────────────── UpdateFunctionCode ────────────────────────────
@PUT
diff --git a/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaService.java b/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaService.java
index 81013eda49..30610eb479 100644
--- a/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaService.java
@@ -323,6 +323,48 @@ public class LambdaService {
return fn;
}
+ public LambdaFunction updateFunctionConfiguration(String region, String functionName, Map<String, Object> request) {
+ LambdaFunction fn = getFunction(region, functionName);
+
+ if (request.containsKey("Description")) {
+ fn.setDescription((String) request.get("Description"));
+ }
+ if (request.containsKey("Handler")) {
+ fn.setHandler((String) request.get("Handler"));
+ }
+ if (request.containsKey("MemorySize")) {
+ fn.setMemorySize(((Number) request.get("MemorySize")).intValue());
+ }
+ if (request.containsKey("Role")) {
+ fn.setRole((String) request.get("Role"));
+ }
+ if (request.containsKey("Runtime")) {
+ fn.setRuntime((String) request.get("Runtime"));
+ }
+ if (request.containsKey("Timeout")) {
+ fn.setTimeout(((Number) request.get("Timeout")).intValue());
+ }
+ if (request.containsKey("Environment")) {
+ @SuppressWarnings("unchecked")
+ Map<String, Object> envBlock = (Map<String, Object>) request.get("Environment");
+ if (envBlock != null && envBlock.containsKey("Variables")) {
+ @SuppressWarnings("unchecked")
+ Map<String, String> vars = (Map<String, String>) envBlock.get("Variables");
+ fn.setEnvironment(vars != null ? vars : new java.util.HashMap<>());
+ }
+ }
+
+ fn.setLastModified(System.currentTimeMillis());
+ fn.setRevisionId(UUID.randomUUID().toString());
+
+ // Drain warm containers so the next invocation picks up the new configuration
+ warmPool.drainFunction(functionName);
+
+ functionStore.save(region, fn);
+ LOG.infov("Updated configuration for function: {0}", functionName);
+ return fn;
+ }
+
public void deleteFunction(String region, String functionName) {
LambdaFunction fn = getFunction(region, functionName); // throws 404 if not found
functionName = fn.getFunctionName();
diff --git a/src/test/java/io/github/hectorvent/floci/services/lambda/LambdaIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/lambda/LambdaIntegrationTest.java
index f76714f388..3a04b6963c 100644
--- a/src/test/java/io/github/hectorvent/floci/services/lambda/LambdaIntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/lambda/LambdaIntegrationTest.java
@@ -167,6 +167,53 @@ class LambdaIntegrationTest {
@Test
@Order(10)
+ void updateFunctionConfiguration() {
+ given()
+ .contentType("application/json")
+ .body("""
+ {
+ "Timeout": 60,
+ "MemorySize": 512,
+ "Description": "Updated description",
+ "Environment": {
+ "Variables": {
+ "MY_KEY": "my-value",
+ "ANOTHER_KEY": "another-value"
+ }
+ }
+ }
+ """)
+ .when()
+ .put(BASE_PATH + "/functions/hello-world/configuration")
+ .then()
+ .statusCode(200)
+ .body("FunctionName", equalTo("hello-world"))
+ .body("Timeout", equalTo(60))
+ .body("MemorySize", equalTo(512))
+ .body("Description", equalTo("Updated description"))
+ .body("Environment.Variables.MY_KEY", equalTo("my-value"))
+ .body("Environment.Variables.ANOTHER_KEY", equalTo("another-value"))
+ .body("RevisionId", notNullValue());
+ }
+
+ @Test
+ @Order(11)
+ void updateFunctionConfiguration_notFound_returns404() {
+ given()
+ .contentType("application/json")
+ .body("""
+ {
+ "Timeout": 30
+ }
+ """)
+ .when()
+ .put(BASE_PATH + "/functions/nonexistent-function/configuration")
+ .then()
+ .statusCode(404);
+ }
+
+ @Test
+ @Order(12)
void deleteFunction() {
given()
.when()
@@ -176,7 +223,7 @@ class LambdaIntegrationTest {
}
@Test
- @Order(11)
+ @Order(13)
void deletedFunctionNotFound() {
given()
.when()
@@ -186,7 +233,7 @@ class LambdaIntegrationTest {
}
@Test
- @Order(12)
+ @Order(14)
void createFunctionWithLargeInlineZip() throws Exception {
// Build a valid zip with a handler file + 16 MB padding so the base64
// encoding exceeds Jackson's former 20 MB maxStringLength default.