Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS lambda working without errors but i cannot return a value

I am not able to make my lambda ever return a value even though the code runs fine to right before the return statement. my return statement and the statement above it look like this:

print(score)
return {
        "StatusCode": 200,
        "headers":{'dummy':'dummy'},
        "body": str(score)
    }

Following is my serverless.yml:

service : test-deploy

plugins:
  - serverless-python-requirements
provider:
 name: aws
 runtime: python3.6
 region : ap-south-1
 deploymentBucket:
  name : smecornerdep-package
 iamRoleStatements:
  - Effect : Allow
    Action:
     - s3:GetObject
    Resource:
     - "arn:aws:s3:::smecornerdep/*"

custom:
 pythonRequirements:
  slim: True

functions:
 app-on-book-only:
  name: app-on-book-only
  description : deploy trained lightgbm on aws lambda using serverless
  handler : run_model_l.get_predictions
  events :
   - http : POST /engine

And I am hitting the end points with a POST from my command line like so:

curl -X POST -H "Content-Type: application/json" --data @sample_common_3.json https://76pmb6z1ya.execute-api.ap-south-1.amazonaws.com/dev/engine

In my aws lambda logs I can see the output of print(score) right above the return statement to be computed accurately. There are no errors in aws lambda logs. However, in my terminal I always get {"message": "Internal server error"} returned by the curl command.

I am a data scientist and fairly new to the concepts of dev ops. Please help me understand my mistake and also, suggest a solution.

Thank you for reading

like image 620
Nitin Siwach Avatar asked Dec 01 '25 11:12

Nitin Siwach


1 Answers

I know whats wrong with your code. You are using the wrong syntax in the return dictionary StatusCode should be statusCode

return {
    "statusCode": 200,
    "headers":{'dummy':'dummy'},
    "body": str(score)
}
like image 154
Pradeep Pathak Avatar answered Dec 04 '25 14:12

Pradeep Pathak



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!