How to Create a WebView Application Based on AWS ApiGateway and AWS Lambda?

How to Create a WebView Application Based on AWS ApiGateway and AWS Lambda?

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!

Data preparation

To begin with, we have the simplest data model:

data model

S3 will be used as a data source. We create JSON-files with the contents of the type:

data source

We can use Python as a template rendering engine. Templates are HTML files of the form:

a template form

After creating the data, we upload everything onto the bucket with the appropriate prefixes (directories):

uploading onto the bucket

Creating a feature in AWS Lambda

We can create a Lambda feature in the AWS console,  \using blueprint hello-world-python.

Creating a Lambda feature

The policy for access to S3 should be added to the used IAM role.

API creation

Now we go to the API Gateway console and create an API of the following form:

API form

API form 2

API form 3

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.

production and development

Work with AWS Lambda

Next, we return to the created lambda and add the following code:

following the code

After that, we publish Lambda and create two aliases for it – production and development:

two aliases

That’s all – we’ve got a rather working project. And the link to Github is right here: aws webview

2019-04-08T14:56:34+00:00