Working with AWS Lambda

Lambda is a mature product that is being used in a large number of organisations across the world – it is front and centre of the AWS product line and has a very active roadmap.

Inawisdom uses a cloud native and serverless approach to the solutions our engineers create. This involves using Lambda, API Gateway and StepFunctions as critical elements of the architectures and micro-services that Inawisdom develop. These services also provide the foundation for creating ML Ops processed that support the operational function of machine learning models at scale. Lastly we pride ourselves on educating clients on the use of serverless technology including how to deploy, debug, optimise and observe the operation on Lambda function in production workloads.

About Lambda

AWS Lambda was launched by AWS in November 2014 and is their “Function as a Service” offering that has completely changed how solutions are built in the Cloud.  AWS Lambda allows for code developed in a number of programming languages (including Python the principal language we used at Inawisdom) to be executed.  AWS handling the execution of the code means you can focus on the business logic without the need to worry about under lying concerns like provisioning and maintaining of servers. The cost model for lambda is pay per execution (invocation)  of the code, you do not pay for ideal instances, unused storage or expensive licences. This makes Lambda fast, versatile and cost effective.

Inawisdom’s way of thinking

The development of Lambda functions requires a step change in thinking on how to develop distributed solutions and running of code. The main focus must be on the functionality of the function and doing one thing really well, simply and fast. Think like a programmer, if a function is too big or to complex then split it up and refactor, use smaller components and make things more manageable. This can be achieved with AWS Lambdas by combining it with use of step functions, SQS and SNS. The cost model helps here as the more compute resources you use and the amount of time you use them for will drive your costs.

Common Uses of Lambda

At Inawisdom we use Lambda functions at the heart of the solutions that we develop for our customers and especially when it comes to ML Ops. Here are the four most common ways we currently use Lambda:

  • API: Lambda is used with AWS API Gateway and Amazon SageMaker to make thousands of live predictions per minute (see Aramex case study here)
  • Batch: Lambda is used with S3, Step Functions and number of Machine Learning models to make millions of predictions for batches of data such as call analytics (learn about Contact Centre Intelligence here)
  • Streaming: Lambda is used with Kinesis to process thousands of events per minute to perform enrichment and take business decisions using a rules engine
  • Pipelines: Lambda is used with Step Functions and CodePipeline to automate the retraining and deployment of Machine Learning models

Performance tips

The pay per innovation aspect of AWS Lambda means the Lambda code needs to highly optimised and to accomplish this. At Inawisdom we use CloudWatch and X-Ray to observe the execution of the code. We then take a detailed look at what aspects are consuming the most resources or taking the longest. Typically, things to look out for are:

  • The establishes and closing of connection to databases
  • The reuse of HTTPS sessions to avoid continuous SSL negotiation
  • Balancing the amount of memory and CPU, as CPU scales with memory but sometimes more CPU may speed up throughput.
  • Use layers to help with deployments times and to speed up cold starts

Costs

The costs of AWS Lambda are per million requests and are based on the amount time and amount of compute resource used. AWS Lambda also comes with a monthly free tier of 4 million requests. This means in most situations you can adopt and experiment with AWS Lambda a little cost.

AWS Ambassador Phil Basford on Deep Learning Container in Lambda running TensorFlow

Customer Case Studies using Lambda:

See how we have helped our customers achieve success utilising AWS Lambda through Inawisdom:

View more of our customer case studies.

Blogs