AWS serverless for beginners

In this blog we'll create a simple serverless app using AWS lambda and API Gateway.

"Serverless" what is it? ๐Ÿค”

No servers obviously right? nope you got that wrong

Here's what it is: In serverless computing, infrastructure management tasks like capacity provisioning and patching are handled by third party (in our case AWS), so you can focus on only writing code that serves your customers.

How to Serverless?

AWS Lambda

AWS Lambda is a compute service that lets you run code without provisioning or managing servers - As per AWS

AWS API Gateway

Amazon API Gateway is a fully managed service that makes it easy for developers to create, publish, maintain, monitor, and secure APIs at any scale - As per AWS

In easy words Lambda is where you write your code and API Gateway is where you define routes to execute those Lambda functions, let's say you wrote a lambda function for login functionality and whenever someone hits xyz.com/login you want to execute the login Lambda you can do so by Connecting Lambda to API Gateway and configuring the route /login.

You know what it is, now let's see how it works ๐Ÿ˜ƒ

  1. Login to your AWS account
  2. Open lambda console Screenshot 2021-08-14 22-42-16.png
  3. Then click on "Create function" Screenshot 2021-08-14 22-43-40.png
  4. Select "Author from scratch", type the function name, select an execution role ( learn how to create execution role ) Screenshot 2021-08-14 22-44-26.png
  5. You'll see a screen like this Screenshot 2021-08-14 22-45-01.png here you can see the code editor, type your code and press deploy to deploy it you can run the function by clicking on "Test" button

Congratulations ๐ŸŽ‰ you have successfully created your first lambda function

Now, Let's connect to API Gateway

  1. Go to API Gateway console by searching "API Gateway" in services section
  2. Click on "Create API"
  3. Select Rest API Screenshot 2021-08-14 22-45-49.png
  4. Type in the name and press "Create API" Screenshot 2021-08-14 22-46-11.png
  5. Now let's add a path, Click on "Actions" and then "Create Resource" Screenshot 2021-08-14 22-47-33.png
  6. Type the path name and hit "Create Resource" Screenshot 2021-08-14 22-47-58.png
  7. You can now see a path is created as "/test"
  8. Click on "Actions" and "Create Method" Screenshot 2021-08-14 22-48-30.png
  9. Choose "Get"
  10. Type in the lambda function name you created earlier and click on "Save" Screenshot 2021-08-14 22-48-42.png
  11. And finally Click on "Actions" and then "Deploy API" ( learn how to create stages )

Wohoo!! you have have finally created a serverless app ๐Ÿฅณ๏ธ You'll see the link to your serverless app by clicking on "Stages" and the stage you have created Screenshot 2021-08-14 23-18-38_LI.jpg You can test the API by hitting the /test and you'll see the logs in lambda console

Thank you for reading ๐Ÿค— learn more about AWS serverless framework

Written by Syed Zubair Ahmed Twitter Instagram Website LinkedIn

ย