How to set up and configure an AWS Lambda Function

AWS Lambda is an event-driven computing service that allows the user to create applications and then run the code for those applications on the AWS infrastructure by creating what is called a lambda function. AWS Lambda abstracts server management from users thus enabling them to concentrate on the creation of applications without having to worry about server administration, infrastructure provisioning and scaling.

AWS Lambda is a compute resource that will run code in response to a specific event/events determined by the user for example changes to an s3 bucket or an update to a table on DynamoDB. It can also be used to trigger code in response to HTTP requests by using AWS API Gateway.

Why use AWS Lambda?

AWS Lambda takes care of all the server and Operating System patching and maintenance and also manages capacity, scaling and the automatic provisioning of resources. The service is also linked to AWS CloudWatch which will automatically generate logs based on the events that take place.

Lambda Functions are known stateless which means that they are not dependent on any specific underlying infrastructure configuration and as such can easily scale to meet the needs of incoming events.  AWS Lambda could be considered a step towards a serverless environment for application developers.

What is an AWS Lambda Function?

The code created by the user and uploaded to AWS is uploaded as a “lambda function” and is written as a stateless function meaning that within the code there cannot be any dependencies on local host resources. keeping the function stateless allows AWS to create multiple copies of the function as is needed which can all run in parallel to each other allowing scalability at the rate of events that are incoming.

AWS Lambda currently supports functions created in Java, Python and Node.Js.  When creating your Lambda function AWS provides the user with some skeleton code for Python and Node.Js however if a user wishes to use Java they must upload the code in the form of a .zip file or a .jar file.

CloudRanger AWS Backups

How to set up and run an AWS Lambda Function?

Once the user logs in to their AWS account they will be presented with the AWS management console which displays all the different services that AWS currently provide. Once logged in go to the services dashboard and select Lambda>Create Lambda Function or New Lambda Function which will present the user with 29 blueprints which are basically skeleton code to run specific Lambda functions, for example, making a call to an s3 bucket.

Once you have selected your blueprint, in this instance I have selected s3-Get-Object-Node.Js which will retrieve metadata from an object in my s3 bucket which I created earlier you must then configure your event sources which in this instance will be my s3 bucket. In the configure event sources window specify the source type and the name of that source as well as the type of event you wish to monitor. Once this is complete continue to the next configuration step.

The function must now be configured with the function name and the description as well as the runtime which should already be set for you. Below this section there will be some auto-generated code in a code editor which can be altered if necessary however in this instance no changes will be made to the code.

Below the code, there will be a section which will allow you to specify the Lambda Function and role. You can also the execution and performance of your Lambda Function by selecting the amount of memory to be used and also the timeout.

Setting up identity access management

In order to set up the proper Identity Access Management for your function, you must specify the role type which will open up a new tab allowing you to create a new IAM role thus giving permission to Lambda to make calls to your chosen resource. You can now review your selections before creating your Lambda Function.

Once you have created your function you must now enable your event source by clicking on “Disabled” in the state column. The management console allows users to test their code before running it. You can now go to your resource, in my case, it is an s3 bucket, and make some changes to it, for example, upload a file.

Once the file is uploaded you can return to Lambda and select the function you created to either view the CloudWatch logs or to view a graphical representation of the parameters being monitored. If you uploaded a file to an s3 bucket you should see a spike in the invocation count and invocation duration of your function.

Creating an AWS Lambda function can be tricky the first time you do it. However, AWS do offer an introduction to Lambda in the form of Quick Labs which can be used for free and as many times as you require to make users more comfortable with the services that they offer.

About CloudRanger

CloudRanger offer a simple DevOps automation solution to make it easy to manage backups & servers on AWS cloud. Using CloudRanger, you can easily backup your RDS and EC2 instances as well as EBS volumes with snapshots and AMIs.

With an easy to use interface, managing your routine AWS tasks is simple and effective. CloudRanger saves your team time and hassle, making the day-to-day management of your AWS resources easier and more automated. CloudRanger can also help you save on your EC2 costs by starting/stopping non-production instances automatically when you need them.

Try CloudRanger for Free

Start a 14-Day Free Trial, so you can try out our range of AWS features and benefits for yourselves.

CloudRanger AWS Backups

Contact Us