Skip to main content

AWS Lambda – Configuring Lambda Function

Memory Allocation

Login to AWS console and create or select the existing lambda function. Click the Configuration tab to get the details of the memory allocated. Look at the screenshot shown below −

Memory Allocation

Note that by default the memory allocated is 128MB. If you want to increase the memory you can click the slider.

The memory will get incremented to 64MB as you move the slider. Observe that the maximum memory available is 3008MB. Look at the screenshot shown below −

Maximum Memory

You can also use aws cli from command prompt to increase the memory limit. You will have to give the memory in increments of 64MB.

Now, let us increase the memory limit of AWS Lambda with name :myfirstlambdafunction.

The memory details of the function are shown in the screenshot given below −

Memory Details

The command used to change the memory using aws cli is as follows −

aws lambda update-function-configuration --function-name your function name --
region region where your function resides --memory-size memory amount --
profile admin user

The corresponding output of AWS Lambda function myfirstlambdafunction in AWS console is shown here. Observe that the memory is changed from 128MB to 256MB.

Memory Command
Maximum Execution Time

Timeout is the time allotted to AWS Lambda function to terminate if the timeout happens. AWS Lambda function will either run within the allocated time or terminate if it exceeds the timeout given. You need to evaluate the time required for the function to execute and accordingly select the time in Configuration tab in AWS console as shown below −

Maximum Execution Time
IAM Role

When creating AWS Lambda function, the role or the permission needs to be assigned. Incase you need AWS Lambda for S3 or dynamoDB, permission with regard to the services of lambda needs to be assigned. Based on the role assigned, AWS Lambda will decide the steps to be taken. For Example if you give full access of dynamodb, you can add, update and delete the rows from the dynamodb table.

Handler Name

This is the start of execution of the AWS Lambda function. Handler function has the details of the event triggered, context object and the callback which has to send back on success or error of AWS Lambda.

The format of the handler function in nodejs is shown here −

exports.handler = (event, context, callback) => {
callback
(null, "hello from lambda");
};


Lambda Function using Environment Variables

In this section, we will create a simple Lambda function using environment variables added in the configuration section. For this purpose, follow the steps given below and refer the respective screenshots −

Step 1

Go to AWS console and create a function in Lambda as shown.

Lambda Variables
Step 2

Now, add the environment variables as shown −

Lambda Environment
Step 3

Now, let us fetch the same in Lambda code as follows −

exports.handler = (event, context, callback) => {
var hostName = process.env.host;
var userName = process.env.username;
callback
(null, "Environment Variables =>"+hostName+" and "+userName);
};


Step 4

To get the details from environment variables we need to use process.env as shown. Note that this syntax is for NodeJS runtime.

var hostName = process.env.host;   
var userName = process.env.username;


Step 5

The output for the Lambda function on execution will be as shown −

Lambda Function Execution

 

Comments

Popular posts from this blog

PERL Some good framework

1. Catalyst is the most popular agile Perl MVC web framework that encourages rapid development and clean design without getting in your way. Catalyst | Perl MVC web application framework 2. Mojolicious is a next generation web framework for the Perl programming language. Back in the early days of the web, many people learned Perl because of a wonderful Perl   ... Mojolicious - Perl real-time web framework 3. Documents for Perl  The Perl Archive Network, the gateway to all things Perl. The canonical location for Perl code and modules. The Comprehensive Perl Archive Network - www. cpan .org

C++ How to use Date and Time

The C++ standard library does not provide a proper date type. C++ inherits the structs and functions for date and time manipulation from C. To access date and time related functions and structures, you would need to include <ctime> header file in your C++ program. There are four time-related types: clock_t, time_t, size_t , and tm . The types clock_t, size_t and time_t are capable of representing the system time and date as some sort of integer. The structure type tm holds the date and time in the form of a C structure having the following elements: struct tm { int tm_sec ; // seconds of minutes from 0 to 61 int tm_min ; // minutes of hour from 0 to 59 int tm_hour ; // hours of day from 0 to 24 int tm_mday ; // day of month from 1 to 31 int tm_mon ; // month of year from 0 to 11 int tm_year ; // year since 1900 int tm_wday ; // days since sunday int tm_yday ; // days since January 1st int tm_isdst ; // hours of daylight savin...

Lambda Function with Amazon DynamoDB

DynamoDB can trigger AWS Lambda when the data in added to the tables, updated or deleted. In this chapter, we will work on a simple example that will add items to the DynamoDB table and AWS Lambda which will read the data and send mail with the data added. Requisites To use Amazon DB and AWS Lambda, we need to follow the steps as shown below − Create a table in DynamoDB with primary key Create a role which will have permission to work with DynamoDBand AWS Lambda. Create function in AWS Lambda AWS Lambda Trigger to send mail Add data in DynamoDB Let us discuss each of this step in detail. Example We are going to work out on following example which shows the basic interaction between DynamoDB and AWS Lambda. This example will help you to understand the following operations − Creating a table called customer in Dynamodb table and how to enter data in that table. Triggering AWS Lambda function once the data is entered and sending mail using Amazon SES service. The basic block diagram that ...