- AWS Lambda - Additional Example
- Monitoring and TroubleShooting using Cloudwatch
- AWS Lambda@Edge with CloudFront
- Lambda Function with Custom User Applications
- Lambda Function with Amazon Kinesis
- Lambda Function with CloudTrail
- Lambda Function with Amazon SNS
- Lambda Function with Scheduled Events
- Lambda Function with Amazon DynamoDB
- Lambda Function with Amazon S3
- Working with Amazon API Gateway
- Deleting Lambda Function
- AWS Executing & Invoking Lambda Function
- Creating & Deploying using Serverless Framework
- Creating & Deploying using AWS CLI
- Creating & Deploying using AWS Console
- Configuring Lambda Function
- Function in C#
- Function in Go
- Function in Python
- Function in Java
- Function in NODEJS
- Building the Lambda function
- AWS Lambda - Introduction
- AWS Lambda - Environment Setup
- AWS Lambda - Overview
- AWS Lambda - Home
AWS Lambda Useful resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
AWS Lambda – Configuring Lambda Function
In the previous chapters, we have learnt how to create AWS Lambda function in AWS console. However, there are other parameters for creating a Lambda function. These include memory allocation, timeout etc.
In this chapter, let us understand in detail about the following configuration properties for AWS Lambda.
Memory Allocation
Login to AWS console and create or select the existing lambda function. Cpck the Configuration tab to get the details of the memory allocated. Look at the screenshot shown below −
Note that by default the memory allocated is 128MB. If you want to increase the memory you can cpck the spder.
The memory will get incremented to 64MB as you move the spder. Observe that the maximum memory available is 3008MB. Look at the screenshot shown below −
You can also use aws cp from command prompt to increase the memory pmit. You will have to give the memory in increments of 64MB.
Now, let us increase the memory pmit of AWS Lambda with name :myfirstlambdafunction.
The memory details of the function are shown in the screenshot given below −
The command used to change the memory using aws cp 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.
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 −
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.
Step 2
Now, add the environment variables as shown −
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 −
Advertisements