mirror of
https://github.com/serverless/serverless.git
synced 2026-01-18 14:58:43 +00:00
feat(AWS Local Invocation): Support decimal serialization for Python
This commit is contained in:
parent
254e70cd0a
commit
9ef46ba05f
@ -3,9 +3,17 @@ import argparse
|
||||
import json
|
||||
import logging
|
||||
import sys
|
||||
import decimal
|
||||
from time import strftime, time
|
||||
from importlib import import_module
|
||||
|
||||
def decimal_serializer(o):
|
||||
if isinstance(o, decimal.Decimal):
|
||||
f = float(o)
|
||||
if f.is_integer():
|
||||
return int(f)
|
||||
return f
|
||||
|
||||
class FakeLambdaContext(object):
|
||||
def __init__(self, name='Fake', version='LATEST', timeout=6, **kwargs):
|
||||
self.name = name
|
||||
@ -84,4 +92,4 @@ if __name__ == '__main__':
|
||||
|
||||
context = FakeLambdaContext(**input.get('context', {}))
|
||||
result = handler(input['event'], context)
|
||||
sys.stdout.write(json.dumps(result, indent=4))
|
||||
sys.stdout.write(json.dumps(result, default=decimal_serializer, indent=4))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user