AWS Lambda & Cloud Computing with Amazon

A PaaS

AWS is a Platform As A Service (PaaS) which allows to execute code serverless.

They take care of environment updates, scaling, load balancing,

You pay only for the resources consumed, on the contrary to AWS OC2 which factures for the uptime.

Usage

  • Data processing in real-time – for example to be triggered when a new object is stored in a database (like Amazon S3, Dynamo DB, or from Kafka, Kinesis for IoT objects, …)
  • Extract, Transform & Load (ETL). Your function can react to an order for example and prepare the data to be load in a data warehouse (like Amazon Redshift) or a data lake. Read this article to know more about data lake and data warehouse.
  • You can use it with a back-end API (created with API Gateway for REST Apis, AppSync for GraphQL APIs) and make your API endpoints call your Lambda Functions. It works for both mobile app and web app (the latter can be hosted in Amazon S3)
  • Program your Lambda Functions to be trigger at a regular time frequency (i.e. once every 2 hours)
  • In a nutshell, program external events to trigger your Lambda functions.

Requirements:

  • You need to have a AWS account. Create one at aws.amazon.com.
  • A good practice is to create an IAM (Identity and Access Management). Your account is considered as a root user, and you want to create IAM user for each person that requires access. See how to create IAM user and group (official documentation by Amazon).
  • Even if AWS Lambda is free up to 1 million requests per month, you still have to put your billing informations to get access to the console. Protip: use a virtual bank card!

AWS Lambda Console

AWS Lambda comes with a console, a command line interfaceand an IDE (Integrated Development Environement) useful for:

  • Create Lambda Functions
  • Concepts
  • Quotas

Create a Function

Supported languages

AWS Lambda supports, as of November 2020 :

  • Go 1.x,
  • Java 8 and 11,
  • Node.js 10.x, 12.x,
  • Python 2.7, 3.6, 3.7, 3.8,
  • Ruby 2.5, 2.7,
  • .NET Core 2.1 (C# / PowerShell),
  • Custom execution: you can use your own runtime. Some people uses it to run PHP, Kobol, Swift, …

Functions roles

It’s important to define roles for your functions. Roles allow you to define the accesses and authorisations of your function, the same way you do with the roles of your users.

For example, you may want to give it access to Amazon Cloud Watch to store logs there, where you can consult them. Or to another databases (S3, Dynamo, …)

Functions parameters

Your Lambda Functions takes two parameters:

  • event: Contains the input parameters in JSON form (received by API Gateway, S3, or any service that triggered your Lambda Function)
  • context: Contains runtime informations (region (i.e. “eu-west-3 is Paris), …)

You can test your Function inside the console, select a template (i.e. the data that can be sent by S3) and see the execution results in stdout + duration + billing duration.

You can also invoke it with a command line. Given that your function name is hello_world, you can provides context information and have to provide the input in JSON format, and a file in which the function’s output will be written:

aws --region eu-west-3 lambda invoke --function-name hello_world --payload fileb://input.json output.txt

You can define your timeout (default is 3 seconds), the simultaneity (default is 1000 concurrent running).

More ressources

Leave a Reply

Your email address will not be published. Required fields are marked *