title: Error message when I am trying lambda function to be integrated in API Gateway in AWS When I am checking the endpoint URL
body: <p>This is my main.py file which has lambda function defined in it.When I am trying to execute this in linux terminal with the following command, I am getting the output.</p>
  
  <p>Command used in linux terminal : sudo serverless invoke local -f aimodel-lambda -d '{"body":[500]}'
  output:</p>
  
  <pre><code>    "StatusCode": 200,
      "body": 89.01565538975994
     }
  </code></pre>
  
  <p><strong>main.py file:</strong></p>
  
  <pre><code>import pickle
  import boto3
  from botocore.vendored import requests
  from sklearn.linear_model import LinearRegression
  import numpy as np
  import json
  
  def get_model():
      s3_client = boto3.client("s3")
      # s3client = boto3.client("s3")
      # s3 = boto3.resource("s3")
      s3 = boto3.resource("s3")
      bucket_name ='deploy-simpleml'
      bucket = s3.Bucket(bucket_name)
      s3_client.download_file('deploy-simpleml','finalized_model.sav','/tmp/finalized_model.sav')
      model = pickle.load(open("/tmp/finalized_model.sav",'rb'))
      return model
      # # bucket_name = 'deploy-simpleml'
      # # bucket = s3.Bucket(bucket_name) 
      # bucket= boto3.resource('s3').Bucket(bucket_name)
      # s3_client.download_file('model/finalized_model.sav','/tmp/finalized_model.sav')
      # model = pickle.load(open("finalized_model.sav",'rb'))
      # return model
   #    # bucket.download_file('model/finalized_model.sav','/tmp/finalized_model.sav')
   #    # model= pickle.load(open("finalized_model.sav",'rb'))
   #    # return model
  
  def predict(event):
      sample =event['body']
      sample=np.array(sample)
      sample = sample.reshape(-1,1)
      # x = x.values.reshape(-1,1)
      model = get_model()
      result = model.predict(sample)
      return result
  
  def lambda_handler(event,context):
      result = predict(event)
      response = {'StatusCode':200,
      'body': result[0]}
      return response
  </code></pre>
  
  <p>I am triggering the code through "serverless.yml " file:</p>
  
  <p><strong>Serverless.yml File</strong></p>
  
  <pre><code>service : test
  
  plugins:
   - serverless-python-requirements
  
  provider:
   name: aws
   runtime: python3.6
   region : ap-southeast-2
   deploymentBucket:
    name : deploy-simpleml
  
  IamRole:
    Type: AWS::IAM::Role
    Properties:
      RoleName: "test-deploy-dev-ap-southeast-2-lambdaRole"
      AssumeRolePolicyDocument:
        Version: "2012-10-17"
        Statement:
          - Effect: Allow
            Principal: "*"
            Service: lambda.amazonaws.com
            Action:
  
              - s3.*
              - s3.GetObject
              - lambda:InvokeFunction
              - lambda:InvokeAsync
              - execute-api:Invoke
              - execute-api:InvalidateCache
  
  
      Resource:
        - "arn:-----------------------------------given my method request ARN number-------"
      # Condition:
  
      #   StringEquals:
  
      #     aws:sourceVpce": "9896d9ff"
  
  custom:
   pythonRequirements:
    slim : true
    pythonBin: /usr/bin/python3
  
  environment:
      SLS_DEBUG: serverless-deploy
  
  functions:
    # postApiTest:
  
    #   handler: main.lambda_handler
    #   name: post-api-test
    #   events:
    #     - http:
    #         path: dev
    #         method: post
    #         private: true
    aimodel-lambda:
  
      name: aimodel-lambda-function
      description : deploy trained linear reg model on aws lambda using serverless
      handler : main.lambda_handler
      events :
  
        - http:
  
  
            path: GET/testapi
  
            method: GET
            private: true 
  
  </code></pre>
  
  <p>Then I have created API Gateway, by adding resource, and method as GET and in Integration request, I have selected in the mapping template as "application/json" and in the editor I have given the following command by selecting "empty".</p>
  
  <pre><code>{
    "body" : "$input.params("500")"
  }
  
  </code></pre>
  
  <p>and in the method execution , in URL Query String Parameters, I have given body.</p>
  
  <p><a href="https://i.stack.imgur.com/7qhzG.png" rel="nofollow noreferrer">for reference i have added string parameter screenshot</a></p>
  
  <p>and when i check the end point url i am facing below error :</p>
  
  <pre><code>{"errorMessage": "'body'", "errorType": "KeyError", "stackTrace": [["/var/task/main.py", 38, "lambda_handler", "result = predict(event)"], ["/var/task/main.py", 29, "predict", "sample =event['body']"]]}
  </code></pre>
  
  <p>and when I click on Test and give the parameters in the query strings, <a href="https://i.stack.imgur.com/Xn1ph.png" rel="nofollow noreferrer">method execution query string</a></p>
  
  <p>I am getting the following error.Please help me with this.</p>
  
  <p>body response:</p>
  
  <pre><code>{
    "errorMessage": "float() argument must be a string or a number, not 'dict'",
    "errorType": "TypeError",
    "stackTrace": [
      [
        "/var/task/main.py",
        38,
        "lambda_handler",
        "result = predict(event)"
      ],
      [
        "/var/task/main.py",
        34,
        "predict",
        "result = model.predict(sample)"
      ],
      [
        "/var/task/sklearn/linear_model/_base.py",
        225,
        "predict",
        "return self._decision_function(X)"
      ],
      [
        "/var/task/sklearn/linear_model/_base.py",
        207,
        "_decision_function",
        "X = check_array(X, accept_sparse=['csr', 'csc', 'coo'])"
      ],
      [
        "/var/task/sklearn/utils/validation.py",
        531,
        "check_array",
        "array = np.asarray(array, order=order, dtype=dtype)"
      ],
      [
        "/var/task/numpy/core/_asarray.py",
        85,
        "asarray",
        "return array(a, dtype, copy=False, order=order)"
      ]
    ]
  }
  
  </code></pre>