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
- Sign in to the AWS Management Console at https://aws.amazon.com/console/ using your AWS Account
- In the Find Services search box, type Lambda, and press Enter
- On the new page, click on the
button
- On the Create function screen, select Author from scratch
- On the same screen, fill in the following information:
Function name →computelab03-lbd
Runtime →Node.js 10.x
- Click on the
button
- 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
- On the function page, on the Configuration tab, click on the
button
- On the Add trigger page, click on the Trigger configuration dropdown and select API Gateway
- In the form, select the following information:
API →Create a new API
Security →Open
- Click on the
button to create the trigger
- Once the trigger is created, on the function page, copy the API endpoint URL from the API Gateway section
- Open a new browser window and paste the URL in the address bar
- 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
- On the function page, on the Configuration tab, click on the
button
- In the code editor, in the Function code section, find the following line:
body: JSON.stringify('Hello from Lambda!'),
- Change the line to the following:
body: JSON.stringify(`Hello, ${event["queryStringParameters"]["name"]}! I am a serverless app!`),
- Click on the
button on top of the page to save your changes
- Click on the
button to show the trigger information
- Copy the API endpoint URL from the API Gateway section
- Open a new browser window and paste the URL in the address bar
- 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. - 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
- On the function page, click on the
button on top of the page
- Select the
option from the dropdown
- Confirm the deletion by clicking on the
button
- 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
You must be logged in to post a comment.