I have written the below code and have deployed in AWS Lambda using deployment package :
from flask import Flask,jsonify,request
app = Flask(__name__)
books = [
{'id': 0,
'title': 'A Fire Upon the Deep',
'author': 'Vernor Vinge',
'first_sentence': 'The coldsleep itself was dreamless.',
'year_published': '1992'},
{'id': 1,
'title': 'The Ones Who Walk Away From Omelas',
'author': 'Ursula K. Le Guin',
'first_sentence': 'With a clamor of bells that set the swallows soaring, the Festival of Summer came to the city Omelas, bright-towered by the sea.',
'published': '1973'},
{'id': 2,
'title': 'Dhalgren',
'author': 'Samuel R. Delany',
'first_sentence': 'to wound the autumnal city.',
'published': '1975'}
]
@app.route("/listbooks",methods=['GET'])
def hello():
return jsonify(books)
@app.route("/getbookbyid",methods=['GET'])
def getBybookid(event,context):
if 'id' in request.args:
id=int(request.args['id'])
results=[]
for book in books:
if book['id']==id:
results.append(book)
return jsonify(results)
I have configured API Gateway to hit the lambda function for a GET request. When i am trying to hit the endpoint using postman I am getting :
Working outside of request context error
Any pointers