I'm currently developing a REST API using the serverless framework with python and dynamoDB. I would like to know how I can pass and retrieve parameters in my lambda function. My configuration on serverless.xml
looks like:
getNearestConvenios:
handler: src/controllers/convenio_controller.get_nearest_convenios
events:
- http:
path: convenios/nearest
method: get
cors: True
request:
template:
application/json: '{ "lat" : "$input.params(''lat'')", "long" : "$input.params(''long'')"}'
and I'm trying to retrieve the parameters like this:
def get_nearest_convenios(event, context):
try:
parameters = event['pathParameters']
convenios = service.get_nearest_convenios(parameters['lat'], parameters['long'])
return http.ok(convenios)
except Exception as ex:
logger.warn("WARNING: Request id: {0}, Error: {1}, Info: {2}".format(context.aws_request_id, type(ex), ex.args))
return http.bad_request(str(ex))
I followed the Custom Request Templates provided on the official documentation, but I had no success until now. Also, in CloudWatch the following error is being showed:
[WARNING] 2020-08-14T09:04:11.783Z 3c9222b2-4601-4460-ba7c-3cd89ba3b04b WARNING: Request id: 3c9222b2-4601-4460-ba7c-3cd89ba3b04b, Error: <class 'TypeError'>, Info: ("'NoneType' object is not subscriptable",)