Skip to content

refactor(lambda): extract CreateFunctionInput from create_function#339

Merged
vieiralucas merged 1 commit intomainfrom
worktree-cleanup+lambda-elasticache-splits
Apr 13, 2026
Merged

refactor(lambda): extract CreateFunctionInput from create_function#339
vieiralucas merged 1 commit intomainfrom
worktree-cleanup+lambda-elasticache-splits

Conversation

@vieiralucas
Copy link
Copy Markdown
Member

@vieiralucas vieiralucas commented Apr 13, 2026

Summary

`create_function` was 118 lines, most of which were field extraction and defaulting for the `CreateFunction` request shape: `FunctionName`, `Runtime`, `Role`, `Handler`, `Description`, `Timeout`, `MemorySize`, `PackageType`, `Tags`, `Environment.Variables`, `Architectures`, and `Code.ZipFile` (base64-decoded). Only the last ~35 lines actually did anything: check for conflict, hash the code, build `LambdaFunction`, insert.

Move the parsing into `CreateFunctionInput::from_body`. The operation body now reads as 'parse input, check conflict, hash code, build function, persist' without the 80-line prelude. The `Code.ZipFile` base64 decode stays in `from_body` so `InvalidParameterValueException` is still surfaced at parse time.

Test plan

  • `cargo fmt`
  • `cargo clippy --workspace --all-targets -- -D warnings`
  • `cargo test -p fakecloud-lambda` (8 passed)

Summary by cubic

Refactored Lambda function creation by extracting request parsing into CreateFunctionInput::from_body, making create_function smaller and easier to read. Invalid Code.ZipFile still fails fast with InvalidParameterValueException.

  • Refactors
    • Moved field extraction and defaults (FunctionName, Runtime, Role, Handler, Description, Timeout, MemorySize, PackageType, Tags, Environment.Variables, Architectures, Code.ZipFile) into CreateFunctionInput.
    • Streamlined create_function flow: parse input → check conflict → hash code → build and persist LambdaFunction.
    • Code hash prefers decoded ZIP bytes; falls back to raw Code JSON for image-based functions.

Written for commit 4745889. Summary will update on new commits.

create_function was 118 lines, most of which were field extraction
and defaulting for the CreateFunction request shape: FunctionName,
Runtime, Role, Handler, Description, Timeout, MemorySize, PackageType,
Tags, Environment.Variables, Architectures, and Code.ZipFile
(base64-decoded). Only the last ~35 lines actually did anything:
check for conflict, hash the code, build LambdaFunction, insert.

Move the parsing into CreateFunctionInput::from_body. The operation
body now reads as 'parse input, check conflict, hash code, build
function, persist' without the 80-line prelude. The Code.ZipFile
base64 decode stays in from_body so InvalidParameterValueException
is still surfaced at parse time.
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 1 file

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="crates/fakecloud-lambda/src/service.rs">

<violation number="1" location="crates/fakecloud-lambda/src/service.rs:192">
P2: `CreateFunction` now validates/decodes request payload before checking name conflict, which can return `InvalidParameterValueException` instead of `ResourceConflictException` for duplicate function names.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

)
})?
.to_string();
let input = CreateFunctionInput::from_body(&body)?;
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot Apr 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: CreateFunction now validates/decodes request payload before checking name conflict, which can return InvalidParameterValueException instead of ResourceConflictException for duplicate function names.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At crates/fakecloud-lambda/src/service.rs, line 192:

<comment>`CreateFunction` now validates/decodes request payload before checking name conflict, which can return `InvalidParameterValueException` instead of `ResourceConflictException` for duplicate function names.</comment>

<file context>
@@ -91,85 +189,21 @@ impl LambdaService {
-                )
-            })?
-            .to_string();
+        let input = CreateFunctionInput::from_body(&body)?;
 
         let mut state = self.state.write();
</file context>
Fix with Cubic

@vieiralucas vieiralucas merged commit 2a9fc1c into main Apr 13, 2026
22 of 24 checks passed
@vieiralucas vieiralucas deleted the worktree-cleanup+lambda-elasticache-splits branch April 13, 2026 03:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant