Skip to content

Conversation

bchampp
Copy link
Member

@bchampp bchampp commented Oct 3, 2025

Fixes #8289

Which issue(s) does this change fix?

#8289

Why is this change necessary?

The lambda invoke API supports multiple different formats for the function name parameter. However, SAM only supports matching the function name directly as it exists in the provided SAM template.

How does it address the issue?

This change updates SAM so that we support more flexible function name arguments. Now, we normalize the provided function name to be just the function name by extracting it from the full or partial ARN, and/or stripping the version provided.

Now, when invoking a function locally, we first normalize the provided function name field to extract just the function name.

Testing:
I have a SAM template which has a function "HelloWorld". I tested by invoking different variations that are supported of the function name:

# works as it did before
samdev local invoke HelloWorld

# alias, invokes HelloWorld function
samdev local invoke HelloWorld:alias 

# full function arn, invokes HelloWorld function
samdev local invoke arn:aws:lambda:us-east-1:123456789012:function:HelloWorld

# partial function arn, invokes HelloWorld function
samdev local invoke 123456789012:function:HelloWorld

I also updated the error handling around invalid function names to match what the lambda service does:

samdev local invoke :HelloWorld
                                                                                                                                                                                                                                                                 
Error: 1 validation error detected: Value ':HelloWorld' at 'functionName' failed to satisfy constraint: Member must satisfy regular expression pattern: ^(arn:[^:]+:lambda:[^:]*:\d{12}:function:|\d{12}:function:)?[a-zA-Z0-9-_\.]+(:[\w$-]+)?$

What side effects does this change have?

None.

Mandatory Checklist

PRs will only be reviewed after checklist is complete

  • [N/A] Add input/output type hints to new functions/methods
  • [N/A] Write design document if needed (Do I need to write a design document?)
  • Write/update unit tests
  • [N/A] Write/update integration tests
  • [N/A] Write/update functional tests if needed
  • make pr passes
  • [N/A] make update-reproducible-reqs if dependencies were changed
  • Write documentation

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@bchampp bchampp requested a review from a team as a code owner October 3, 2025 14:29
@github-actions github-actions bot added area/local/start-api sam local start-api command area/local/invoke sam local invoke command area/local/start-invoke pr/external stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. labels Oct 3, 2025
@bchampp bchampp force-pushed the feat/support-function-name-variations branch from 5c6d766 to ce025d5 Compare October 3, 2025 18:00
@bchampp bchampp force-pushed the feat/support-function-name-variations branch from ce025d5 to 4c2e09f Compare October 6, 2025 15:30
@bchampp bchampp force-pushed the feat/support-function-name-variations branch from 4c2e09f to 67ba5d5 Compare October 7, 2025 18:12
@bchampp bchampp force-pushed the feat/support-function-name-variations branch from 67ba5d5 to 554bcb3 Compare October 7, 2025 19:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/local/invoke sam local invoke command area/local/start-api sam local start-api command area/local/start-invoke pr/external stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request: SAM local lambda server should support function ARNs on invoke API.
3 participants