title: AWS API Gateway failed with: Lambda execution failed with status 200 due to customer function error: Object of type Decimal is not JSON serializable
body: <p>I try to get my data from dynamodb using API-Gateway. It works with other functions that are relatively similar. If I work without "<strong>json.dumps()</strong>" I get Malformed exception, but in the Logs are the data from the table, otherwise, I get this exception (without any data):</p>
  
  <blockquote>
    <p>Lambda execution failed with status 200 due to customer function
    error: Object of type Decimal is not JSON serializable</p>
  </blockquote>
  
  <p>This is my python-code</p>
  
  <pre><code>import json
  import boto3
  from decimal import Decimal
  
  from boto3.dynamodb.conditions import Key, Attr
  
  dynamodb = boto3.resource('dynamodb')
  tablename = dynamodb.Table('db')
  
  def lambda_handler(event, context):
  
     query = event["queryStringParameters"]['email']
     #query = event['query']
  
     response = tablename.scan(
        FilterExpression=Attr('email').eq(query))
     items = response['Items']
  
     return{
        "isBase64Encoded": False,
        "statusCode": 200,
        "body" : json.dumps(items)
     }
  
  </code></pre>
  
  <p>This code for another table works fine:</p>
  
  <pre><code>import json
  import boto3
  from decimal import Decimal
  
  from boto3.dynamodb.conditions import Key, Attr
  
  dynamodb = boto3.resource('dynamodb')
  tablename = dynamodb.Table('FOODGER')
  
  def lambda_handler(event, context):
  
     query = event["queryStringParameters"]['query']
     #query = event['query']
  
     response = tablename.scan(
        FilterExpression=Attr('generic food.name').begins_with(query.title()))
     items = response['Items']
  
     return{
        "isBase64Encoded": False,
        "statusCode": 200,
        "body" : json.dumps(items)
     }
  
  </code></pre>