Integrating AWS Lambda, API Gateway, System Manager, EC2 Instance

Deepak SinghDeepak Singh
3 min read

Hello all, Here I have created an architecture such that when a user clicks a link(given by API Gateway), users get a Custom HTML link which has some information/functionality like your public IP address and also can change the cover name. One thing to note is that the page will automatically get deleted in 5 minutes.

Services used to get up to this architecture:

  1. AWS Lambda

  2. API Gateway

  3. System Managers

  4. AWS EC2

Features on the Custom HTML page:

  1. Edit cover name

  2. Delete the page after 5 minutes

Configuring the services:

  1. AWS EC2

    > This instance will serve the custom html page which gets created. For this, we have to install a webserver like httpd. And to make a server installed we have 2 options either install it manually by logging into the server or by providing the user data while creating the instance on the UI.

    > To launch an instance read here. As soon as you have created the instance login into the instance using the command ssh -i <KeyPair.pem> ec2-user@<public-ip>

    Run the following commands:

     #!/bin/bash
     # Use this for your user data (script from top to bottom)
     # install httpd (Linux 2 version)
     yum update -y
     yum install -y httpd
     systemctl start httpd
     systemctl enable httpd
    

    > The command will install the httpd web server onto the system.

    > Now we will save the Default HTML page which is used as the default page for each user.

    > create a file using the command sudo nano /var/www/html/default.html

    > copy this code and paste using the command ctrl+shift+v

    > save using the command ctrl+s and exit using ctrl+x

    > now our ec2 instance is configured with Default HTML

  2. AWS Lambda

    We will be needing 3 Lambda Functions. The function language used is Python.

    Function 1 (custom-html-page):

    > this function helps to get the basic information of the user who clicks the link generated by API Gateway and then generates the unique page which is publically accessible with the user's public IP.

    > Function-name: custom-html-page

    > Runtime: Python-3.9

    > Architecture: x86_64

    > Permissions: Create a new role with basic Lambda permissions

    > code: here

    deploy the code...

    Function 2 (change-cover-name):

    > this function helps to change the cover name of HTML generated.

    > Function-name: change-cover-name

    > Runtime: Python-3.9

    > Architecture: x86_64

    > Permissions: Use an existing role

    > code: here

    deploy the code...

    Function 3 (delete-custom-page):

    > this function helps to delete the page automatically when the timer ends.

    > Function-name: delete-custom-page

    > Runtime: Python-3.9

    > Architecture: x86_64

    > Permissions: Use an existing role

    > code: here

    deploy the code...

    change the instance-id in all the lambda function with the instance you launched earlier.

    Also, attach the ssm policy and ec2 policy to the role created for lambda functions.

  3. API Gateway

    Create a REST API which will handle the incoming request and transfer it to the lambda functions.

    create new api

    create resources

    create method

    Similarly, create 3 resources and attach each with the three function created.

Architecture

Screenshots

0
Subscribe to my newsletter

Read articles from Deepak Singh directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Deepak Singh
Deepak Singh