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

Bug: sam local invoke - Failed to load #7831

Open
f1-f12-projects opened this issue Jan 10, 2025 · 1 comment
Open

Bug: sam local invoke - Failed to load #7831

f1-f12-projects opened this issue Jan 10, 2025 · 1 comment
Labels
blocked/more-info-needed More info is needed from the requester. If no response in 14 days, it will become stale.

Comments

@f1-f12-projects
Copy link

f1-f12-projects commented Jan 10, 2025

Description: Created new sam project and replaced lambda_handler with flask_lambda. Unable to start the server due to various dependency issues.

Steps to reproduce:

  1. Create new project with command:
    sam init —name xxxx
    Note: I can build and start the api.

  2. Replace lambda_handler with flask_handler. Below is the code of app.py:

from flask_lambda import FlaskLambda
from flask import request, app

app = FlaskLambda(__name__)

@app.route('/hello')
def hello():
    print (request.args.get('name'))
    return "Hello World"

  1. Downgraded version of werkzeug to 2.0.3 due to dependency issues (BaseRequest).
  2. Update Requirements.txt as below:
requests
flask_lambda
flask==3.0.3
Werkzeug==2.0.3
  1. start build —> Successful
  2. start local invoke - Out of sam local invoke:
Invoking app.app (python3.12)                                                                                                                                                             
Local image is up-to-date                                                                                                                                                                 
Using local image: public.ecr.aws/lambda/python:3.12-rapid-x86_64.                                                                                                                        
                                                                                                                                                                                          
Mounting ProjectFolder/aws/vk-aws-flask-testing/.aws-sam/build/HelloWorldFunction as /var/task:ro,delegated, inside runtime  
container                                                                                                                                                                                 
START RequestId: 3ce5e5c2-4b90-410c-b117-c20db0700ec8 Version: $LATEST
{"timestamp": "2025-01-10T23:20:02Z", "log_level": "ERROR", "errorMessage": "Unable to import module 'app': No module named 'flask_lambda'", "errorType": "Runtime.ImportModuleError", "requestId": "", "stackTrace": []}
10 Jan 2025 23:20:02,509 [ERROR] (rapid) Init failed error=Runtime exited with error: exit status 1 InvokeID=
10 Jan 2025 23:20:02,514 [ERROR] (rapid) Invoke failed error=Runtime exited with error: exit status 1 InvokeID=2c5f0794-306b-4c16-baaa-7ed4411562b8
10 Jan 2025 23:20:02,515 [ERROR] (rapid) Invoke DONE failed: Sandbox.Failure
{"errorMessage": "Unable to import module 'app': No module named 'flask_lambda'", "errorType": "Runtime.ImportModuleError", "requestId": "", "stackTrace": []}
koteswarvijay@Vijays-MacBook-Air vk-aws-flask-testing % 

sam -info output:
{
  "version": "1.132.0",
  "system": {
    "python": "3.12.4",
    "os": "macOS-12.7.6-x86_64-i386-64bit"
  },
  "additional_dependencies": {
    "docker_engine": "27.4.0",
    "aws_cdk": "Not available",
    "terraform": "Not available"
  },
  "available_beta_feature_env_vars": [
    "SAM_CLI_BETA_FEATURES",
    "SAM_CLI_BETA_BUILD_PERFORMANCE",
    "SAM_CLI_BETA_TERRAFORM_SUPPORT",
    "SAM_CLI_BETA_RUST_CARGO_LAMBDA"
  ]
}

Updated templates.yaml:

Resources:
  HelloWorldFunction:
    Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
    Properties:
      CodeUri: hello_world/
      Handler: app.app
      Runtime: python3.12
      Architectures:
      - x86_64
      Events:
        HelloWorld:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            Path: /hello
            Method: get
@f1-f12-projects f1-f12-projects added the stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. label Jan 10, 2025
@roger-zhangg
Copy link
Member

Not sure if this helps, could you check if the following handler code works?

from flask import request
from flask_lambda import FlaskLambda

app = FlaskLambda(__name__)

@app.route('/hello')
def hello():
    print (request.args.get('name'))
    return "Hello World"

@roger-zhangg roger-zhangg added blocked/more-info-needed More info is needed from the requester. If no response in 14 days, it will become stale. and removed stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. labels Jan 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked/more-info-needed More info is needed from the requester. If no response in 14 days, it will become stale.
Projects
None yet
Development

No branches or pull requests

2 participants