Loading....
Lab
Cloud Vendor Amazon AWS
Proficiency Level Cloud Enthusiast
Tags LambdaServerless

Summary

In this lab, you will create a serverless app using AWS Lambda. The serverless app will use an HTTP trigger and will be publicly accessible via its URL. When invoked, the app will reply with the phrase: “Hello, [your_name]! I am a serverless app!”, where [your_name] will be replaced with the name you pass as a query string parameter to the app.

Each exercise below builds upon the previous one. You should start each new exercise from the last step of the previous exercise unless it is explicitly written otherwise.

Learning Objectives

After completion of this lab, you will be able to:

  • Create AWS Lambda serverless apps
  • Use HTTP to trigger the execution of your serverless app
  • Modify the code of the serverless app to reply with the intended message

Prerequisites

To complete this lab, you will need the following:

  • Reliable internet connection
  • AWS account used to access Amazon AWS Management Console

Exercise #1: Create an AWS Lambda Function

In this exercise, you will create an AWS Lambda Function for your serverless app.

Steps

  1. Sign in to the AWS Management Console at https://aws.amazon.com/console/ using your AWS Account
  2. In the Find Services search box, type Lambda, and press Enter
  3. On the new page, click on the button
  4. On the Create function screen, select Author from scratch
  5. On the same screen, fill in the following information:
    Function namecomputelab03-lbd
    RuntimeNode.js 10.x
  6. Click on the button
  7.  Milestone step:  At this point, you have learned how to create an AWS Lambda Function that you can use for your serverless app.

Exercise #2: Add an HTTP Trigger to the Lambda Function

In this exercise, you will add an HTTP trigger to use with your AWS Lambda Function. You will test the trigger by loading the endpoint URL into your browser.

Steps

  1. On the function page, on the Configuration tab, click on the button
  2. On the Add trigger page, click on the Trigger configuration dropdown and select API Gateway
  3. In the form, select the following information:
    APICreate a new API
    SecurityOpen
  4. Click on the button to create the trigger
  5. Once the trigger is created, on the function page, copy the API endpoint URL from the API Gateway section
  6. Open a new browser window and paste the URL in the address bar
  7.  Milestone step:  At this point, you have learned how to create an HTTP trigger for your AWS Lambda Function and test it with your browser

Exercise #3: Modify the AWS Lambda Function Code

In this exercise, you will modify the AWS Lambda Function Code to reply with “Hello, [your_name]! I am a serverless app!”, where [your_name] will be replaced with the name you pass as a query string parameter to the app. You will test the modification in your browser.

Steps

  1. On the function page, on the Configuration tab, click on the button
  2. In the code editor, in the Function code section, find the following line:
    body: JSON.stringify('Hello from Lambda!'),
  3. Change the line to the following:
    body: JSON.stringify(`Hello, ${event["queryStringParameters"]["name"]}! I am a serverless app!`),
  4. Click on the button on top of the page to save your changes
  5. Click on the button to show the trigger information
  6. Copy the API endpoint URL from the API Gateway section
  7. Open a new browser window and paste the URL in the address bar
  8. Add the following at the end of the URL
    ?name=[your_name]

    where [your_name] is your name. The desired text will appear in the browser window.

  9.  Milestone step:  At this point, you have learned how to modify the code for Azure Function with HTTP trigger and test your changes.

Exercise #4: Delete the AWS Lambda Function

In this exercise, you will delete the AWS Lambda Function to prevent unwanted use and save on cost.

Steps

  1. On the function page, click on the button on top of the page
  2. Select the option from the dropdown
  3. Confirm the deletion by clicking on the button
  4.  Milestone step:  At this point, you have learned how to delete the AWS Lambda Function to prevent unwanted use and save on cost.

 

Last Update: October 1, 2019  

October 1, 2019   702   Toddy Mladenov    Compute    
Total 0 Votes:
0

Tell us how can we improve this post?

+ = Verify Human or Spambot ?

Back To Top