Nowadays you may find a large number of available tutorials about creating a serverless API. In this post, we’d like to outline another case of using API Gateway, which in particular can be used as a backend for a WebView application.
Worth to note:
This is just a concept, so you should not consider it as a working use case. In the end, you’ll find the link to Github, if you do not want to go through all the stages manually. That’s why it may seem that some points will be missed here. Anyway, let’s dive in!
To begin with, we have the simplest data model:
S3 will be used as a data source. We create JSON-files with the contents of the type:
We can use Python as a template rendering engine. Templates are HTML files of the form:
After creating the data, we upload everything onto the bucket with the appropriate prefixes (directories):
Creating a feature in AWS Lambda
We can create a Lambda feature in the AWS console, \using blueprint hello-world-python.
The policy for access to S3 should be added to the used IAM role.
Now we go to the API Gateway console and create an API of the following form:
Pay attention to the mapping template – it describes the event that is given to the lambda. Next, we describe the mapping and content-type for data sent from the API Gateway.
That we deploy two stages – production and development, register the stage variable LamdbdaAlias in each and forget about API Gateway for some time.
Work with AWS Lambda
Next, we return to the created lambda and add the following code:
After that, we publish Lambda and create two aliases for it – production and development:
That’s all – we’ve got a rather working project. And the link to Github is right here: aws webview