Search code examples
amazon-web-serviceslambdarestchalice

Why is my Lambda API via Chalice giving an internal server error instead of a datetime value?


The API result at /date is giving an {"message": "Internal server error"} error. /hello is successfully returning 'hello world'.

The ultimate goal is to return the number of days passed so far this year.

'''

from chalice import Chalice
from datetime import date

app = Chalice(app_name='days')
app.debug = True

@app.route('/hello')
def index():
    return {'hello': 'world'}

@app.route('/date')
def days():
    return date.today()

'''


Solution

  • Based on the comments.

    The issue was that date.today() was not returning json.

    The solution was to convert it to string so that is correctly recognized as a json string: something like str(date.today())