Seth Geoghegan
10/21/2021, 12:08 PMnpm run start
works well and the live lambda environment spins up just fine. However, when I hit an endpoint, I get a JSON parsing errorSeth Geoghegan
10/21/2021, 12:08 PM54b9eb2d-7fbe-45db-81fb-89f896e57099 REQUEST sgeoghegan-kas-sst-kas-st-ApiLambdaGETrecordsource-LZHr312naXqt [functions/record_source/retrieve.handler] invoked by API GET /record-source
Traceback (most recent call last):
File "/code/node_modules/@serverless-stack/core/src/runtime/shells/bootstrap.py", line 59, in <module>
event = json.loads(r.read())
File "/usr/lib/python3.5/json/__init__.py", line 312, in loads
s.__class__.__name__))
TypeError: the JSON object must be str, not 'bytes'
Seth Geoghegan
10/21/2021, 12:09 PMSeth Geoghegan
10/21/2021, 12:09 PMSeth Geoghegan
10/21/2021, 12:15 PMbuf = response.read()
result = json.loads(buf.decode('utf-8'))
manitej
10/21/2021, 12:16 PMSeth Geoghegan
10/21/2021, 12:18 PM"dependencies": {
"@aws-cdk/core": "1.126.0",
"@serverless-stack/cli": "0.47.2",
"@serverless-stack/resources": "0.47.2"
},
manitej
10/21/2021, 12:20 PMSeth Geoghegan
10/21/2021, 12:27 PMFile "/usr/lib/python3.5/json/__init__.py", line 312, in loads
s.__class__.__name__))
Although my SST app is specifying a runtime environment of Python 3.7
// Set default runtime for all functions
app.setDefaultFunctionProps({
runtime: "python3.7",
srcPath: "functions",
environment:{
...dbCredentials
}
});
Seth Geoghegan
10/21/2021, 12:33 PMSeth Geoghegan
10/21/2021, 12:43 PMevent = json.loads(r.read())
to
event = json.loads(r.read().decode('utf-8'))
which seemed to do the trick.Seth Geoghegan
10/21/2021, 12:44 PMFrank
Seth Geoghegan
10/21/2021, 5:58 PMSeth Geoghegan
10/21/2021, 5:59 PMfrom lib.dbi import DBConfig
from lib.dbi.record_source import RecordSourceDBI
from lib.helper import json_serialize
from lib.helper.connection import ConnectionHelper
def handler(event, _context):
try:
response = handler_safe(event, _context)
status_code = 200
except Exception as e:
response = dict(error=str(e))
status_code = 500
finally:
ConnectionHelper.close()
return dict(body=json_serialize(response), statusCode=status_code)
def handler_safe(event, _context):
db_connection = ConnectionHelper.open(**DBConfig.get_attribution_db())
dbi = RecordSourceDBI(db_connection)
request_params = event.get('queryStringParameters')
db = request_params.get('record_db')
table = request_params.get('record_table')
table_id = str(request_params.get('record_table_id'))
record_source = dbi.get_record_source(db, table, table_id)
return dict(record_source=record_source)
Frank
def handler(event, context):
response = {
"statusCode": 200,
"body": "Hello World"
}
return response
Seth Geoghegan
10/22/2021, 1:30 PMSeth Geoghegan
10/22/2021, 1:33 PM