Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update sam local invoke to support new runtime options #7885

Merged
merged 10 commits into from
Mar 1, 2025

Conversation

jonife
Copy link
Contributor

@jonife jonife commented Feb 12, 2025

Why is this change necessary?

Enable testing Lambda functions with a different runtime than specified in the function configuration.

Test using a compatible runtime version: build artifact was in python3.13 and test runtime was python3.11.

jonife@80a9972c3483 sam-app % samdev local invoke --runtime python3.11
2025-02-12 15:00:00 Attaching import module proxy for analyzing dynamic imports
No current session found, using default AWS::AccountId                                                                                                                                                        
Invoking app.lambda_handler (python3.13)                                                                                                                                                                      
Local image is up-to-date                                                                                                                                                                                     
Using local image: public.ecr.aws/lambda/python:3.11-rapid-x86_64.                                                                                                                                            
                                                                                                                                                                                                              
Mounting /Users/jonife/Documents/dev/aws-sam-cli/sam-app/.aws-sam/build/HelloWorldFunction as /var/task:ro,delegated, inside runtime container                                                                
START RequestId: 75413eb4-7d36-4199-a993-218bd461b9fa Version: $LATEST
END RequestId: eea22581-421f-4a43-913d-3a834b71b055
REPORT RequestId: eea22581-421f-4a43-913d-3a834b71b055  Init Duration: 1.58 ms  Duration: 312.49 ms     Billed Duration: 313 ms Memory Size: 128 MB     Max Memory Used: 128 MB
{"statusCode": 200, "body": "{\"message\": \"hello world\"}"}

Test using an incompatible runtime: build artifact was in python3.13 and test runtime was java11.

jonife@80a9972c3483 sam-app % samdev local invoke --runtime java11    
2025-02-12 15:00:46 Attaching import module proxy for analyzing dynamic imports
No current session found, using default AWS::AccountId                                                                                                                                                        
Invoking app.lambda_handler (python3.13)                                                                                                                                                                      
Local image is up-to-date                                                                                                                                                                                     
Using local image: public.ecr.aws/lambda/java:11-rapid-x86_64.                                                                                                                                                
                                                                                                                                                                                                              
Mounting /Users/jonife/Documents/dev/aws-sam-cli/sam-app/.aws-sam/build/HelloWorldFunction as /var/task:ro,delegated, inside runtime container                                                                
START RequestId: e0af6df0-a576-440c-89fb-2f995f05f39d Version: $LATEST
Class not found: app.lambda_handler: Runtime.ClassNotFound
java.lang.ClassNotFoundException: app.lambda_handler. Current classpath: file:/var/task/

12 Feb 2025 23:00:50,192 [ERROR] (rapid) Init failed InvokeID= error=Runtime exited with error: exit status 1
12 Feb 2025 23:00:50,196 [ERROR] (rapid) Invoke failed InvokeID=f491b398-209c-48c4-8c4c-e71bfed2e388 error=Runtime exited with error: exit status 1
12 Feb 2025 23:00:50,197 [ERROR] (rapid) Invoke DONE failed: Sandbox.Failure
{"errorMessage": "Class not found: app.lambda_handler", "errorType": "Runtime.ClassNotFound"}

Mandatory Checklist

PRs will only be reviewed after checklist is complete

  • Add input/output type hints to new functions/methods
  • Write design document if needed (Do I need to write a design document?)
  • Write/update unit tests
  • Write/update integration tests
  • Write/update functional tests if needed
  • make pr passes
  • 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.

@jonife jonife requested a review from a team as a code owner February 12, 2025 23:27
@github-actions github-actions bot added area/local/invoke sam local invoke command area/schema JSON schema file pr/external stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. labels Feb 12, 2025
"-r",
"--runtime",
type=click.Choice(get_sorted_runtimes(INIT_RUNTIMES)),
help="Lambda runtime for application."
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can get a better text here. I would suggest:

Lambda runtime used to invoke the function.

(in particular "function" instead of "application")

Copy link
Contributor

Choose a reason for hiding this comment

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

Updated.

@mbfreder mbfreder added this pull request to the merge queue Mar 1, 2025
Merged via the queue into aws:develop with commit e3fa341 Mar 1, 2025
50 checks passed
justinmk3 pushed a commit to aws/aws-toolkit-vscode that referenced this pull request Mar 6, 2025
## Problem
Customers are not able to local invoke with the runtime selected in the
webview UI. Currently the runtime used is the one specified on the
template. The feature was already added to SAMCLI
aws/aws-sam-cli#7885.

## Solution
Allows customers to change runtimes when locally invoking in the local
invoke webview, without having to change it in their template and
rebuilding. Under the hood, the newly added ```--runtime``` option will
be appended to the ```samcli``` command.
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/schema JSON schema file 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.

4 participants