Lambda

Soumya Pallebothula
4 min readJan 18, 2021

--

AWS Lambda is one of the services that falls under the ‘Compute’ domain of services that AWS provides. We can run any type applications like Java, Node ,Ruby etc.

Features of Amazon Lambda

No worries about the sever

You don’t require any server to run or to manage and all you need to do is write the code and upload it to lambda.

Automatically Scaling

Scaling is done automatically based on the size of the workload. It automatically scales the application by running code in response to each trigger our code runs in parallel and processes each triggers individually scaling precisely with the size of the workload. Lambda can scale the application running the code in the response to each trigger that it receives.

Metering on the second

You can pay only for the amount of time that your code is running. Which means you’re not charged for any of the servers .The only payment required is for the amount of time the code computed.(per 100 milliseconds)

Lambda is basically depends upon four concepts they are:

  1. Functions : This process an event and returns a response
  2. Runtimes : It executes the function containing the code.
  3. Log streams : These will automatically monitor your function Invocations and reports the metrics to cloud watch
  4. Layers

Configuring Lambda

  1. Sign in to AWS account.
  2. Select Lambda from AWS services section.

3. Click the Skip button.

4. Provide the necessary details to create a Lambda function as shown in the following screenshot and paste the Node.js code that will be triggered automatically whenever a new item is added in DynamoDB. Select all the required permissions.

5. Click the Next button and verify your details.

6. Click the Create Function button.

Now, when we select the Lambda service and select the Event Sources tab, there will be no records. Add at least one source to the Lambda function to work. Here, we are adding DynamoDB Table to it.

We have created a table using DynamoDB (we will discuss this in detail in DynamoDB chapter).

7. Select the stream tab and associate it with the Lambda function.

You will see this entry in Event Sources Tab of Lambda Service page.

8. Add some entries into the table. When the entry gets added and saved, then Lambda service should trigger the function. It can be verified using the Lambda logs.

9. To view logs, select the Lambda service and click the Monitoring tab. Then click the View Logs in Cloud Watch.

Connecting Lambda With the Gateway

We can connect the AWS lambda to a API Gateway in two ways i.e through the Lambda console or API gateway console.

  1. On the AWS console click Lambda and click on create function.
  2. Name the function and select the runtime editor of your choice, Now on the permissions tab click on use an existing role.
  3. Select the role that you have created and click on create function.
  4. fter the function is created click on Add Trigger, Now on trigger configuration page on the search bar type API gateway and click on the Rest API option.
  5. On the security mechanism select the Open and click on the additional settings bar and make sure all the defaults are present and click on the add button at the end.
  6. After clicking add you will see a message containing the API trigger was successful.
  7. Now to verify it expand the API name containing the details on the Lambda dashboard.
  8. Now click on the URL which is present in the details of the API and copy it and paste it in the browser.
  9. You will see an internal server error if you don’t have any code and you can modify the code and save it.
  10. you can run the code and can see the result of the code in the URL home page.

Thank you..!!

--

--

No responses yet