Skip to content

fix(lambda): accept FunctionName as ARN / partial ARN / qualified name (#817)#819

Closed
vieiralucas wants to merge 2 commits intomainfrom
worktree-issue-817-lambda-arn
Closed

fix(lambda): accept FunctionName as ARN / partial ARN / qualified name (#817)#819
vieiralucas wants to merge 2 commits intomainfrom
worktree-issue-817-lambda-arn

Conversation

@vieiralucas
Copy link
Copy Markdown
Member

@vieiralucas vieiralucas commented Apr 28, 2026

Summary

  • Lambda's GetFunction (and every other op taking FunctionName) was using the literal path / body string as a state.functions map key. AWS accepts four equivalent forms — plain name, qualified name, full ARN, partial ARN — so the AWS Toolkit for VS Code (which calls GetFunction with the full ARN) listed zero functions.
  • New resolve_function_name helper collapses every form, plus percent-encoded ARN segments emitted by AWS SDKs (arn%3Aaws%3Alambda%3A...), to the bare function name.
  • Applied at dispatch only for FunctionName-bearing actions; Tag/EventSourceMapping/Layer/CodeSigningConfig/CapacityProvider/DurableExecution resources keep their original identifier. Also normalizes body-derived FunctionName in CreateFunction + CreateEventSourceMapping, and the IAM-action resource ARN so it doesn't double-wrap.

Fixes #817.

Test plan

  • 13 new unit tests in service.rs covering the helper across plain / qualified / full ARN / partial ARN / percent-encoded / unknown-shape passthrough, plus three end-to-end dispatch tests for GetFunction and DeleteFunction via path with a full ARN.
  • New E2E lambda_function_name_accepts_all_arn_forms exercising 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 warnings clean.
  • cargo fmt --all.

Summary by cubic

Accepts Lambda FunctionName as plain name, qualified name, full ARN, or partial ARN across all relevant ops. Fixes #817 where GetFunction with a full ARN returned 404 (e.g., from the AWS Toolkit for VS Code).

  • Bug Fixes

    • Added a resolve_function_name helper 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.
    • Applied at dispatch for all FunctionName-bearing actions; other resource types are unchanged. Normalizes body FunctionName in CreateFunction and CreateEventSourceMapping, and fixes IAM action resource ARN to avoid double-wrapping.
    • Expanded unit tests and added a new E2E covering all forms.
  • Dependencies

    • Added percent-encoding for decoding encoded ARN segments.

Written for commit 298757e. Summary will update on new commits. Review in cubic

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.
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 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.

Comment thread crates/fakecloud-lambda/src/service.rs Outdated
…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
Copy link
Copy Markdown

codecov Bot commented Apr 28, 2026

Codecov Report

❌ Patch coverage is 98.03922% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/fakecloud-lambda/src/service.rs 98.03% 4 Missing ⚠️

📢 Thoughts on this report? Let us know!

@vieiralucas
Copy link
Copy Markdown
Member Author

Closing as duplicate. Issue #817 was independently fixed and shipped via #822 (merged 13:23 UTC) using the same approach — normalize_function_name helper that strips full ARN, partial ARN, and qualifier suffix. No further action needed.

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.

Lambda GetFunction does not accept ARN, causing AWS Toolkit for VS Code to fail when listing Lambda functions

1 participant