AWS has saved a lot of money for their customers who were looking for a simple proxy to expose serverless application by releasing HTTP API Gateway. If you are NOT looking for features like request/response transformation, Lambda authorizer, request parameters/body validation, request forwarding to other AWS services and such other advanced features then HTTP API is the best choice instead of REST API. A detailed comparison between HTTP and REST API can be found here.

Before diving into the implementation part you will need Lambda code to successfully test our deployment.


Let’s start with the implementation part by creating our lambda functions.

First Function:

  • Start with giving your function a name
  • Under runtime, select Python 3.8
  • For permissions, select Create a new role with basic Lambda permissions

Image for post

Lambda Function 1

Once you click on Create Function button an IAM role with basic required permissions will be created along with your function.

Replace the default code with the following:

mport json

	def lambda_handler(event, context):
	    return {
	        'statusCode': 200,
	        'body': json.dumps('Hello from api 1')
	    }

Make sure to click the Save button available on the top right side before navigating away from the page.

Image for post

Lambda Code (Function 1)

Function Two

  • Give your function a name
  • Select **Python 3.8 **for runtime
  • For permissions, select Create a new role with basic Lambda permissions

Image for post

Lambda Function 2

Replace the default code with the following for the second function:

Don’t forget to save your code.

Image for post

Lambda Code (Function 2)

It’s now time to create our API Gateway so let’s do it.

#aws-api-gateway #cloudfront #http-api #lambda #aws

Exposing HTTP API Gateway Via AWS CloudFront | Detailed Guide
5.80 GEEK