Uncategorized

How to Make a Serverless Website with AWS Lambda (for free)

In this tutorial, you will learn how to create a serverless static website using AWS Lambda functions. You can get 1 million free Lambda calls per month that are part of the AWS Always Free plan. This essentially equates to 1 million free page views per month.

The following are several examples of Lambda Python function calls that return HTML that can be accessed over a public URL using HTTPS.

Reading: How to create a serverless website using lamda

Note this If you find AWS Lambda hosting too complicated or too limiting, there are many other ways to host a free website.

1. Getting started with AWS Lambda

2. Create a very simple Lambda function

Click the orange Create Function button in the upper-right corner of the AWS Lambda dashboard.

Choose one Function names and runtime. I selected Home or Python 3.9.

The next screen shows a basic Lambda function that simply returns the text “Hello from Lambda!”. with status code 200.

import json def lambda_handler(event, context): # TODO implement return { ‘statusCode’: 200, ‘body’: json.dumps(‘Hello from Lambda!’) }

See also: How to Create a New Gmail Account

Leave add us a trigger so we can run the function in a web browser.

Click Add Trigger. For the trigger configuration drop-down list, select API Gateway. Create an API of type HTTP API with open security. Leave all other fields at their default values.

See also  Top Ways to Create Free Website and Earn Money

On the next page, copy and paste the API endpoint URL into a web browser and you will see “Hello from Lambda!”. string displayed.

2. Lambda function with HTML

Edit the Lambda function with the following code to return HTML instead of JSON.

def lambda_handler(event, context): body = ”’ Homepage

Home

Hello! my name is tony I love teaching people about websites.

Like, comment, subscribe!

Check out my blog.

”’ response = { ‘statusCode’: 200, ‘headers’: {“Content-Type”: “text/html”,}, ‘body’: body } return response

See also: How Much Does it Cost to Develop an Android App?

You can return the HTML code Happy to modify for your purposes.

Browse to the same URL in a web browser and you will see the HTML displayed as expected.

3.Multiple-page Lambda function website

Create another Lambda function called blog Replace the default Lambda function with the following:

def lambda_handler(event, context): body = ”’ Blog

Blog

This is my blog. I haven’t written any posts yet.

”’ respon se = { ‘statusCode’: 200, ‘headers’: {“Content-Type”: “text/html”,}, ‘body’: body } return re sponse

Provide the function and test if the link to the blog page works.

You can create a Lambda function for as many pages as you want. Below is a detailed video walkthrough of the steps in this tutorial.

Next, check out some of the many other ways to host a free website.

See also: Free Website Generator Tutorial

.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button