No two days at travel.cloud are the same, an engineering team developing a brand new product face interesting challenges everyday. travel.cloud’s values help us drive our ambition to build a product with industry best practices, using the latest technology and delivering an unmatched customer experience. The tech scene is rapidly changing, new and often game-changing technologies are being proposed and put into action by leading infrastructure/service providers. As a tech-savvy company, travel.cloud has embraced the “startup culture” by being at the forefront in terms of absorbing workflows and leading edge tech.
Keeping in line with the “startup culture”, travel.cloud has encouraged members of SET (Software Engineering Team) to take a day to research any interesting technology or software artifact which could potentially be used to improve the Product. The subject for my research day was to look into the Lambda platform by AWS.
What is AWS Lambda?
AWS Lambda is “a compute service that runs developers’ code in response to events and automatically manages the compute resources for them, making it easy to build and manage applications that respond quickly to new information.”
Lambda functions are stateless, allowing them to scale rapidly. Depending on the speed at which the events are raised, the runtime can decide to run multiple Lambda function copies concurrently.
How it works - Lambda Invocation model
There are two models:
- the pull model
AWS Lambda polls the event source and invokes Lambda when it detects an event. For example, it can listen to DynamoDB, Kinesis streams and react to new records on the stream.
- the push model
An event source invokes the Lambda function when it publishes a new event. Users can configure S3, SNS, Cognito, Echo to invoke Lambda function. Lambda functions can also be triggered by user applications.
Lambda scripts can be written in an in-line editor and has Node.js and JAVA 8 support. These scripts are known as Lambda functions they are uploaded to AWS using the Lambda console.
Lambda functions require permissions to access CloudWatch logs and any resources they will be accessing via an IAM role.
Lambda with Java
AWS recently announced Java 8 support for Lambda. I wanted to learn more about Lambda as part of my research day and choose to use the familiarity with Java to my advantage. Although AWS Lambda supports Java 8, for the purpose of my research I compiled code with Java 7. I followed the steps mentioned in the documentation. Writing Lambda functions in Java requires creating a deployment package, a .jar. A deployment package can be created using Gradle or Maven.
Development environment configuration:
- Eclipse - IDE
- Maven - build tool
- Java 7 - compiler
The instructions to configure the environment are here.
Lambda functions in Java are stateless, and can be expected to have access to other AWS services and the local filesystem. The important thing that such access rights be limited to the lifetime of the request.
Lambda functions in Java have to specify a “handler”. This handler is invoked when the function executes. The handler can consume any pre-defined event data or any custom object. A “Context” (http://docs.aws.amazon.com/lambda/latest/dg/java-context-object.html) object can be passed on as an additional parameter to interact with the execution environment. The function can write to CloudWatch logs via the context object.
Exceptions, if any can be viewed in CloudWatch.
For the purpose of the research I followed the example to “Process S3 events”. The Lambda function jar was uploaded to S3 as the size of the JAR was 11.5MB. AWS Lambda provides option to create functions uploaded via S3.
Lambda vs EC2
Previously if a developer wanted to run code, DevOps would have to spin a new EC2 instance. This would also involve installing the right software stack and other activities provisioning, configuring, maintaining VM before code could be uploaded and run. Lambda doesn’t require an EC2 instance. Its just simple code written in-line in an editor. The outcome of the execution of a Lambda function can be monitored using CloudWatch logs.
Potential Lambda use cases
There are a number of use cases for Lambda
- a Mobile backend
- a REST service that uses the AWS API Gateway
- a Microservice
- reacting to events from AWS DynamoDB, Kinesis, S3 and other services.
In conclusion I think Lambda functions are easy to setup, provided an IAM execution role and event trigger. Biggest advantage is the ability to deploy/redeploy functions without the need to redeploy application(s). The support for JAVA made it easier on the day to go through the example. Although JAVA support is good, the same (and more) can be achieved in Node.js with fewer lines of code. TravelCloud, and Travel in particular, can leverage the power of Lambda functions in intuitive ways to solve challenges. For example, function(s) listening to Kinesis, DynamoDB streams can help us build an efficient audit trail service. Changes to data which affect business can be monitored intelligently via functions.
Lambda has the potential to becoming the focal point in the AWS Cloud infrastructure and at Click Travel we are “all-in”.
Make sure to check out Software Engineering Team Tech Topics: No.1 - Machine Learning, if you missed out.