O'Reilly logo

Hands-On Serverless Deep Learning with TensorFlow and AWS Lambda by Rustem Feyzkhanov

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating the API Gateway using the serverless framework

Before creating the API, let us look at our project files: the main Python file (index.py) and the serverless configuration file (serverless.yml). Let's look at the Python file as shown in the following code:

import jsondef handler(event, context):print('Log event', event)return{'status code': 200;'body': json.dump('Hello world API!')}

From the preceding code block, you can see that this file will be returning a JSON response instead of the string to the API request. For this, we need to change status code to 200 and change body to transform in the JSON format.

In the server configuration file, we will be adding a events and adding an API endpoint name:

functions:  main: handler: index.handler ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required