fix(lambda): accept FunctionName as ARN / partial ARN / qualified name (#817)#819
Closed
vieiralucas wants to merge 2 commits intomainfrom
Closed
fix(lambda): accept FunctionName as ARN / partial ARN / qualified name (#817)#819vieiralucas wants to merge 2 commits intomainfrom
vieiralucas wants to merge 2 commits intomainfrom
Conversation
GetFunction (and every other Lambda op that takes FunctionName) was treating the path-segment / body identifier as a literal map key into state.functions. Real AWS accepts four equivalent forms: - plain name: my-fn - qualified name: my-fn:PROD - full ARN: arn:aws:lambda:REGION:ACCOUNT:function:my-fn[:Q] - partial ARN: ACCOUNT:function:my-fn[:Q] The AWS Toolkit for VS Code calls GetFunction with the full ARN, so fakecloud was returning 404 for every function and the toolkit listed nothing. Reported in issue #817. Adds a resolve_function_name helper that collapses any of the four forms (and percent-encoded variants the AWS SDK emits in path components) to the bare function name. Applied at the dispatch site for FunctionName-bearing actions only — Tag/EventSourceMapping/ Layer/CodeSigningConfig/CapacityProvider/DurableExecution actions keep their original identifier. Also normalizes body-derived FunctionName in CreateFunction and CreateEventSourceMapping, plus the IAM action-resource ARN so it doesn't double-wrap. Covers: 13 unit tests (helper + dispatch round-trip via GetFunction and DeleteFunction with full/partial/qualified/percent-encoded ARN) and one E2E test exercising every form through the AWS SDK.
There was a problem hiding this comment.
1 issue found across 4 files
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:191">
P1: The generic `split_once(':')` fallback over-normalizes unknown identifiers (for example non-Lambda ARNs) to the text before the first colon, which can route requests to the wrong function instead of preserving the original identifier.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
…nputs Cubic flagged that the qualifier-stripping fallback collapsed any colon-bearing identifier to its prefix, including foreign ARNs like `arn:aws:s3:::bucket` which would resolve to `arn`. Real Lambda qualifiers can't contain `:` (`$LATEST | [a-zA-Z0-9-_]+ | [0-9]+`), so a well-formed `name:qualifier` has exactly one colon. The fallback now only fires when (a) the input has exactly one colon and (b) the prefix matches Lambda's `[a-zA-Z0-9-_]+` function-name regex. Foreign ARNs and multi-colon garbage pass through unchanged so the caller surfaces a 404 with the original identifier instead of silently routing to a truncated prefix. Adds is_valid_function_name helper + foreign_arn_passthrough test covering S3 / SNS / IAM ARNs. Updates the partial-ARN-with-bad-account test to expect passthrough.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Member
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
GetFunction(and every other op takingFunctionName) was using the literal path / body string as astate.functionsmap key. AWS accepts four equivalent forms — plain name, qualified name, full ARN, partial ARN — so the AWS Toolkit for VS Code (which callsGetFunctionwith the full ARN) listed zero functions.resolve_function_namehelper collapses every form, plus percent-encoded ARN segments emitted by AWS SDKs (arn%3Aaws%3Alambda%3A...), to the bare function name.CreateFunction+CreateEventSourceMapping, and the IAM-action resource ARN so it doesn't double-wrap.Fixes #817.
Test plan
service.rscovering the helper across plain / qualified / full ARN / partial ARN / percent-encoded / unknown-shape passthrough, plus three end-to-end dispatch tests forGetFunctionandDeleteFunctionvia path with a full ARN.lambda_function_name_accepts_all_arn_formsexercising every form (plain qualifier, full ARN, qualified full ARN, partial ARN) and a delete-by-ARN through the AWS SDK.cargo test -p fakecloud-lambda --lib— 78 passing.cargo test -p fakecloud-e2e --test lambda— 7 passing (including the new test).cargo clippy --workspace --all-targets -- -D warningsclean.cargo fmt --all.Summary by cubic
Accepts Lambda
FunctionNameas plain name, qualified name, full ARN, or partial ARN across all relevant ops. Fixes #817 whereGetFunctionwith a full ARN returned 404 (e.g., from the AWS Toolkit for VS Code).Bug Fixes
resolve_function_namehelper to collapse all forms (including percent-encoded ARNs) to the bare name; tightened fallback to only single-colon inputs with valid names so foreign ARNs and multi-colon values pass through unchanged.FunctionNameinCreateFunctionandCreateEventSourceMapping, and fixes IAM action resource ARN to avoid double-wrapping.Dependencies
percent-encodingfor decoding encoded ARN segments.Written for commit 298757e. Summary will update on new commits. Review in cubic